News for hackers. Stuff that matters.
Re:C4: C in Four Functions (2014) by zelphirkalt on Tuesday February 18, 2020 @06:20AM (#22355131)
The repo says "An exercise in minimalism." – Looking at the code, there is nothing minimalistic about it. Perhaps in terms of C it can be called that, but in terms of programming languages in general, this cannot be called "minimal" at all.

The code quality is terrible. Few explaining comments (actually mos of those are only 1 or 2 words, so not explaining anything at all) and almost all variable names consist of 1 or 2 characters, which do not say what the thing actually is. Then to achieve this arbitrary goal of doing it "in 4 functions" (actually procedures) loads of stuff was apparently stuffed into 4 those 4 functions, so much so, that they are longer than a whole page of code. Most of it looks like gigantic switch statements. It's horribly written code. It looks like what I think of as a C nightmare.

I will admit, I could not write such a thing myself. I lack the knowledge for writing such a low level stuff, do not use C, and if I had that knowledge to do it, my inner drive to do a cleaner job than anything remotely looking like that code, would prevent me from ever sharing such a thing with anyone in public. At least group cases into procedures as it makes sense. Even people writing this low level type of code should be aware of how unreadable that code is, right?

Re:C4: C in Four Functions (2014) by jackewiehose on Tuesday February 18, 2020 @07:27AM (#22355451)
> I lack the knowledge

And yet you have a strong opinion about how terrible it is.

It is very minimal and it is very readable. It is actually a joy to read. You have no idea what a C-nightmare really is.

Re:C4: C in Four Functions (2014) by zelphirkalt on Tuesday February 18, 2020 @07:39AM (#22355514)
Yep, I can have a "strong" (what is strong?) opinion about it, because I know what readable code in other programming languages looks like and it certainly does not look like that. I did use C a few times in assignments and still my code had more comments and better readable names for basically everything than the code present in the repository.

Wait, you are telling me, that people write even less readable code in C? Perhaps you are right. Perhaps people can really be that much without care.

It still does not make this code "very readable". If it was very readable, I would have a vague idea about what each of the "functions" does from reading its name or its docstring. Oh wait, there is no docstring at the beginning of each of the "functions" and the name consists of one word, sometimes abbreviated word. And the variable names don't give me hints either. I think our definitions of readable code simply differ quite a lot. When I write code myself, I am unwilling to accept code on that readability level, but we probably have different standards.

Perhaps for entertainment purposes only, you could show me a real C nightmare. I do honestly believe you, that there is worse ;)

Re:C4: C in Four Functions (2014) by clarry on Tuesday February 18, 2020 @08:15AM (#22355757)
I don't understand russian, therefore russian is unreadable.

I don't understand mathematics, therefore math is undreadable.

I don't understand music, therefore sheet is unreadable.

That is your problem in a nutshell.

Meanwhile, people here take a glance at the code and immediately get it, because it is written in a language they understand. These people tend to find it quite readable -- not necessarily an example of most pretty code, but nevertheless readable.

Re:C4: C in Four Functions (2014) by zelphirkalt on Tuesday February 18, 2020 @08:59AM (#22356070)
Still you do not address the simplest of points, which there are: meaningful variable names, meaningful procedure names, explaining comments. All of which are minimum standards for software development these days.

I may be a C noob, as I already and in an honest way stated in the very first post, but my points still stand. Those are not some subjective things. It is very clear, that those things add to readability, yet the code does not have them.

Re:C4: C in Four Functions (2014) by clarry on Tuesday February 18, 2020 @09:26AM (#22356255)
I addressed those points implicitly. Those names are meaningful, in context, to the people who understand the language; just as symbols in math are, in context, understandable to those who understand mathematics. And thus there is no need for comments. Arguably, there are too many comments, because I saw many that said something obvious without adding anything useful. Short identifiers aid reading for people who understand the language, because it allows them to focus on what the code does (or, rather, how exactly it does it) rather than what the things in it are (which is obvious to people who understand the language).
Re:C4: C in Four Functions (2014) by klyrs on Tuesday February 18, 2020 @08:13AM (#22355746)
> Wait, you are telling me, that people write even less readable code in C? Perhaps you are right. Perhaps people can really be that much without care.

I'm a person who has written a lot of c, readable and unreadable. It's not that folks don't care; I find that notion slightly offensive. It's that a lot of c programmers care about different things. And, especially those of an older school have a different mindset.

When you read c source, especially that labelled "exercise in minimalism", you should approach it as hallowed. Enter the file with a sense of reverence; lose the ego; ask not why the file wasn't written in service to you. As you have here, tsk tsk. Expect a challenge, a puzzle. Ignore the variable names; they may be misleading -- learn for yourself what role each variable takes on each line -- some of us will reuse a variable for multiple purposes throughout its lifetime. Humble yourself with the understanding that the code was not written for you. It was written for a machine infinitely more patient and methodical than you. Use that machine to execute and debug, watch and analyze, to discover the true meaning.

https://www.ioccc.org

Re:C4: C in Four Functions (2014) by saagarjha on Tuesday February 18, 2020 @10:43AM (#22356809)
I agree with you, the code isn’t as readable as it could be. But that’s precisely the point here: it’s an exercise in artistic license, so its conciseness is a feature, not a bug. Think of it like poetry.
Re:C4: C in Four Functions (2014) by psychoslave on Wednesday February 19, 2020 @03:03AM (#22363833)
I can recognize why it will generates a feeling of elegance, as some say with short mathematical concise formula. However this is more like of esoteric practices: it's meaningful for the selected few that went through the initiation, and has only the charming/frustrating taste of mystery for other.

But, at least to me, it's nothing like poetry. Anyone, without any specific formation, can read poetry and understand something of it. In poetry, artistic license is the exception, not the general rule. The deep meanings, intertwines between form and content, the attention to metre, the use of allegories, and so on, will not be consciously grabbed by every reader. But still anyone that has the base language knowledge required can read it and find some sense to it.

Re:C4: C in Four Functions (2014) by joppy on Tuesday February 18, 2020 @07:24AM (#22355428)
Gigantic switch statements are pretty much the best way to do a parsing style thing in a straightforward basic manner, and it is after all, “an _exercise_ in minimalism”. There are short variable names but again there are not many variables used in the whole program. This was not code written to be approachable by any other random team member without further context, it was written for a different purpose entirely.

Perhaps people would be less reluctant to show their code in public if it were not so often criticised for falling short of some criteria that the author was never intending to meet?

Re:C4: C in Four Functions (2014) by zelphirkalt on Tuesday February 18, 2020 @07:50AM (#22355595)
> This was not code written to be approachable by any other random team member without further context, it was written for a different purpose entirely.

Ah, let me quote: "Programs must be written for people to read, and only incidentally for machines to execute." – Hal Abelson

And I believe he is right. If you don't write your programs for other people to read, then they not worth being written in that way. Always consider that next person, who needs to read and understand your code. If you don't, then you are not much of a great team player at all. It's great you can do some brain acrobatics, but not much use, if the only one on team being able to understand your code is yourself. I don't know how many 1 person software developer jobs there are still out there, but I guess the number is vanishingly small, compared to team jobs. I would not want someone in my team, who does not pay attention to keeping things very readable.

> Perhaps people would be less reluctant to show their code in public if it were not so often criticised for falling short of some criteria that the author was never intending to meet?

True, you got a point here. But do we want this display of code? However, personally, I'd probably not miss reading such code and maybe it would even be good for the entire profession of software development, if such code was not displayed as something to be achieved but rather something to be shunned.

Re:C4: C in Four Functions (2014) by joppy on Tuesday February 18, 2020 @09:29AM (#22356286)
It’s not a piece of software worked on by a team though. It’s a personal project, written to by one person to be understood by that person, and incidentally I think some effort has been made to make the code easier to read for random passers-by on the internet. Not every piece of code has to be written to meet the same goals, there is a large spectrum.

I write both terse notes to myself, and longer more well-thought out sets of notes to distribute to undergraduates in classes I teach. I wouldn’t give the undergraduates my personal notes - they are simply too unpolished and terse - but my colleagues find them very helpful on occasion. Is it wrong to have two different ways of writing?

I would say this C implementation leans somewhere between “note to self” and “arty exploration”. Is it worth being written? I don’t think you or I could be the judge of that, but the author obviously thought so. Live and let live.

Re:C4: C in Four Functions (2014) by userbinator on Tuesday February 18, 2020 @08:10AM (#22355735)
Your amount of unwillingness to learn and understand is disturbing. Lowest-common-denominator dumbing-down is not how we advance our craft. There are many others who can understand it, perhaps you should ask yourself why you can't.

If you think this is unreadable, then you are not qualified to read it --- yet. I implore you to try; maybe it will actually be enlightening.

Re:C4: C in Four Functions (2014) by zelphirkalt on Tuesday February 18, 2020 @08:55AM (#22356049)
Nice, now we are getting personal! Interesting, how much you know about me from just a comment. And still you miss the simplest of points, which there are: meaningful variable names, meaningful procedure names, explaining comments.

Perhaps it is not as much that "I can't" because of incapability or stupidity, but simply, that I wont, because of the lack of care given to creating something meeting minimal standards for modern software development and best practices.

Re:C4: C in Four Functions (2014) by userbinator on Tuesday February 18, 2020 @08:01PM (#22362117)
modern software development and best practices

Yes, that's all too familiar to me. The dogmatic cargo-culting buzzword-bingo "religion" whose only claim to fame is in effectively producing gargantuan Enterprise Quality™ software --- I mean solutions --- which everyone inevitably hates because they are ridiculously bloated and overengineered to the point that the simplest things take an absurd amount of time and energy, and also have abysmal UX too...

"best practices are best not practiced."

Re:C4: C in Four Functions (2014) by jfkebwjsbx on Tuesday February 18, 2020 @08:33AM (#22355895)
No reasonable amount of comments will make up for a lack of domain knowledge.
Re:C4: C in Four Functions (2014) by rramadass on Wednesday February 19, 2020 @04:58AM (#22364270)
Exactly! You hit the nail right on the head.
Re:C4: C in Four Functions (2014) by jfkebwjsbx on Tuesday February 18, 2020 @07:03AM (#22355321)
The code is obviously not intended for production, but it is straightforward nevertheless for anyone with C experience.
Re:C4: C in Four Functions (2014) by jabbequbs on Tuesday February 18, 2020 @12:45PM (#22358112)
I've only skimmed the code but it seems to me that the repo is an art piece just as much or more than it is a software project. The medium is code but that doesn't mean that it needs to adhere to professional standards anymore than someone's woodworking project needs to adhere to building codes.
Re:C4: C in Four Functions (2014) by hibbelig on Tuesday February 18, 2020 @08:19AM (#22355792)
It's a C compiler in 500 lines. I guess there are C compilers in 500,000 lines.