Hacker News new | ask | show | jobs
by com2kid 639 days ago
> is like asking which syntax (letters) is faster - syntax of Rust, Java or C++?

This is actually a bad example because C style decls are provably, objectively, bad. They make parsing harder and once the types are non-trivial, they are absurdly hard to read and write. The case in point being non-trivial function pointers in C. The syntax for declaring a function pointer of a type that returns a function pointer is hidious.

Meanwhile here is how you define a function in that returns a function that returns a string in a modern language (Typescript):

    type NumberToStringFunction = (num: number) => () => string;
Compare that to C

    typedef char* (*(*NumberToStringFunction)(int))(void);
> And same as with CPUs - everything is up to the implementation

It is very easy to add CPU features that place a hard limit on performance. That is why Arm64 dropped all the conditional stuff! (Any instruction that limits the potential branch prediction is going to severely impact potential CPU performance.) History is littered with failed CPU architectures that just couldn't scale up, Intel's famous folly being Itanium.

That said, x86 is mature and it dropped some of its less pleasant aspects with x64.

Also IMHO drivers matter more for laptops than the CPU does. A bad driver keeping the GPU on w/o need or just not being able to enter the lower sleep states in general, will kill battery faster than anything else.

3 comments

>This is actually a bad example because C style decls are provably, objectively, bad. They make parsing harder and once the types are non-trivial, they are absurdly hard to read and write. The case in point being non-trivial function pointers in C. The syntax for declaring a function pointer of a type that returns a function pointer is hidious.

The example is good, I just dont understand why you focused on compiler performance or developer experience. It doesnt imply program's performance.

We were talking purely about performance/energy eff of generated binary, not other RELEVANT things like developer experience/low compilation times because it is outside the scope of this discussion.

Yes, C++ is poorly designed language, but point that syntax (letters) don't imply language's performance stands. The result is up to the implementation: compiler, runtime/vm, std libs, etc.

ah I didn't understand that your "syntax (faster)" referred to the compiler speed, I thought you were referring to the speed of development/engineering!
Actually I meant speed of generated program/binary :P
The funny part of your example is, decoding AArch64 instructions (argubly, "parsing") is also easier than decoding x86_64.

Yet GP's point still holds.

> This is actually a bad example because C style decls are provably, objectively, bad.

I found your comment extremely funny. You singled out the language which is not only one of the most popular languages ever designed but also the one whose syntax inspired or was straight out cloned by the bulk of the world's most popular programming languages.

Yes, the programming language defined in the 70s isn't perfect and has a couple of kinks that could be improved. As does every single programming language.

But when you see a curly-bracket language you see programming language designers yelling to the world that C got way more things right than any other language not derived from C, which is the exact opposite of your unbelievable claim.

> Yes, the programming language defined in the 70s isn't perfect and has a couple of kinks that could be improved. As does every single programming language.

Back in the 70s, they didn't know as much about writing parsers as we do now. The field was much younger.

There is a reason that Go's declaration syntax is not based on C's, despite Go being created by one of the co-creators of C.

> which is the exact opposite of your unbelievable claim.

I'm not making claims, I'm stating facts. Parsing C declarations is difficult. Writing C declarations is difficult. Reading non-trivial C declarations is difficult. For examples of this in action read https://en.wikipedia.org/wiki/Most_vexing_parse.

C++'s horrific syntaxial complexity is the ultimate end of C-style decls. C++'s syntax is, again, objectively overly complicated for what it does. The reason it is overly complicated it because of the syntax it inherited from C.

C got some things right, mostly around ease of porting to different architectures. However, 50 years later we know a lot more about how to design programming languages.

C is not perfect, and even when it was created, better designed programming languages existed. However C was cheap and good enough, and because it was easy to port, it spread to lots of platforms.

FWIW I started my career in C/C++ compilers, I have first hand experience with these topics. I love C as a language, but I also acknowledge it is not perfect. The machines it was designed to run on in the 70s were not the height of Computer Engineering and C is not the height of programming language design.

Millions of flies can’t be wrong.

Or, more politely, a primer on how to confuse first-mover advantage with being any good.

C is abysmal by today’s standards, it being the first popular language for weak computers is literally what’s keeping it popular. Popularity is very valuable but please don’t confuse it with being good.

> Millions of flies can’t be wrong.

You're talking about experts in programming language design. They decided that C's syntax was the best for their needs.

Then the whole software development world adopted these languages, based in no small part due to their readability and user-friendlyness.

If you think the whole world is wrong and you are the only one who is right then sure why not?

If I was the only one, you wouldn't have all the other languages around, a lot of which have nothing in common with C.

C is good enough for some tasks. It doesn't mean it's good. I don't see many of those programming language experts saying that C is good. I see many people who don't think they need anything more than C in their work.

> your unbelievable claim

Please quote the specific claim you think is unbelievable.

(I assume you don't mean the declarations claim because you didn't even disagree with it.)

I'm presuming the poster either never took a compilers course, never had to write a parser, slept through their entire CS curriculum, or doesn't have a background in CS. (Which to be clear, doesn't have to involve a degree! The people who invented Computer Science sure as heck didn't have CS degrees!)

People forget that Computer Scientists has actual foundations built upon objective, scientifically backed, work in multiple disciplines, including mathematics, linguistics, and philosophy.

We use those foundations to build the tools that we then use to engineer software. It is one of the few fields where practitioners are expected to know both the foundational theories underpinning the tools they build, as well as then use those tools to create absurdly complex projects.

Sadly some people skip over the theory part.

I don't think a lot of theory went into most of C's syntax. History is important but it doesn't make designs good.

And if we really want to get into how much C was copied, that's more because of familiarity than correctness. Look how many languages copied C's goofy precedence for bitwise operations, which was only there because they made a syntax change and didn't want to disrupt a few existing programs.

But all this aside, you didn't answer the question at all. What was their unbelievable claim?

> I don't think a lot of theory went into most of C's syntax. History is important but it doesn't make designs good.

Agreed. C is just what sort of worked at the time. 50 years on, we can do better. Theory is what lets us do so in a scientific way, instead of just throwing stuff at the wall and seeing what works.

Although, there is something to be said for testing out new syntax and seeing how it feels in the real world!