3 ms·
I actually like the VB-style, but VB did it mostly wrong: if you start the block with X, you should always end it with "End X". Thus, you'd have While ... End W
by tabtab 4y ago
I actually like the VB-style, but VB did it mostly wrong: if you start the block with X, you should always end it with "End X". Thus, you'd have While ... End While instead of crap like "Wend" and "Next" (in For...Next).
It's more legible to know what block is being ended. C-style continually frustrates me that area. The End-X style just never found a nice way to wrap text for longer statements.
C-style also has a problem in that there is no way to define arbitrary blocks: it relies too much on key-words. I'm trying to remedy this with "Moth" syntax:
https://www.reddit.com/r/ProgrammingLanguages/comments/ky22dx/simplified_take_on_moth_colonfree/ https://www.reddit.com/r/ProgrammingLanguages/comments/ky22d...
It's LINQ-esque but without the bloated Lambda conventions, and influenced by XML in that you have a simple syntax pattern that can "implement" many domains' needs. It started with an attempt to merge the best of Lisp and C-style. (Whether it succeeded or not is hotly contested. I welcome other attempts.)
- f1shy 4y agoNote that in the for case, you can have many "next" and having many "end" would be silly.
- Jtsummers 4y ago> I actually like the VB-style, but VB did it mostly wrong: if you start the block with X, you should always end it with "End X". Thus, you'd have While ... End While instead of crap like "Wend" and "Next" (For...). That's covered in their syntactic salt section, but Ada does, mostly, what you describe. procedure Proc(...) is -- vars, types, and subprograms defined here begin ... end Proc; for I in Some_Array'Range loop ... end loop; if condition then ... end if;
- mojifwisi 4y ago> C-style also has a problem in that there is no way to define arbitrary blocks I might have misunderstood what you mean by "arbitrary blocks", but you can definitely do this in C: int main() { { /* arbitrary block */ return 0; } }
- Jtsummers 4y agoThey seem to mean a computational block (or a closure/lambda) that can be passed on to other functions. Try to do this in C (it's invalid as presented, but this is the concept): int main() { int* collection = ... int* filtered = filter(collection, int func(int item) { return item > 10; }); ... } You have to actually define a function at the top level in order to pass that in and there is no notion of closures so you can't do the more useful thing that you might have in even C++ these days: int main() { int* collection = ... int limit = ... auto filter = [&limit](auto item) { return item > limit; }; int* filtered = filter(collection, filter); // assuming `filter` is defined ... } You can come close, but you create a lot of extra bookkeeping in your C program to pull it off, and the functions are still only defined at the top-level.
- hoosieree 4y agoGCC has an extension for nested functions: https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html#Nested-Functions https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html#Nes... Not as nice as anonymous blocks but helps put the function closer to where it's used, which is nice.
- Jtsummers 4y agoYeah, but the two dominant open source C compilers have chosen different approaches. This makes nested functions (gcc) and blocks (clang) both unusable if you want portable code even between the pair of them (and not generally).
- deleted 4y ago[deleted]