9 ms·
> Want to make tiny binaries for some obscure system with virtually no storage or RAM? C++, D, Rust, ... > Want to trivially import any of the huge array of e
by atilaneves 10y ago
> Want to make tiny binaries for some obscure system with virtually no storage or RAM?
C++, D, Rust, ...
> Want to trivially import any of the huge array of existing libraries? You guessed it...
If C can talk to it, so can anything else. Granted, having the preprocessor means no bindings, but C++ has that too.
> Want to do something you really shouldn't, and any 'sensible' language might attempt to stop, but is called for right here and now...
C++, D.
Want undefined behaviour? C.
Want segfaults? C.
Want memory leaks? C.
Want memory corruption? C.
Want to write insecure code? C.
Want to write your own containers? C.
Want Go's approach to generics? C.
Want to spend 3x as much time writing code as a comparable C++ solution (not to mention more productive languages)? C.
I've known C for 21 years now. I just quit a job as a C programmer for embedded systems. If I can help it, never again.
- S_I 10y ago>Want undefined behaviour? C. Want segfaults? C. Want memory leaks? C. Want memory corruption? C. Want to write insecure code? C. Want all of that and a whole bag of inconsistent design choices? C++. Because, yes, one day you will meet a C++ codebase which is a mixture of "forbidden C++" and "modern C++".
- existencebox 10y agoFor the last decade or so writing physics engines has been a hobby project of mine; I shamefully read your comment and realized that absolutely describes my current toy. It's been in various stages of dev since c++11 was newfangled, and combined with being the "learning experience" of a programmer moving over from C; let's just say it shows... (mentally revising my plans to ever apply to C++ jobs and not just go hide in a forest)
- Nursie 10y agoWriting C++ is three times as fast? Perhaps so, but reading it back takes 5 times as long.
- ArkyBeagle 10y agoNo, not for similarly skilled writers. And C++ pushes certain pathologies into much more opaque, dark corners.
- StavrosK 10y ago> Want to spend 3x as much time writing code as a comparable C++ solution Coming from Python and dabbling in C for embedded software, this is the one that gets me the most. It's so frustrating to be spending hours doing something you can do with one line of the regex library in Python...
- bkjsbkjdnf 10y agoThere are regex libraries for C. Worst argument so far.
- majewsky 10y agoI would upvote this if it weren't for the second sentence.
- ixtli 10y agoI think it's a bad thing that hacker news is so allergic to strong editorialization.
- lemmings19 10y agoI do not. There is enough of it elsewhere on the web, it's nice to be somewhere relatively free of it for a change. The conversations that occur here generally seem much more structured.
- ixtli 10y agoI agree that they are more structured, but I don't see any evidence that this is in any way due to how immediately people are attacked for wording things strongly. Engineering is a life and death business more often than people think; it deserves people who feel strongly about it. As an aside, I think the rules about trolling and personal attacks are pretty clear and easy to enforce. What I'm specifically concerned about is that those rules are evoked outside of the spirit in which they were created to attack emphasis in general. In fact, most of the discussion here is in clear violation of "Please avoid introducing classic flamewar topics unless you have something genuinely new to say about them." but obviously we rightly care a lot about this topic and, since people are acting like adults, no one needs to tap on the poster so to speak.
- bkjsbkjdnf 10y agoIf you spend 3x the time writing equivalent code in C as you do in C++ you're either a bad C programmer, a bad C++ programmer, or likely, both.
- CyberDildonics 10y agoConcatenate two strings with resource management in C then C++ and see which is easier.
- ArkyBeagle 10y agoThis is a relatively trivial thing in either - depending on how you define "with resource management." I understand completely that people want to translate patterns directly across languages, but since "string manipulation with resource management" as a delta-detail going from 'C' to say, Python was a design goal, it's somewhat specious.
- atilaneves 10y agoIt's not trivial in C, it's a pain is what it is. I'd put it another way: if someone can't write C++ 3x faster than C they're not a very good C++ programmer. Maybe they're writing C with classes.
- ArkyBeagle 10y agoYou just won't get agreement from me here - string manipulation in 'C' is quite easy. Concatenation operators and the like mostly get in the way. This has nothing to do with design approaches. The str() suite from the standard library is very easy to use safely, if you're careful in your constraints. You do have to think "this is a buffer" and behave accordingly. The resulting code is pretty tedious, but there's no way it takes 3x as long. Throw in the level of control with sprintf() and there's a pretty clear win. What is easier with C++ ( and most scripting languages ) are things like combinators and regexp.
- 10y ago
- tscs37 10y agoDon't drag go into this.
- microcolonel 10y agoD? You sure you can get a compiler for that on an "obscure platform"? Do the libraries you want to use work when the GC is off?
- atilaneves 10y agoYou can use D on platforms LLVM amd gcc support. Some libraries work, some don't. Stick @nogc on main and you're guaranteed to not use the GC. Besides, on constrained systems you're not going to be wanting many dependencies.
- themihai 10y agoYou forgot to respond to the first one: "Want minimal syntactic sugar and a language that's not prone to feature-of-the-week hipsterism"
- oldmanjay 10y agoThat's a lot of words to declare oneself a masochist Or if being verbose is desired, do you want to do a job for a computer that you are not suited to do but the computer is?
- coldtea 10y agoWhy in God's name would I want minimal syntactic sugar? I want optimal syntactic sugar.
- themihai 10y ago> I want optimal syntatic sugar Like Rust or C++ templates? I prefer C syntax over the "optimal" alternative.
- coldtea 10y agoWhy in god's name would Rust or C++ templates be the optimal amount (or optimal syntactic sugar design)?
- themihai 10y agoWell, that's my point! There is no alternative with "optimal syntactic sugar design". You have to choose between something 'minimalistic' (C) and something less minimalistic (i.e. Rust).
- EpicEng 10y agoEveryone has a different idea of what 'optimal' means here.
- atilaneves 10y ago
- chias 10y agoI love Rust with a passion, but in all fairness it does not make tiny binaries. On my system, hello world in C is 6.5k, hello world in Rust is 805k (124 times bigger). After running 'strip' on the binaries it's a little better: 4.3k vs 345k, which is better but is still 80 times bigger. (I know there are some "tricks" you can use to make smaller Rust binaries by chopping things out, but of course the same applies to C. For example, I can take the C binary and just truncate the file down to 2230 bytes without breaking it)
- steveklabnik 10y agoYou're not comparing apples and oranges there. For more: https://lifthrasiir.github.io/rustlog/why-is-a-rust-executable-large.html https://lifthrasiir.github.io/rustlog/why-is-a-rust-executab...
- dbaupp 10y agoA direct comparison like that is somewhat comparing apples to oranges. Don't get me wrong, defaults matter, but Rust still does offer the control required to get small binaries, and, those defaults are not nearly as bad for low-level domains where one isn't using the standard library, which is where binary size is most critical. See also https://lifthrasiir.github.io/rustlog/why-is-a-rust-executable-large.html https://lifthrasiir.github.io/rustlog/why-is-a-rust-executab... and even http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-static-linux-binary-in-rust.html http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-... .
- Gankro 10y agoHello world is large primarily because it statically links in jemalloc and libunwind, which are obviously fixed overhead. Both can be removed (and indeed I would expect jemalloc to be turned off by default sometime soon because each jemalloc release seems to be less stable than the last). If you do this you'll get a much healthier binary size. C binaries are small because they're assuming you've installed what is ultimately the C runtime on your system (libc).
- Manishearth 10y agoThose aren't tricks. Rust does not choose the same defaults as C, and, among other things, statically links to the stdlib and jemalloc. The tricks you describe are just changing the compile options to those that C uses by default. on top of that you can apply the same tricks as C; e.g. by running strip, truncating the binary, writing a linker script, etc.
- snakeanus 10y ago> Want undefined behaviour? C Can be solved by not doing stuff that are considered as undefined. Think of them as the standard's say of saying "don't do that". It's quite easy to do in most cases. > Want segfaults? C > Want memory corruption? C > Want to write insecure code? C There is absolutely nothing in C that makes it more prone to these in comparison to other languages. Moreover you can easily solve these by using an implementation that protects you. (such as one of the multiple C compilers that guarantee to produce safe code without UB or the sanitisers in gcc and clang) > Want memory leaks? C Can be easily avoided by avoiding dynamic memory allocation. Moreover nothing stops an implementation from using a GC. > Want to write your own containers? C This applies to all the languages as none of them happen to have an implementation of every container in their standard library. It is true that C lacks that in comparison to some other languages, however implementing the common ones (or using a library) is an extremely trivial thing to do. > Want to spend 3x as much time writing code as a comparable C++ solution (not to mention more productive languages)? C You must be quite the shitty C programmer to need 3 times less time to write something in C++.
- atilaneves 10y ago> Think of them as the standard's say of saying "don't do that" I have a list of "don't do that" rules. I still do them, usually by accident. > There is absolutely nothing in C that makes it more prone to these in comparison to other languages If you believe that, then there's nothing I can say that will change your mind. > Moreover nothing stops an implementation from using a GC Many applications can't use a GC. For tiny systems, forget it. > none of them happen to have an implementation of every container in their standard library That completely sidesteps the fact that in pretty much every other language the containers one would like to use 99% of the time are implemented in the standard library or the language itself. > You must be quite the shitty C programmer to need 3 times less time to write something in C++. Only a shitty C++ programmer _doesn't_ write code 3 times as fast as they'd write C.