246 points · by ingve · 4y ago · 131 comments
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!)
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.https://augustss.blogspot.com/2009/02/regression-they-say-th...
And to answer the question in the top comment:
https://hackage.haskell.org/package/BASIC-0.1.5.0/docs/Langu...
#include<curses.h>
#include<stdio.h>
#define ;
#define do
#define ʌ *
#define N -1
#define call
#define main.
#define , ];
#define ꞉= =
#define = ==
#define ; ];
#define not !
#define I int
#define M 256
#define or ||
#define end ;}
#define CALL }
#define S case
#define X x<<8
#define size [
#define <> !=
#define var int
#define Y y<<16
#define begin {
#define F FILE*f
#define ꞉integer
#define POOL ;}}
#define W p[y*q+x]
#define Z (W&(M N))
#define packed char
#define OK break;case
#define procedure int
#define fill꞉= return
#define close fclose(f)
#define readln(a) c=fgetc(f)
#define H(a,b) mvaddch(a,b,' ')
#define writeChar(a) fputc((a),f)
#define open(a,b) F=fopen((a),(b))
#define A(a) attron(COLOR_PAIR(a))
#define B(a) attroff(COLOR_PAIR(a))
#define read(a) switch(getch()){case
#define draw(a) {W=Y;W|=X;W|=((a)&0xff);}
#define LOOP for(y=0;y<w;y++){for(x=0;x<q;x++){
#define check if(fgetc(f)!=83){fclose(f);return N;};w=fgetc(f);q=fgetc(f)
#define start initscr();clear();keypad(stdscr,TRUE);cbreak();noecho();curs_set(0)https://www.reddit.com/r/rust/comments/5penft/parallelizing_...
> If you look closely, those aren't angle brackets, they're characters from the Canadian Aboriginal Syllabics block, which are allowed in Go identifiers. From Go's perspective, that's just one long identifier.
The thread goes downhill fast from there to the point where
> I once wrote a short Swift program with every identifier a different length chain of 0-width spaces.
In the above thread, user "yiyus" actually went through the macro code line-by-line and made explanatory notes; unbelievable! - https://docs.google.com/document/d/1W83ME5JecI2hd5hAUqQ1BVF3...
If we're going to use crazy header files, I want to see someone get the linux kernel to build and boot while including this: https://gist.github.com/aras-p/6224951
A long time ago, a friend who was studying mathematics at the time, approached me laughing hysterically and showed me a page in an "intro to C"-style book. It showed an example of how one would write a "get circumference of a circle" function. At the top of the code, there was a #define for the value of pi.
The text describing the code said something like this about why pi is #defined and not included directly in the expression:
"We define pi as a constant for two reasons: 1) it makes the expressions using it more readable 2) should the value of pi ever change, we will only have to change it in one place in the code"
"It's easier to type $pi than 𝜋, especially if you don't have Unicode. And it will be easy to maintain the program in case the value of ever changes."
There is also a comment by Randal Schwartz in the comments section where he credits Tom Phoenix with that particular bit of humour.
https://www.forbes.com/sites/kionasmith/2018/02/05/indianas-...
"When I use a word," Humpty Dumpty said, in a rather scornful tone, "it means just what I choose it to mean - neither more nor less."
Very ugly, ill-defined, uncodified democracy. No one tells you when you vote, no one counts up the votes, there are no official results.
When you speak or communicate with someone else, you are voting with them. "I vote this word means X, for a poor/crude/coarse agreement of what X is the first place."
And this is propaganda at its finest. Evil doublespeak: say one thing, and it actually is another. Snuck in.
Fantastic.
#define ;
#define do
I was under the impression it was "#define CNAME value" – what does it mean when there is no value? A trip to Google didn't turn up anything for me, so I'm wondering if a C master can weigh in. Thanks!The most common place where this sort of thing occurs is the common idiom
#ifdef DEBUG
#define debug(...) realdebug(__VA_ARGS__)
#else
#define debug(...)
#endif
which allows you to sprinkle debug() calls through your code and have them disappear if you compile without defining the macro DEBUG. #define debug(...) ((void)0)
This forces you to use debug() as a statement. If no value is defined you could omit the semicolon on a debug() statement and it still compiles.Clever, I was wondering how the : was done, but it's an abomination :-/
With some simple improvements to the language, about 99% of the C preprocessor use can be abandoned and deprecated.
Of course, I've also opined that Unicode supporting multiple encodings for the same glyph is also madness. The Unicode people veered off the tracks and sank into a swamp when they decided that semantic information should be encoded into Unicode characters.
[Purely-Latin borderline cases: umlaut (is not two dots in Fraktur) vs diaeresis (languages that use it are not written in Fraktur), acute (non-Polish, points past the letter) vs kreska (Polish, points at the letter). On the other hand, the mathematical “element of” sign was still occasionally typeset as an epsilon well into the 1960s.]
Unicode decides most of these based on the requirement to roundtrip legacy encodings (“have these been ever encoded differently in the same encoding?”), which seems reasonable, yet results in homograph problems and at the same time the Turkish case conversion botch. In any case, once (sane) legacy encodings run out but you still want to be consistent, what do you base the encoding decisions on but semantics? (On the other hand, once you start encoding semantic differences, where do you stop?..) You could do some sort of glyph-equivalence-class thing, but that would still give you no way to avoid unifying a and а—everyone who writes both writes them the same.
None of this touches on Unicode “canonical equivalence”, but your claim (“Unicode supporting multiple encodings for the same glyph is [...] madness”) covers more than just that if I understood it correctly. And while I am attacking it in a sense, it’s only because I genuinely don’t see how this part could have been done differently in a major way.
As if that weren't enough, they also decided to cram half-assed formatting into it. You got bold letters, italics, various fancy-style letters, superscripts and subscripts for this and that.. all for the sake of leagacy compatibility. Unicode was legacy right from the beginning.
1. static if conditionals
2. version conditionals
3. assert
4. manifest constants
5. modules
I occasionally find macro usages that would require templates, but these are rare.
typedef enum { ONE, TWO, THREE } my_enum;
const char* getEnumName(my_enum val);
you can use various preprocessor tricks to implement getEnumName such that you don't have to change it when adding more cases to the enum. This would be much better implemented with some compiler intrinsic/operator like `nameof(val)` that returned a string. C# does something similar with its `nameof`.For those who don’t know: the X Macro (https://en.wikipedia.org/wiki/X_Macro, https://digitalmars.com/articles/b51.html)
Arguably the C feature most used in other languages is the C preprocessor's conditional compilation for e.g. different OSes. Used by languages from Fortran (yes, there exists FPP now - for a suitable definition of 'now') to Haskell (yes, `{-# LANGUAGE CPP #-}`).
A better preprocessor (a C code generator, effectively) would be a simple program that would interpret the <% and %> brackets or similar (by “inverting” them). It is very powerful paradigm.
If you want to use metaprogramming, you've outgrown C and should consider a more powerful language. There are plenty to pick from. DasBetterC, for example.
> Is anyone using Cello?
> People have experimented with it, but there is no high profile project I know of that uses it. Cello is too big and scary a dependency for new C projects if they want to be portable and easy to maintain.
void get_order_token()
BeginDeclarations
EndDeclarations
BeginCode
While token_break_char Is ' '
BeginWhile
order_token_get_char();
EndWhile;
copy_string(token, null_string);
If IsIdentifier(token_break_char)
Then
While IsIdentifier(token_break_char)
BeginWhile
concat_char_to_string(token, token_break_char);
order_token_get_char();
EndWhile;
lowercase_string(token);
Else
If token_break_char Is '['
Then
While token_break_char IsNot ']'
BeginWhile
concat_char_to_string(token, token_break_char);
order_token_get_char();
EndWhile;
order_token_get_char();
If case_ignore.val
Then
lowercase_string(token);
EndIf;
Else
concat_char_to_string(token, token_break_char);
order_token_get_char();
EndIf;
EndIf;
return;
EndCode
*1 https://ftp.sunet.se/mirror/archive/ftp.sunet.se/pub/simteln...Whether they’d ever go back and finish the migration is not known.
Stephen Bourne did this in the sources of the Bourne shell, around 1977, to make C look like Algol.
Here it is in V6 Unix, 1979:
https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh...
https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh...
1) Write CPP macro language to emulate Oberon syntax.
2) Write program in the above macro language.
3) This program looks like Oberon but we now have two ways of "compiling" it; a) Feeding it to the CPP/C Compiler or b) Feeding it to the Oberon compiler directly with a little bit of tweaking.
Have i understood it correctly?
(https://github.com/ibara/cpaint/blob/21c70acba373df932920d5f...)
In the 80's I worked for a guy who insisted that we wrote all our C using macros that made it look like FORTRAN, amongst much other nonsense. How fondly I remember the many hilarious hours spent trying to pin down the cause of unexpected results.
I don't remember any specific examples, but consider:
#define SQ(v) v*v
int sq = SQ(++v);
In similar vein there is also the “do {} while 0” trick to allow macros to be appear like normal functions and end with semicolon.
Don’t even want to imagine how many more hacks would be needed to transform into another syntax using macros only.
Yeah that sounds like the easiest way to make your colleagues hate you
I "love" how we had more languages in the 70s (usually created as a one-off project for people with not so much user friendliness in mind) think m4, awk, tcl, etc
Some absolute lunatic solved this year's Advent of Code in m4; it was impressive.
Except C.
(It was a long time ago, and there was no C compiler on our IBM/370...)
For short scripts, awk is nice, but most people would use Python nowadays, and die hard Unix greybeards will use Perl or TCL depending on the mood.
Well I'm not Whitney's colleague but I really like his code.
I like it because it makes it easier for me to see the big picture. The forest and the mountain. It doesn't over-emphasize the bark on the trees; it doesn't drag on and make me scroll & jump through a maze of boring minute detail. At the same time, it doesn't actually bury and hide whatever detail there is; it's all there for when you need it. Whitney also generally simplifies things a lot and avoids tedious contortions others would make for portability or some theoretical conception of maintainability, readability, or vague "best practices". It's very straightforward and -- once you get past the Whitney vocabulary and general style -- there are no mountains of abstractions and layers you need to grok before you can work on the code.
The biggest problem is that after getting used to that style, "normal" code starts to feel like kindergarten books with very simple sentences written in horse sized capital letters, a handful per page. Except that those letters are not used to write a short children's story, but a complex labyrinthine machine, and the over-emphasis on minute detail just obscures the complexity and you end up with cross cutting concerns spread over thousands of lines of code and many many files. It might look clean and readable on the surface, yet: there be dragons. And nobody wants to tame those dragons because there's so much code. And then I find myself sighing and asking: why on earth do we need an entire page for what would really amount to a line of code if we didn't insist on spelling everything out like it's babby's third program after hello world? It's just tedious.
Whitney certainly writes his own sort of dragons, but it's easier to keep them all in your head. For example, the b compiler won't work out of the box on multiple platforms. I'm fairly confident I could port it without much effort, as long as the platform meets some basic requirements.