Live data from Hacker News

Pretty.c

github.com

51–60 of 227 posts

Re: Pretty.c

#51
post #26

All that is missing is a garbage collector. Should be possible to implement one by overriding malloc & friends?

You can use the Boehm-Demers-Weiser GC with C. It's conservative, because it has to be with C, so it may/will miss things (it will treat integers etc. as potential pointers, and so avoid freeing anything "pointed to" by them), and so it works best as an extra layer of protection/leak detector, but it can be used as a replacement for freeing memory too.

Re: Pretty.c

#53
post #34

Earlier quoted context omitted.

Another bikeshed is the infinite for(;;) loop being called "always" I've seen "loop" in other languages. But Qt calls it "forever", and that is indeed very pretty. Very Qt, even

> I've seen "loop" in other languages. But Qt calls it "forever", and that is indeed very pretty. Very Qt, even You can break a "forever" loop so I think "loop" is a better name.

I don’t know why “repeat” isn’t very common in place of while/loop/etc; it works out nicely grammatically.

    repeat {}
    repeat while  {}
    repeat {} while 
    repeat  {}

Re: Pretty.c

#54

Earlier quoted context omitted.

Wow, I was not expecting that! Was this style of C common back then? Before he wrote the Bourne shell the author wrote an ALGOL compiler, and ALGOL inspired Bourne syntax: https://en.wikipedia.org/wiki/ALGOL_68C

There were article suggesting #define BEGIN { and #define end }; to make C look more like Pascal. I think in Europe C was not as common as other languages at the time so the terseness looked odd.

Also because the special characters were (and are) difficult to type on European keyboards.

Characters like []{}\|~ are behind multi-finger access and often not printed at all on the physical keys (at least in the past). You can see how this adds a hurdle to writing C…

Pascal was designed by a European, so he preferred keywords which could be typed on every international keyboard. C basically just used every symbol from 7-bit ASCII that happened to be on the keyboards in Bell Labs.

Re: Pretty.c

#55
post #27
post #14

Earlier quoted context omitted.

https://en.wikipedia.org/wiki/Stephen_R._Bourne https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh

Now that's just silly. And I see the backwards keyword terminators (LOOP/POOL). I have wondered why we have case/esac, if/fi but while/done. I imagine the author himself figured that while/elihw would just be entirely ridiculous.

Just call it wyl/lyw. Pronunciation maintained, problem solved.

Re: Pretty.c

#56
post #8

`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?

It uses type dispatch to perform an epsilon comparison: static int pretty_float_equal (float a, float b) { return fabsf(a - b) So it’s https://docs.python.org/library/math.html#math.isclose

This code is incorrect, but I don't blame them. :) Probably one of the most common float-related mistakes, even among people who "know how floats work".

FLT_EPSILON is the difference between 1.0 and the next larger float. It's impossible for numbers less than -2.0 or greater than 2.0 to have a difference of FLT_EPSILON, they're spaced too far apart.

You really want the acceptable error margin to be relative to the size of the two numbers you're comparing.

Also, everyone should read the paper "What, if anything, is epsilon?" by Tom7

Re: Pretty.c

#57
Can someone clarify whether this is intended as a joke or whether the author is actually confused? I mean, nothing about this makes sense: it's not "scripting"; it claims to introduce "strong typing" while it does nothing about typing; it introduces all kinds of operator aliases "modeled after Lua and Lisp" that are present in neither of these languages. But it's not an obvious parody either, so I'm genuinely not sure.

Re: Pretty.c

#59
post #34

Earlier quoted context omitted.

Another bikeshed is the infinite for(;;) loop being called "always" I've seen "loop" in other languages. But Qt calls it "forever", and that is indeed very pretty. Very Qt, even

> I've seen "loop" in other languages. But Qt calls it "forever", and that is indeed very pretty. Very Qt, even You can break a "forever" loop so I think "loop" is a better name.

"indefinitely" might be a better name. (But I think loop is indeed a better name.)

Re: Pretty.c

#60
I've seen this implementation of defer a few times now. I really dislike calling this defer (like the keyword in Go) as the given code won't be executed on return.
Post reply on HN