5 ms·
Steve Bourne used a set of macros to enable ALGOL-like programming in C and used it to implement his Unix shell - https://research.swtch.com/shmacro https://res
by johndoe0815 5y ago
Steve Bourne used a set of macros to enable ALGOL-like programming in C and used it to implement his Unix shell - https://research.swtch.com/shmacro https://research.swtch.com/shmacro
- agumonkey 5y agoha, I was googling FORTRAN C macros and went nowhere, that was the page I was looking for :)
- OskarS 5y agoThis is obviously terrible, but my favorite part of this whole thing is the fact that he included the parentheses in the IF/THEN macros, so you didn't have to do it for the condition in the if statement. So, like, this line doesn't need parentheses around the condition: IF (n=to-from)<=1 THEN return FI All modern languages that try and do a refresh on the C style (Rust and Swift notably) do this, it's clearly the right idea. They should just update the C and C++ syntax to make those parentheses optional at this point. (PS. some people would also recoil at the assignment-as-expression used in that line, but that's just good clean fun!)
- josefx 5y agoThey already make them optional for single nested statements, which causes a gigantic mess when you extend code and forget to add them. if (a) doThis(); andThat(); is interpreted as if(a){ doThis(); } andThat(); Some compilers are nice enough to throw around misleading indentation warnings, but without an explicit block termination like FI this just causes issues all over the place.
- skocznymroczny 5y agohe meant making the (a) part optional to make "if a" instead. parenthesis are (), {} are braces :)
- josefx 5y agoOne of the few times I get to remember that English is only my second language. Can't really think of a reason for not dropping them unless there is a weird corner case in the existing grammar.
- thaumasiotes 5y ago> One of the few times I get to remember that English is only my second language. Most native speakers aren't aware of the terms. They'll call anything by any name. There is a significant constituency for "curly brackets {}" and "square brackets []". Anyway, there are mistakes you could make that would give you away as a nonnative speaker, but that wasn't one of them.
- dragonwriter 5y ago> There is a significant constituency for "curly brackets {}" and "square brackets []". Yes, but there is still basically no constituency for “parentheses” (“{}”) or “parentheses” (“[]”), except in some narrow specific contexts; in programming, one example would be discussion of certain Lisp dialects where either all or certain uses of “()” in classic Lisp can (or, in the “certain” case, sometimes must) use the others, in which context “parentheses” are sometimes used generically for all three. So, while there is a variety of ways paired delimiters are described by native speakers, the particular use here was still outside of the normal range of that variation.
- iainmerrick 5y agoIf you dropped the parentheses around the condition, I think you’d have to make the braces around the body mandatory. Many (most?) C style guides make the braces mandatory, but it’d be a big step to actually change the language syntax that way. Tons of existing code would need to be updated. .. although I guess that could be automated!
- OskarS 5y agoYou could probably do an either or thing: "You can drop the parentheses if you use braces. But you can't drop both". Though you're right, this is why it'll never happen. Basically, C had a choice of eliding the parentheses around the condition or the braces around a single-statement block, and they chose the braces. With a half-century of hindsight, that was probably the wrong choice.