7 ms·
The code in C that suppose to be written like this is usually never written first like that, its like pretending writing minified js by hand from scratch. Usual
by countWSS 3y ago
The code in C that suppose to be written like this is usually never written
first like that, its like pretending writing minified js by hand from scratch.
Usually the code is contracted and "minified" from large program to
fit entire program into 1-3 screens, the person who manually "minified" it to
that state will know its expansion but other people will dismiss it as obfuscated C,
its an old technique to fit lots of code into 80x25 type terminal.
Not surprising since J is optimized for code density per screen.
- clausecker 3y agoNope, Whitney just codes like this.
- colonwqbang 3y ago> Not surprising since J is optimized for code density per screen. I don't think that's the whole story. J is dense like traditional mathematical notation, but can be executed by machine. Experienced J programmers use it to convey mathematical ideas. See for instance: https://www.jsoftware.com/jwiki/Puzzles/Unit_Fraction_Sum https://www.jsoftware.com/jwiki/Puzzles/Unit_Fraction_Sum Although I can't read the notation, I appreciate the role it can play. Plain C (or whatever) code isn't an efficient vehicle for ideas like that. Numpy/matlab comes closer but J is a stronger approximation of traditional maths notation.
- crabbone 3y agoI like J. Especially because it has a saner way to write it (it doesn't have to look like as if you accidentally forgot a null terminator in C strings, all the traditionally short identifiers have a long and understandable form). I feel like it's very regrettable that the superficial aspect of J (the very hard to read syntax) is standing in the way of some very nice ideas. To comment on mathematical notation. Before I was a programmer, I was a typographer. During my study in art academy, I invented a bunch of fonts, one of my long time projects was to make Hebrew look more like Latin fonts for example (this is a long-standing issue in Hebrew typography, with several historical attempts, but still not quite resolved). Afterwards I worked in a printing house, paginated a newspaper, typeset a bunch of books etc. Among my coworkers (esp. in the newspaper) I was sort of known for trying to automate stuff, so, I was often suggested as a candidate for "difficult" typographical tasks, like setting sports tables, chess diagrams, music sheets and the most damned and hated kind of typographical work: math formulas. I've helped publish a course book on linear algebra for a university. It was a multi-year project which I joined in the middle. I have never seen so much pain, struggle and reluctance as I've encountered while working on this thing. People tasked with proofreading demanded extra pay for proof-reading this stuff, and still wouldn't do it. Just put it away and later explain that they had other things to do. The lady who had to translate the mostly hand-written, or sometimes typed on a typewriter manuscript would just skip work on the days she was supposed to input the manuscript into our digital system. Everyone passionately wanted this project to burn in hell. And the reason for this was the mathematical notation. Typical proofreading techniques don't work on math formulas. The text is impenetrable to anyone, often even to the people who wrote it, including both the author and the editor. Parenthesis are a curse, because in the manuscript they are one of the elements that is most commonly forgotten or misplaced. Single-letter variables are the other one. Overloading the same symbols with different meaning is yet another one. It gets worse when the same symbol is used in its normal size, subscript and superscript. ---- When I talked about my experiences to people with degrees in math, they way they tend to respond to this is by saying that "math is overall so hard, that mathematicians don't typically notice the extra struggle they incur on themselves by the bad language choices, it pales in comparison to the difficulty of the main problem they need to solve". And, I kind of can see it... on the other hand, I see no reason _the students_ have to endure the same torture. They aren't solving any novel mathematical problems. Their task is usually reading-comprehension combined with memorization. And then I saw Sussman book where he uses Scheme to write math formulas (I think it was about physics, but it still used a lot of math). Dear lord, it was so immeasurably better than the traditional mathematical notation. I really wish more people joined this movement of ditching the mathematical notation in favor of something more regular and typography-friendly as Scheme...
- Koshkin 3y agoI, on the other hand, am dreaming of being able to use mathematical notation in my code. Sort of like what Fortran has helped with, only on a much larger scale.
- moonchild 3y agoYou would have liked fortress.
- crabbone 3y agoAs with a lot of things, some people may enjoy arduous and very low-yield process for all sorts of reasons. I, for example, like baking sourdough bread. As with the bread, which comes out more or less comparable quality to what I can buy from the local grocery in exchange for much less effort, I get certain satisfaction from doing it myself. But, if I had to do this on an industrial scale (and I worked in a bakery, although very briefly), I'd want to kill myself if I had to deal with the same kind of process. Math language is very similar in this regard. It's kind of nice, like a calligraphy piece. Sometimes it takes a master month to write just a few words in a visually appealing way, but if this was the expectation for everyday boring tasks, that'd be a completely different story.
- Koshkin 3y agoMy impression has always been that it is mathematical notation that is indeed high-yield and low-effort. That’s why Fortran was/is successful.
- kelas 3y ago> math notation is indeed high-yield and low-effort low-effort is perhaps “your mileage may wary”, as they say :) but the yield per square inch of paper does indeed make math the most powerful and expressive language known to humans. On that note, Ken Iverson was very concerned that tons of mathematical symbolic conventions and speak overlap and conflict with each other to an obscene degree. As we all know, that little book he wrote on this very subject eventually got him a Turing award when people finally realized what he did there. That said (and please no offense APL and typography fiends who are reading this) a considerable portion of the funny APL chars was a hard compromise dictated by economics and physics of IBM Selectric typeball. With that in mind, if you take a fresh look at the original APL charset, you will see that much of it is stone-stupid overtypes of two ASCII chars. Why? Because IBM, that’s why. El Cheapo.
- andrewla 3y agoWhile there are people that do this, I do not think that Whitney is one of them. This code is not obfuscated; it uses macros and strategically defined functions to allow writing code in a style similar to APL that appears natural (-ish?) to someone fluent in that programming style.
- kelas 3y ago> not obfuscated absolutely not. porting it to ISO C was a very fun and smooth ride, also added two adverbs atw forgot to add in 1989 (see over/scan) and a header file with some handy accesssors (atw usually does that, but he was lazy that day) > to someone fluent in that programming style what people often don’t realize is just how fast one can pick up atwc style, and how hard it is to ever go back :)
- max_ 3y agoHow do we pick up that writing style.
- kelas 3y agoOne possible way is to look at a header file i once gave to a 13yo girl. ever since she says she has no idea why people write tall c: https://github.com/aaalt/altc https://github.com/aaalt/altc
- moonchild 3y agolearn apl (k and j count)
- kelas 3y agotrue. only k is faster, easier to learn, and does the trick :) that said, i hold the view that mastering programming in an ultra-high level language such as APL or k does not absolve a computer programmer from learning lingua franca of our trade, which is due to k&r, will stay around for a very long time, and is called C. people who don’t know c are ok, only they are not involved in computer programming. their field is known as software development. feel the difference. i once attempted to convey my own understanding of this divide in a chapter titled “no stinking loops”, which is a nod to Apter’s mandatory nsl.com: https://github.com/kparc/kcc#no-stinking-loops https://github.com/kparc/kcc#no-stinking-loops
- kelas 3y ago> The code in C that suppose to be written like this is usually never written first like that usually not. but we prefer to write it first this exact way, and there are good reasons for rhat. > obfuscated c it is not. this style is extremely regular, very readable and writable, and escapes a whole galaxy of typical C blunders. i can expand on that if you wish.
- hnfong 3y agoPlease do. Although I'll probably never write C in that style, most of us here will probably learn a few things that will eventually prove useful. (And it probably will also serve as a historical document of a "skill"(?) that is apparently soon to be lost to obscurity...)
- kelas 3y ago> please do now that i think of it, i already did just that once, only forgot. getting old sucks, and also forgetting things is a great skill i learned from atw. as he likes to say, “kelas, ignorance is bliss”. Here you go - all you ever need to know about how to read and write atwc: https://github.com/kparc/bcc/blob/master/d/sidenotes.md#style https://github.com/kparc/bcc/blob/master/d/sidenotes.md#styl...
- orthoxerox 3y ago> inequality x!=y is not used at all, because it is two chars. instead, we test with x-y, which holds true when operands differ I think this is the line in the document that represents his coding style the most. Sacrificing legibility for plebs to save one character per comparison.
- kelas 3y ago> represents his coding style the most i agree that atw’s inequality test is a bit cheeky, but like everything else it is a matter of habit. a convention. eventually you just begin to see what is subtraction and what is comparison. here’s another classic example of the same effect: x=x+1 makes perfect sense to everyone, right? wrong. to some, the right answer is “no, they are not”.