Live data from Hacker News

Let's Destroy C

gist.github.com

41–50 of 192 posts

Re: Let's Destroy C

#41

   > printf("%s\n", "Hello, World!");
   >
   > That's an awful lot of symbolic syntax.
Well... Because it should have been

    printf("Hello, World!\n");
in the first place?

One can do something like

    printf("%s,%s%c\n", "Hello", "World", '!');
and claim that C is awful and that

    displayln("Hello, World!");
is so much better.

Re: Let's Destroy C

#42

> printf("%s\n", "Hello, World!"); > > That's an awful lot of symbolic syntax. Well... Because it should have been printf("Hello, World!\n"); in the first place? One can do something like printf("%s,%s%c\n", "Hello", "World", '!'); and claim that C is awful and that displayln("Hello, World!"); is so much better.

This works for a literal, but the author was probably thinking of "print a string that comes from somewhere else" where you do the first thing to avoid format characters to be interpreted.

Re: Let's Destroy C

#43
post #42

> printf("%s\n", "Hello, World!"); > > That's an awful lot of symbolic syntax. Well... Because it should have been printf("Hello, World!\n"); in the first place? One can do something like printf("%s,%s%c\n", "Hello", "World", '!'); and claim that C is awful and that displayln("Hello, World!"); is so much better.

This works for a literal, but the author was probably thinking of "print a string that comes from somewhere else" where you do the first thing to avoid format characters to be interpreted.

Could be. But wouldn't then displayln() require the same string placeholder? Be it "%s", or "{1}" or someting else.

Re: Let's Destroy C

#44
I guess this article is to be taken lightly as kind of a "joke" ?

The first proposed macro displayln is the archetype of malpractice. What if I want to do:

if(some_condition) displayln("enjoy debugging that");

etc etc... almost all proposed changes seem to be awful ?

Re: Let's Destroy C

#45

> printf("%s\n", "Hello, World!"); > > That's an awful lot of symbolic syntax. Well... Because it should have been printf("Hello, World!\n"); in the first place? One can do something like printf("%s,%s%c\n", "Hello", "World", '!'); and claim that C is awful and that displayln("Hello, World!"); is so much better.

displayln is a _Generic.

All of these are valid:

    displayln("Hello, World!");
    displayln(100);
    displayln(1.8);
The point is, for simple things, to not have to specify how they appear.

> Well... Because it should have been

> printf("Hello, World!\n");

No. You don't really want to do that. If you're doing that, use puts [0] . All this requires is a modification to one string in memory and you have an injection vulnerability.

[0] http://www.cplusplus.com/reference/cstdio/puts/

Re: Let's Destroy C

#46
post #44

I guess this article is to be taken lightly as kind of a "joke" ? The first proposed macro displayln is the archetype of malpractice. What if I want to do: if(some_condition) displayln("enjoy debugging that"); etc etc... almost all proposed changes seem to be awful ?

It's a form of humour called sarcasm. It even has a convenient hint at the top to announce that it is "Let's destroy C"

Re: Let's Destroy C

#47

> printf("%s\n", "Hello, World!"); > > That's an awful lot of symbolic syntax. Well... Because it should have been printf("Hello, World!\n"); in the first place? One can do something like printf("%s,%s%c\n", "Hello", "World", '!'); and claim that C is awful and that displayln("Hello, World!"); is so much better.

How about just

    puts(“Hello, World!”)
which has been in C since the dawn of time?

Re: Let's Destroy C

#48
post #44

I guess this article is to be taken lightly as kind of a "joke" ? The first proposed macro displayln is the archetype of malpractice. What if I want to do: if(some_condition) displayln("enjoy debugging that"); etc etc... almost all proposed changes seem to be awful ?

I think I was pretty explicit:

> What if, for a moment, we forgot all the rules we know. That we ignore every good idea, and accept all the terrible ones.

Re: Let's Destroy C

#49

Big fan. I don’t see support for exceptions, maybe this can help: https://github.com/hraban/c-exceptions (I ended up using this in a job once. They didn’t hire me back...)

That's horrifying. I've opened a ticket to implement it. [0]

[0] https://todo.sr.ht/~shakna/CNoEvil3/9

Re: Let's Destroy C

#50
post #42

Earlier quoted context omitted.

This works for a literal, but the author was probably thinking of "print a string that comes from somewhere else" where you do the first thing to avoid format characters to be interpreted.

Could be. But wouldn't then displayln() require the same string placeholder? Be it "%s", or "{1}" or someting else.

displayln uses the massive _Generic in display_format to supply a large number of formatters automatically. [0]

[0] https://gist.github.com/shakna-israel/4fd31ee469274aa49f8f97...

Post reply on HN