Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    #define BEGIN {
    #define END }
> Believe it or not, this was common C practice back in the 1980s.

Was it, though? I used C back then (granted, learning it, and remember reading posts from Walter on what I think was FidoNet? BBS based, regardless), and never once saw anything like this OTHER than the stories of the bourne shell source code.

But, "common"? Feels kind of strawman.



Huge strawman and not at all common outside of the "we invert the norms up to 11" crowd.

The article opens with excerpts from the authors entry into The International Obfuscated C Code Contest which indicates the kind of crowd that treated such hijinks as commonplace.

You didn't see such things in dull boring let's just make simple code that works projects.

You'd see all that and more in the end of town that wanted to sketch out new language ideas ... the first "working" C++ implementations were made by swapping out the default C preprocessor for a more powerful text manipulation engine and really going to town on the macro magic.

It looked like early C++ but it went through a text mangling and came out as C and went into C compilers of the day.

ADDENDUM: I'm pretty sure the first C++ mockup I saw | worked with was the FrankenChild of source.txt | M4 preprocessor | C compiler | Asm | link

https://en.wikipedia.org/wiki/M4_(computer_language)

but that's going back a ways.


<nod> thanks, yeah I was actually a student at UCF where some OCCC winners were instructors (David Van Brackle and Mark Schnitzius, if memory serves).

And, I actually used `cfront` in my first job, and used the parameter to see the C it spit out as a way to learn how C++ did some things. Pretty interesting, if, as you say, nearly unreadable to humans!


i'd just like to point out that cfront was not a preprocessor - it was what today would be called a transpiler - it compiled c++ code into c.


Sure, I tangented off parent's post.


In the day it was controversial. I saw it in several magazine "type this code in to get this great program" articles back in the day, but since I was on an 8bit computer without a C compiler I never was able to type them in. There were several letters to the editor saying don't do that, but the magazine always did it anyway. (in about a year the magazine realized the 8bit and 32 bit computers had nothing in common so they split into two different magazines focused on their different niches - I don't know if if this controversy was ever resolved before magazines went defunct)


I never actually saw it in practice. But it was written about in several “don’t do this”-type articles, so maybe that made it seem more common.


Not common as far as I'm aware, but notably Bourne used this for his shell.



The one other example I know that morphs the language to that extent and to the detriment of readability by C programmers is the J interpreter[1,2]. But, once again, nobody (that I’ve read) claims it’s good or clear C. (Good C for those who speak J, maybe; I wouldn’t know.)

For a way to morph C syntax that does make things better, see libmill[3].

[1] https://code.jsoftware.com/wiki/Essays/Incunabulum

[2] https://github.com/jsoftware/jsource/tree/master/jsrc

[3] https://250bpm.com/blog:56/


Now that you mention this, I think I've also run across the J code before.


There was an article in Byte back in the day that recommended that define, along with several other to make C a more sane, pascal-like, language.

I wouldn't say it was common, but it was not that rare.


People coming to C from Pascal would do this initially, and I still see attempts at using the C preprocessor to look like the author's other favorite language.

It's not as rare as you suggest.


Consider that this was a time before the internet. People had much less communication with other programmers in those days. Lots of people learned C by picking up a book, not reading about it online. There really wasn't much of a way to learn best practices from others.


I can confirm I saw it done a few times.


I'll agree then that our experiences can be different.

But ...

> It's not as rare as you suggest.

is still IMO a far cry from "common".


> #define BEGIN { > #define END }

Had no idea about this but it makes sense!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: