1. Quick Poll: what is the correct indentation for ifdef?
- Posted by petelomax Mar 05, 2011
- 1881 views
I am currently updating Edita's Re-indent function to cope with ifdef statements.
I can either indent ifdef as if part of the code:
while 1 do ifdef WIN32 then msg = "windows" elsedef msg = "linux" end ifdef puts(1,msg) end while
or, and I think I prefer this way, to emphasize them as preprocessing statements:
while 1 do ifdef WIN32 then msg = "windows" elsedef msg = "linux" end ifdef puts(1,msg) end while
I suppose the real question I am asking is do I need an option, and if so what should the precise wording of that question be?
Pete
2. Re: Quick Poll: what is the correct indentation for ifdef?
- Posted by petelomax Mar 05, 2011
- 1851 views
Sorry, I forgot about things like this:
ifdef WIN32 then if c_func(xGetWindow,{}) then elsedef if int80(getwin) then end ifdef ... end if
If you try and treat ifdef as "part of the code", there is no proper indent for that...
3. Re: Quick Poll: what is the correct indentation for ifdef?
- Posted by menno Mar 06, 2011
- 1725 views
This probleem has been intro'd by the definition .
There for I did a other definition in PEU :
add conditional compiling : ifdef , elseifdef elsedef enddef . (02-02-09) Menno
max 10 define's and 10 if levels . (no checks)
So it has nothing to do with the syntax as is done in C with the #if.. .
4. Re: Quick Poll: what is the correct indentation for ifdef?
- Posted by DerekParnell (admin) Mar 06, 2011
- 1720 views
I suppose the real question I am asking is do I need an option, and if so what should the precise wording of that question be?
There is no right way to indent things. Everyone sees indentation differently.
I'd ask ... Align 'ifdef' at column 1? Yes/no
5. Re: Quick Poll: what is the correct indentation for ifdef?
- Posted by DerekParnell (admin) Mar 06, 2011
- 1712 views
Sorry, I forgot about things like this:
ifdef WIN32 then if c_func(xGetWindow,{}) then elsedef if int80(getwin) then end ifdef ... end if
If you try and treat ifdef as "part of the code", there is no proper indent for that...
That is not valid syntax anyway. An if statement must be totally enclosed by an ifdef block.
6. Re: Quick Poll: what is the correct indentation for ifdef?
- Posted by SDPringle Mar 07, 2011
- 1637 views
The first way is what I prefer. The options could be called: 'Indent defined word statements with other code' ot 'indent defined words separately'
Shawn Pringle
7. Re: Quick Poll: what is the correct indentation for ifdef?
- Posted by jeremy (admin) Mar 11, 2011
- 1499 views
I personally like to indent ifdef as any old if statement. The reason being is I treat it like a normal if statement. I don't care (when reading the logic of the code) that it's done in the pre-processing of the Euphoria source vs. runtime of the Euphoria source. All I care about is that:
if 1 then ifdef WINDOWS then alert("Hello") end ifdef end if
If 1 is true and we are running on Windows then a hello alert box will appear. To me, having ifdefs on the first column really breaks up the flow of the code and is very difficult for me to follow. I am sure that one will adapt to their coding style and be able to read the flow no matter how they indent it, but for me it's easier to treat them all the same for the purpose of readability.
Jeremy
8. Re: Quick Poll: what is the correct indentation for ifdef?
- Posted by jeremy (admin) Mar 11, 2011
- 1485 views
Oh, also, I really try to keep the ifdefs to definitions for clarity. Some places I use it in code but most places I try to abstract. I know your code was a simple example and not really intended for real code, but to give an example I would have:
-- Application constants ifdef WINDOWS then constant platform_name = "windows" elsedef constant platform_name = "linux/bsd/osx/something else" end ifdef -- Application code while 1 do puts(1, platform_name) end while
If some logic needs to change deeply nested, I try to abstract it as well:
ifdef WINDOWS then procedure alert(sequence msg) win32:msgbox(msg) end procedure elsedef procedure alert(sequence msg) puts(1, msg) end procedure end ifdef while 1 do if error then alert("bad code") end if end while
instead of
while 1 do if error then ifdef WINDOWS then win32:msgbox("bad code") elsedef puts(1, "bad code") end ifdef end if end while
This makes me think out the code and make it more reusable. I know the above is a simple example, but having an alert() for windows, linux, os/x all different is good programming as it allows me to fix the alert or make it more platform centric very easily without affecting my code not related to displaying an alert message, for example my error detection/reporting code.
Thus, with the above style, I think that how to indent ifdefs becomes less of a problem as you do not tend to have deeply nested ifdefs. Once exception, of course, is ifdef DEBUG type structures.
Jeremy