5 ms·
C syntax is just horrible. It would be better to have something like "ARRAY [100] OF POINTER TO FUNCTION RETURNING POINTER TO INT", if you need it more than onc
by rep_lodsb 2y ago
C syntax is just horrible. It would be better to have something like "ARRAY [100] OF POINTER TO FUNCTION RETURNING POINTER TO INT", if you need it more than once or twice you can declare a type for it.
- bregma 2y agoYou missed the opening "PROCEDURE DIVISION.".
- ape4 2y agoADD A TO B GIVING C would be so much clearer
- pyjarrett 2y agoAda syntax is close to what you described: Foo : array (Positive range 1 .. 100) of access function return access Integer;
- PhilipRoman 2y agoThe root problem is having both postfix and prefix operators (and whatever their combination is called) for types. Plus the fact that arrays in type names sometimes act as pointers and sometimes not.
- wruza 2y agoStill unclear at things like “returning pointer to array of pointer to function …”. The best shot is to name intermediate types, since they aren’t really intermediate most of the times. Properly structured programs tend to disassemble complex structures to work on them, so you need these names anyway. That said, C compilers definitely lack -Wunreadable-types flag which must be default.
- ape4 2y agoI was about to say the same thing. If you have an array of widgets used in several places in your program it would be odd not give it a name. Then you can have a pointer to it, etc.
- bluetomcat 2y agoPointers to arrays are an incredibly rare thing in real-world C programming, let alone functions returning them. They contain the same address as a pointer to the beginning of that array, with the only difference that pointer arithmetic will be done in sizeof(arr) steps, not in element-size steps. It is a widely accepted practice to typedef pointers to functions. With pointers, more than 2 levels of indirection is an indication of a badly written program. In practice, the most complex declarations you should write are "pointer to pointer to x", "array of pointers to x", "array of function pointers returning x". Stuff like "pointer to function returning pointer to pointer to array" is nonsensical most of the time.
- DrNosferatu 2y agoRare? Unless it’s people obfuscating the codebase so they are able to keep their job forever without delivering any new/real value.
- ajross 2y ago> C syntax is just horrible. All syntax is horrible. Rust is the en vogue tool of the moment and it's objectively harder to read than C. Python used to be clean and now it's sort of a mess. C++, well... Some languages try to get away with having simple syntax though. Javascript is in this camp, as of course are all the Lisps. And the result is that you end up drowning in a sea of complicated semantics instead, c.f. the famous "wat" video or the fact that every sexpr macro-ized DSL works like its own little butterfly. You can't win. C is fine. Could you do better if you started from scratch? Sure. Would it last? No.
- nicoburns 2y ago> Rust is the en vogue tool of the moment and it's objectively harder to read than C I think you're just used to C syntax. I find Rust syntax much easier to read than C syntax (and that was already true when I didn't know either language well).
- ajross 2y agoMeh. Grandparent who thinks "C is horrible" just isn't used to C. Familiarity breeds facility, that's no surprise. But no, Rust is just bad at this point given all the stuff that's been added and all the historical idioms that were pushed and then abandoned. It's not C++ bad, but it's objectively "worse" than C whose quirks all fit in a tiny K&R paperback.
- leetcrew 2y agoit's subjective to an extent, but requiring a "reverse spiral rule" (which itself has exceptions) to understand inline types is about as close to objectively bad as it gets. rust surely has it's issues, but reading types is not one of them. whatever you put inside the <> of a outermost symbol is a straightforward tree parse.
- jstimpfle 2y agoThe "reverse spiral rule" is a myth and that website should be shut down. It only adds confusion for the already confused. C type syntax has a simple guiding principle, there is no type syntax and "declaration follows usage" i.e. normal expression syntax. A few ugly additions that don't cleanly fit in this model were made later for practical reasons, but they don't change the basic idea, which is that there is so little to C type syntax that you can barely see it (which may also be why it's so easy to read once you've grokked it).
- inopinatus 2y agouggclang: error in integer literal, did you mean "ONE HUNDRED"? at line one
- jcparkyn 2y agoI was with you until the second sentence - there's so many better syntaxes C could've used but that's not one of them.
- jstimpfle 2y agoI agree it's annoying (really bad for tooling), and what's more annoying is that for a human who understands how it works, there is no syntax as easy to read and write as C declaration syntax. It's terse and intuitive, not adding new type syntax but reusing what already exists as expression syntax.
- deleted 2y ago[deleted]