Hacker News new | ask | show | jobs
by norir 842 days ago
C is horrible for exploratory programming but is acceptable if you already know how to solve the problem. If one uses enums for errors, then the compiler can check for you that all edge cases are handled. You can log an error and exit(1) for unhandled cases during development which makes it feasible to turn on -Werror but not have to implement every edge case up front.

You can do the same thing with tagged unions to implement a poor man's sum types. It is significantly more verbose than in a language that has syntactic support for this, but you get similar compile time safety guarantees.

3 comments

> C is horrible for exploratory programming...

Completely opposite experience here. C is great for explorative coding because it's just structs and functions.

There's no agonizing about whether some piece of code should go here or better there, wrapped in this or that concept or high level abstraction.

Instead you start with an empty screen and incrementally build your ideas from small building blocks, much like in Lisp or Forth.

What is stopping you from only using functions and structures in any language?
Java or C# required me to wrap every piece of code into class boilerplate (I think that has changed in the meantime, but just as an example).

In C++, Visual Studio will bombard you with all sorts of silly C++ Core Guideline advice if you try to write simple and straightforward code.

Finally, the standard libraries and 3rd party libraries might also get in the way if 'simple and straightforward' clashes with the idiomatic style of the language.

Probably even better to pick PHP then, large standard library included, open foo.php to code, no main function required, just start writing, no build step, can output to stdout or http without effort
Sure, but it depends on the task. For instance if I need to talk to operating system APIs directly then C (or ObjC on Mac) might still be the better choice. Best tool for the job etc... I guess the gist is that languages that are built around the idea of high level abstractions and enforcing a specific coding style on large teams might not be the best language for exploring and prototyping.
C# has been focusing on terseness for years now but is kept getting bundled together with Java :(
I'm somewhat aware of the improvements, but at the same time I haven't seen much of that terseness in the real-world C# code I'm dealing with (typically Unity gameplay scripting code).
Unity is stuck on an ancient language version unfortunately and has seen none of the runtime improvements of vanilla .NET due to using custom mono fork and build process. Hopefully this will change with the release of Unity 6. With that said, even old C# can be written in a compact way. Most suffering is completely self-imposed and can even be observed proliferate in languages like Rust with such developers starting to adopt them.
There are other languages than C, Java, C# and C++.
> C is horrible for exploratory programming

Completely disagree. The lack of screwing around selecting abstractions forces you to make something productive right away and not stress about refactor.

Isn't "forced to make sth productive right away" the opposite of "exploratory programming"?
No, I think exploratory programming is exactly that. Solutions to a problem is the very thing to be explored.
Who is stressing you to refactor when doing exploratory programming? Yourself? OOP languages? Society?
If you're talking about something like a web server, then sure. If you're talking about kernel hacking, then I completely disagree.