Are we getting better at designing programming languages?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jul 25 22:11:17 PDT 2013


On Fri, Jul 26, 2013 at 06:36:21AM +0200, Kagamin wrote:
> On Tuesday, 23 July 2013 at 18:14:10 UTC, Ali Çehreli wrote:
> >First of all, C does not have exceptions so every single thing
> >must be done as two lines:
> >
> >    err = do_something();
> >    goto_finally_if_error(err);
> 
> Huh, never seen such pattern in C. I just return error code.

I think what he meant is code like this:

	#define OK 0
	#define ERR -1

	void myfunc(int x, int y, int z) {
		void *buf = malloc(100);
		int err;

		if ((err = fun1(x,y,z)) != OK)
			goto EXIT;

		if ((err = fun2(x,y,z)) != OK)
			goto EXIT;

		if ((err = fun3(x,y,z)) != OK)
			goto EXIT;

		if ((err = fun4(x,y,z)) != OK)
			goto EXIT;

		/* Finally finished! */
		err = OK;

	EXIT:
		/* Do cleanup */
		free(buf);

		return err;
	}

I have to write code like this every day at work, and it's a royal pain
in the neck.


T

-- 
The best way to destroy a cause is to defend it poorly.


More information about the Digitalmars-d mailing list