Re: New keywords: ifdef, elsifdef, end ifdef

new topic     » goto parent     » topic index » view thread      » older message » newer message

yuku wrote:
> 
> However, I don't really like the syntax.
> Especially the elsifdef, it looks like a cramped abbreviation.
>

I was not too happy. I think my first post about the feature was asking for
suggestions. It's functional and I think it can grow on you, but at first sight,
ifdef, elsifdef is, eh?
 
> Other suggestions that came in mind:
> 
> 1. Use another keyword after "if" like "defined"
> 
> }}}
<eucode>
> if defined LINUX then
>     -- linux code
> elsif defined WIN32 then
>     -- win32 code
> else 
>     -- whatever
> end if
> </eucode>
{{{

> 
> Adv: only 1 new keyword instead of 2. Less abbreviation.
> Dis: harder to implement (?)
>

It's not only harder to implement but it would slow *all* programs down. The
reason for this is each and every *if* statement that the parser would come
across would have to be checked for an optional "defined" keyword. IMHO, this
shoots down the above syntax.

> 2. Use static if (idea from D)
> 
> }}}
<eucode>
> static if VERSION > 400 then
>     puts(1, "you are in the future!")
> elsif VERSION < 400 then
>     puts(1, "Please upgrade")
> else 
>     puts(1, "hohoho");
> end if
> </eucode>
{{{

> 
> Adv: One keyword instead of 2. Only need to write "static" once instead of 2
> times
> "defined" like above. Can use >, <, = instead of just boolean testing.
> Dis: same as above
>

This has potential. The static keyword would be the keyword and send the parser
into a new Static_statement() function that would then begin looking for the if,
elsif, end if statements. This would cause zero slow down in existing
applications and in applications that utilize it, it would only cause speed
increases.

However, I dis-like using the word static as static usually means something
totally different. For instance:

function next()
    static integer id
    if !defined(id) then
        id = 0
    end if
    id += 1
    return id
end function


There are other uses for the static keyword as well. Perhaps a different
"trigger" word could be found? This is a good idea, static is just not the best
choice, I do not think.

> 3. Use $ for "preprocessor" variables (variables that are defined during
> compilation),
> no need to use new keywords.
> 
> }}}
<eucode>
> if $VERSION > 400 then
>     puts(1, "you are in the future!")
> elsif $DOS32 then
>     puts(1, "good old-timer")
> else 
>     puts(1, "hohoho");
> end if
> </eucode>
{{{

> 
> Adv: The $ sign makes it stands out from normal if-statement. $ sign is
> already
> used so no new keyword or symbol introduced. Can use >, <, = instead of just
> boolean testing.
> Dis: none?
>

Has the same problem as the first option. I think your second idea is the best
one but with a different trigger word. One thing that may be confusing about
that, and possibly a reason not to use a trigger word would be people would think
you could then do:

compile-time procedure init()
    -- compute big long value that has all sorts of 
    -- nested loops, complex decisions, random number
    -- generation and takes 10 minutes to come up with
    -- the final answer.
    answer = result_of_everything_above
end procedure


and by the nature of "compile-time" keyword, that sounds perfectly legit but not
currently (or ever that I can see in my finite mind) possible.

So, we should carefully consider the use of a trigger word. It makes the if
statement look better, but provides other real benefit and could cause confusion.
Sure, people could read the manual, but how often do they and should they have
to? I know for the most part I can look at a few examples of code in a new
language and begin programming in that language. Sure, there are minor nuances
that must be learned by reading document references, but is this one of those
things or no?

I like the looks of it quite a bit better, but ...

Thoughts?

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu