Reminds me of a C++ codebase I once had to inspect that was entirely written as if it were written in Java. With camelcase naming for everything, getters and setters for every class variable, interfaces everywhere.
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.
> camelcase naming for everything, getters and setters for every class variable, interfaces everywhere
This is not far off from the guidelines in many cases, e.g. Windows code (well, not every variable of course.) A lot of Java design was copied from C++.
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.
I was hoping to see a “this is just for fun” disclaimer but didn’t see one. Please never actually use this in a project that other people will have to read or contribute to.
Picking out an obvious define function that compares a float with a float sum of that nature should indicate an good understanding of why that might be called wizardry and deserving of a second look.
Hats off to the peer comment that suggested scaling against epsilon rather than simpliy regurging the substitution "as was" from the header.
The scaling is better in general, optional in some specific contexts.
it uses absolute difference epsilon equality ('close enough to be considered equal'):
static int pretty_float_equal (float a, float b) { return fabsf(a - b) < FLT_EPSILON; }
static int pretty_double_equal (double a, double b) { return fabs(a - b) < DBL_EPSILON; }
static int pretty_long_double_equal (long double a, long double b) { return fabsl(a - b) < LDBL_EPSILON; }
Type names are nice; Perfect choice for the in-built func macros (like min); Len -- love it. Named boolean operators -- might be a bit much but go for it; Ternaries are illegible so you can only improve them; Not completely sold on all your loop definitions but some make sense to me; Resource tracking is impressive; The for... look a bit ugly -- could probably call it something else.
All in all: quite a solid attempt. I'll give you 8/10 for the design of this. The way you sketched this out in C using macros is really elegant. This actually looks like good code. Would I use it? It's a new language and I like C already. It could help people learn C and think about language design. Since the way you've done this is very clear.
> Deprecate Lua, Python, JavaScript, Ruby and a dozen other languages, because Pretty C is the ultimate scripting language, but lightning-fast and strongly typed!
Meta: the naming is ... strange.
The actual name of the repo is "pretty.c", but the name used for the language/dialect/result/horrorshow[*] is "Pretty C".
The actual code file you include is called "pretty.h", which makes sense since it's a header, of course. Confusing!
Edit: escapes.
[*] Yes, I'm a C programmer, currently hunting for black-marked insulin to combat the rapid-onset diabetic attack from all that sugar. Sorta.
I mean, don’t say the repo didn’t warn you!
> The goals for Pretty C are: Provide so much syntactic sugar as to cause any C developer a diabetes-induced heart attack.
It claims to be a scripting language but you still have to compile the programs. Boo! Add CINT (https://root.cern.ch/root/html534/guides/users-guide/CINT.ht...) and you can have instantaneous execution and even a REPL!
Reminds me of a C++ codebase I once had to inspect that was entirely written as if it were written in Java. With camelcase naming for everything, getters and setters for every class variable, interfaces everywhere.
You ain't seen nothin. Check out the bourne shell source code from unix seventh edition. https://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd... I can't believe it's not ALGOL.
https://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd...
wow.
thanks for this gem.
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.
Good job they weren't using MSVC I guess...
https://learn.microsoft.com/en-us/cpp/cpp/property-cpp?view=...
I had that as well but also Java passes strings in as f(String *) so the C++ code was f(new String("Hello")
> camelcase naming for everything, getters and setters for every class variable, interfaces everywhere
This is not far off from the guidelines in many cases, e.g. Windows code (well, not every variable of course.) A lot of Java design was copied from C++.
I have not decided how I feel in general, but:
> Everyone defines these, so why not provide them?
Honestly, that's fair.
This should have been invented 50 years ago!
Is it possible to tangle the Readme into pretty.h? In other words, are the codeblocks in the orgfile exhaustive.
I love the literate way you have explained your thought process in the readme.
> ifnt for if(!...).
"unless" seems more readable than "ifnt".
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.
Wow, neat! The wildest part to me is
> And it’s backwards-compatible with C and all of its libraries!
I can't wait to give it a shot! This looks like a riot.
Have you heard of Zig?
It requires a different compiler. This is just a collection of C preprocessor macros
This made me immediately think whether MIT Loop of Common Lisp was an inspiration here. Checked the user's profile and sure enough, a lisper!
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.
as someone that just started C, it looks pretty :)
> turn any codebase into a beginner friendly one
Okay then.
I was hoping to see a “this is just for fun” disclaimer but didn’t see one. Please never actually use this in a project that other people will have to read or contribute to.
> Provide so much syntactic sugar as to cause any C developer a diabetes-induced heart attack.
seems like its obvious to me that its a joke
It's a joke that I would happily use.
This is as horrific as it is wonderful.
`equal(0.3, 0.2 + 0.1); // true`
how is this wizardry possible?
It uses type dispatch to perform an epsilon comparison:
So it’s https://docs.python.org/library/math.html#math.iscloseIs What Every Computer Scientist Should Know About Floating-Point Arithmetic wrong ??!!
addendum: why are obviously rhetorical questions are taken so literally here?
It's meant as both humorous and a nerd snipe :)
Because text doesn't convey sarcastic voice tonality, so the intent is far from obvious.
Sarcastic? Okay, if you say so.
Picking out an obvious define function that compares a float with a float sum of that nature should indicate an good understanding of why that might be called wizardry and deserving of a second look.
Hats off to the peer comment that suggested scaling against epsilon rather than simpliy regurging the substitution "as was" from the header.
The scaling is better in general, optional in some specific contexts.
it uses absolute difference epsilon equality ('close enough to be considered equal'):
This is wrong code. It only works somewhat correctly when a and b around 1.
Yeah, should be scaled like |x - y| <= ε * max(|x|, |y|)
static int pretty_float_equal (float a, float b) { return fabsf(a - b) < FLT_EPSILON; }
This is terrifying
Evil, yet beautiful. Hats off to you.
Type names are nice; Perfect choice for the in-built func macros (like min); Len -- love it. Named boolean operators -- might be a bit much but go for it; Ternaries are illegible so you can only improve them; Not completely sold on all your loop definitions but some make sense to me; Resource tracking is impressive; The for... look a bit ugly -- could probably call it something else.
All in all: quite a solid attempt. I'll give you 8/10 for the design of this. The way you sketched this out in C using macros is really elegant. This actually looks like good code. Would I use it? It's a new language and I like C already. It could help people learn C and think about language design. Since the way you've done this is very clear.
So sweet :))
I'm reminded of the guy who did
and a whole bunch of other macro-larkey just to make C look more like Pascal. Only then would he deign to code in it.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.
I cannot wait to show this to a colleague of mine. He will kill me XD
That is pretty cool
> Deprecate Lua, Python, JavaScript, Ruby and a dozen other languages, because Pretty C is the ultimate scripting language, but lightning-fast and strongly typed!
Umm… that’s quite the goal.
I’ll stick with deprecated Python.
love. It.
Can we just pascal?