←back to thread

Be Aware of the Makefile Effect

(blog.yossarian.net)
431 points thunderbong | 9 comments | | HN request time: 0.821s | source | bottom
1. teo_zero ◴[] No.42663964[source]
> the tool (or system) is too complicated (or annoying) to use from scratch.

Or boring: some systems require boilerplate with no added value. It's normal to copy & paste from previous works.

Makefiles are a good example. Every makefile author must write their own functionally identical "clean" target. Shouldn't there be an implicit default?

C is not immune, either. How many bits of interesting information do you spot in the following excerpt?

  #include <stdio.h>
  int main(int argc, char **argv)
  {
    printf("Hello\n");
    return 0;
  }
The printf alone is the real payload, the rest conveys no information. (Suggestion for compiler authors: since the programs that include stdio.h outnumber those that don't, wouldn't it be saner for a compiler to automatically do it for us, and accept a flag to not do it in those rare cases where we want to deviate?)
replies(7): >>42664020 #>>42664022 #>>42664034 #>>42664043 #>>42664258 #>>42664587 #>>42664813 #
2. skirge ◴[] No.42664020[source]
more implicit behaviors more surprises, like security bugs because default functionality or conversions happen
3. oguz-ismail ◴[] No.42664022[source]
> wouldn't it be saner for a compiler to automatically do it for us

no

4. lucianbr ◴[] No.42664034[source]
> since the programs that include stdio.h outnumber those that don't

I don't think that is true. There is a lot of embedded systems C out there, plus there are a lot of files in most projects, and include is per file not per project. The project might use stdio in a few files, and not use it in many others.

5. ◴[] No.42664043[source]
6. brabel ◴[] No.42664258[source]
> The printf alone is the real payload, the rest conveys no information.

What are you talking about? Every line is important.

    #include <stdio.h>
This means you need IO in your program. C is a general purpose language , it shouldn't include that unless asked for. You could claim it should include stuff by default, but that would go completely against what C stands for. Code shouldn't have to depend on knowing which flags you need to use to compile successfully (at least not in general like this).

    int main(int argc, char** argv)
Every program requires a main function. Scripting languages pretend they don't, but they just wrap all top-level code in one. Having that be explicit, again, is important for a low level language like C. By the way, the C standard lets you declare it in a simplified manner:

    int main(void)
Let's ignore the braces as you could just place them on the same line.

    printf("Hello\n");
You could just use `puts` here, but apart from that, yeah that's the main payload, cool.

    return 0;
The C standard actually makes this line optional. Funny but I guess it addresses your complaint that "common stuff" perhaps should not be spelled out all the time?

So, here is the actual minimalist Hello world:

    #include <stdio.h>
    int main(void) {
        puts("Hello world\n");
    }
replies(1): >>42667465 #
7. chikere232 ◴[] No.42664587[source]
> Makefiles are a good example. Every makefile author must write their own functionally identical "clean" target. Shouldn't there be an implicit default?

At some point you have to give the system something to go on, and the part where it starts deleting files seems like a good one where not to guess.

It's plenty implicit in other places. You can for example, without a Makefile even, just do `make foo` and it will do its best to figure out how to do that. If there's a foo.c you'll get a `foo` executable from that with the default settings.

8. pantalaimon ◴[] No.42664813[source]
My main frustration with make has usually been with too much (surprising) implicit default behavior, not the lack thereof.
9. teo_zero ◴[] No.42667465[source]
Thank you, but this thread was not about writing good code, but rather how often one ends up acritically copying existing "legacy" parts without even attempting to understand it.

I probably used the wrong words: "conveys no information" was meant as "is less meaningful than the printf". Just like switching on the PC every morning is essential, but if you ask me what my job's about, I wouldn't mention it.

In the same vein, I'm convinced that the printf is the part that expresses the goal of the program. The rest, the #include, the main(), even with the optimizations that you suggested, is just boilerplate, the part that is usually copied and pasted, not because it's not useful and not because it's too difficult to get right, as the original article claims, but because it's boring.