Adem24 wrote:
> 1) There is no goto statement.
> Hidden goto's like break- and continue-statements are also
> omitted.
There are cases, they are scarce but they exist, where goto is
nothing else but really usefull, and makes the simplemost kind
of code. Examples:
Say you got a series of dependent structures, that must be
allocated in a certain order and deallocated in opposite order.
With goto you can:
void foo()
{
Bar bar;
Baz baz;
Bla bla;
int failure = 1;
bar = bar_create();
if(!bar)
goto bar_create_failed;
baz = baz_create(bar);
if(!baz)
goto baz_create_failed;
bla = bla_create(baz);
if(!bla)
goto bla_create_failed;
failure = 0;
/* do some stuff */
bla_destroy(bla);
bla_create_failed:
baz_destroy(baz);
baz_create_failed:
bar_destroy(bar);
bar_create_failed:
if(failure){
/* deal with failure */
}
}
Challenge: Do this with only if, while and for in a more readable
fashion.
Another exercise: Exit from a stack of neested loops to the
outermost structure, or some loop levels above, and perform some
post handling.
for(...){
for(...){
for(...){
if(...)
goto break_loop_3_to_0;
if(...)
goto break_loop_3_to_1;
}
if(...)
goto break_loop_2_to_0;
}
break_loop_3_to_1:
}
goto normal_finish;
{
break_loop_3_to_0;
/* ... */;
goto normal_finish;
}
normal_finish:
Of course I know that Djkstra will now hate me, too (and not only
some guy called Linus T.).
> 2) There is no return statement.
> Instead a result variable can be declared to which the
> result of a function can be assigned.
Helps you in how far? Makes lambda expressions a PITA.
> 3) There are no automatic type conversions.
> When a subprogram should be used for different types it
> must be overloaded.
If a type can be converted without possible loss of data, why not
make it implicit. Compilers (should) raise a warning otherwise,
anyway.
> 4) There are no variable length parameter lists.
> Instead it is possible to use arrays as parameters.
See the D programming language. D even has a feature, that
variable parameter lists are implicitly converted into an array.
> 6) There is no special "parameter" called "self" or "this".
> In a procedure the receiving object is declared as formal
> parameter with a user-defined name.
In OOP aimed languages such parameters are implicitly created,
but a fixed name is a must, otherwise code is hard to read.
> 7) There is no macro feature since this mechanism is too
> similar to the subprogram feature.
> Instead subprograms can be used in a more flexible way than
> in other languages.
Sounds like templates and mixins in the D programming language
>
There are no reserved words.
Err, how do you want to code then? Ther muse be a few reserved
words the lexer can recognize. How do you want to reference
preimitive typed then?
> 9) There is no conceptual distinction between functions,
> operators, procedures and statements.
See the D programming language. Operators are actually calls to
functions named op_add, op_mul, op_cmp and so on.
> 10) The procedure calling mechanism is not based on a concept
> with an object-message pair
> (An object receives a message). Instead a match is done
> over a list of objects. This more general (and powerful)
> mechanism is called multimatch and it includes the simple
> object-message mechanism as special case.
Bug prone and non deterministic. Can make hell break loose (think
about circular calls...)
I designed a language addressing all those aspects to speed up
development of my game engine system. This language also has a
own mechanism for non-goto loop breaking and post error
cleanups, that I presented with the goto dance above. However
even this language still has goto. You never know, when you may
make good use of it.
Wolfgang Draxinger
--
E-Mail address works, Jabber:
, ICQ: 134682867