Alternate declaration syntax
Hans W. Uhlig
huhlig at gmail.com
Sat Apr 12 00:31:44 PDT 2008
Robert Fraser wrote:
> Hans W. Uhlig wrote:
>> Ok, Posting to the main forum so it doesn't get lost in the const stuff.
>>
>> Perhaps a slight variation to the C declaration might be in order,
>> since I know that multiple return values are wanted, a simple and
>> readable syntax for inheritance is needed (using : as an inheritor
>> does not make code more readable) try this out and see if it makes it
>> clearer
>>
>> <modifiers,...> <identifier> <properties,...> {...}
>>
>> such that:
>> const foo(const int, const double) §
>> throws barExtension §
>> returns const int, const float
>> {
>> // ... code ...
>> }
>>
>> same for classes:
>>
>> const class foo § extends bar {
>> const int x;
>> pure foo(const int, const double) § returns invariant string;
>> // ... more code ...
>> }
>>
>> (Note: § is used as a divider because no one uses it for anything in
>> programming and I didn't want to start an argument over : or | or ; or
>> any other punctuation being used elsewhere and being bad, quite
>> possible punctuation wouldn't be neccessary)
>>
>> It looks like a hideous cross between java and visual basic but it is
>> clean, readable, simple to machine parse(I think) and descriptive.
>> using slightly longer keywords makes a language a little more verbose,
>> but it also makes it readable. if you want to use punctuation for
>> everything you get what happened to perl when someone got a little too
>> creative
>>
>> `$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
>> $!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
>> $_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
>> ;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
>
> As for the post itself, I agree the return type should be at the end,
> but good luck convincing Walter of such. Also, D has no exception
> specifications ("throws" clauses) - nor do many other languages besides
> Java (it's considered something of a failed experiment...).
>
> My suggestion for the syntax is to indeed use the colon but not a
> "returns" keyword since that's a lot of typing. If I were designing a
> language, it would look like:
>
> const foo(int x, int y, int z) : int
> {
> }
>
> Grammatically:
>
> <modifiers> <identifier> "(" <parameters> ")" ":" <return type> "{"
> <statements> "}"
Ok, I have to ask the stupid question, what are peoples problem with
typing. Programmers should not be so lazy as to be unable to type 7
characters. the throws was also an example of how this could be used to
apply a clean syntax to other properties that need to be defined,
extends for inheritance, etc. In a system like this, major additions to
the function declaration can be made rather easily, and it produces
easier to read code. Nice thing about it is, D could support both for a
while and I dont think it would be too hard to implement parser wise.
More information about the Digitalmars-d
mailing list