Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2019-05

Minor request with case else branches

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

J. Gareth Moreton

Hi everyone,

Since the mandatory else section for case blocks isn't going anywhere, I would like to make a small request:

Whenever I come across a section of code in my own projects where "*else *;" is necessary, or any empty branch for that matter, I put a "{ Do nothing }" comment just to make it absolutely clear that the block is there deliberately and so there isn't any confusion with the syntax on first viewing; e.g:

*case *... *of*
*else*
     { Do nothing };
*end*;

(I just hope the e-mail formatting doesn't remove the indentation!)

Just a minor thing, but I'm wondering if that's a sensible request for the compiler source.

Gareth aka. Kit

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

J. Gareth Moreton

Sorry, I didn't mean to post my reply to the core list.

----

I do like things to be documented so there's no guesswork with that.  Admittedly some of the standards seem to be more designed for projects written in C and C++, like identifiers all being in lowercase, whereas Pascal, or at least Delphi, traditionally had the start of every word capitalised (e.g. TCriticalSection instead of tcriticalsection).

I do put spaces before and after operators (e.g. "X := 5" instead of
"X:=5") because that is how I started my life as a Turbo Pascal and
Delphi 2.0 programmer, but if the compiler coding standards tell me
otherwise, then I'll do the no-space style.

Personally I would say that the most readable styles should be championed, but that's just me.

Gareth aka. Kit

Sven Barth wrote 18 lines
J. Gareth Moreton < > schrieb am So., 26. Mai 2019, 19:14: Yeah, coding standards are kind of non- existent for the compiler. Things like spaces before and after operators, how variables are named and indentations etc seem to vary wildly. I don't want to enforce my own standards though without a good debate. There is a style that quite some code inside the compiler is following and which we are trying to make patches from external developers adhere to. Regards, Sven

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

Ben Grasset
to J. Gareth Moreton: Since the mandatory else section for case blocks isn't going anywhere, I would like to…
PM J. Gareth Moreton wrote 6 lines
Whenever I come across a section of code in my own projects where "*else * ;" is necessary, or any empty branch for that matter, I put a "{ Do nothing }" comment just to make it absolutely clear that the block is there deliberately and so there isn't any confusion with the syntax on first viewing; e.g:

On a more general scale, it seems like it might be a reasonable spot for an actual new case-block-specific keyword? I can't imagine it would be an insurmountable task to do something like make the literal word "nothing" (followed by a semicolon) act as "sugar" in the context of case blocks for what a lone semicolon normally does.

For example:

type TSomeEnum = (A, B, C, D);
case BlahBlah() of
  A: DoThingForA();
  B: DoThingForB();
  C: nothing;
  D: DoThingForD();
end;

Reply by email

J. Gareth Moreton
to Ben Grasset

I personally disagree with that one because it's just fluff, considering that "nothing" is equivalent to "{ nothing }" - usually a keyword or an intrinsic should actually do something.

Gareth aka. Kit

Ben Grasset wrote 29 lines
On Fri, May 24, 2019 at 5:46 PM J. Gareth Moreton < > wrote: Whenever I come across a section of code in my own projects where "*else *;" is necessary, or any empty branch for that matter, I put a "{ Do nothing }" comment just to make it absolutely clear that the block is there deliberately and so there isn't any confusion with the syntax on first viewing; e.g: On a more general scale, it seems like it might be a reasonable spot for an actual new case-block-specific keyword? I can't imagine it would be an insurmountable task to do something like make the literal word "nothing" (followed by a semicolon) act as "sugar" in the context of case blocks for what a lone semicolon normally does. For example: type TSomeEnum = (A, B, C, D); case BlahBlah() of   A: DoThingForA();   B: DoThingForB();   C: nothing;   D: DoThingForD(); end; _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email