Live data from Hacker News

A Boggling Return to C

thraxil.org

21–30 of 88 posts

Re: A Boggling Return to C

#21
post #16

maybe the biggest improvement in c programming over the last decade is valgrind, making purify-like debugging available to everyone. it's completely removed a whole class of annoyingly hard to fix bugs from my code.

Tools only created to solve the lack of safe constructs in C. C made lots of sense in the context it was developed, but the world would be better if we had safer systems programming languages. Valgrind, purify and friends are required to C, the same way Java requires IDEs, to improve language usability. Have said this, the new trend in having static analysis tools integrated in the development process, like Clang, Ec…

In the case of C safer also means weaker and less useful, it is a language where you need to be able to do everything. In some way C is "Assembler-complete". With valgrind you have no compromises, because you have a specialized runtime giving you control over what happens only at debugging time.

Re: A Boggling Return to C

#22

I'm a student who learns C#, Java, Php, javascript... at school. I bought "C: A Refence Manual" to learn this summer... Hope it will make me a better programmer.

If you want to learn C, K&R is the right way to do it.

C: A Reference Manual is excellent and is probably the only other C book you need, but only if you are already a C programmer, and only for what the title implies: reference.

Re: A Boggling Return to C

#23
post #13

Earlier quoted context omitted.

valgrind, is only available for a few platforms/architectures. If you are unable to writer proper C programs without valgrind's help, please go home. :-)

One can always write proper C programs without Valgrind: it is "just" a ( really useful) debugging tool. The utility of it is that instead of spending days trying to track down any mallocs missing frees, one can just run Valgrind to find them and their locations straight away.

I guess what my grandparent said, albeit in a slightly dismissing tone, is that relying on tools like Valgrind or Purify to produce good code makes for weak programmers. The days spent trying to track down missing frees can be reduced to hours with practice, and the programmer skilled in this hunt is less likely to forget the free in the first place. (As opposed to the programmer relying on Valgrind and not caring much when writing the code the first time).

I do not necessarily abide by this point of view, but I do respect the kind of harsh discipline it advocates. Valgrind is definitely useful, really useful, but great C programs (and programmers) existed long before it appeared.

Re: A Boggling Return to C

#24
post #6

I absolutely love writing C. Up until late 2011, it was by far the language I used the most. I am now learning Lisp (not exactly, I'm using Lisp in SICP), and use Python more than before. One thing I realized, is that reading C is more tedious than code in other languages. Sure that's a gross generalization and is not true for every piece of code out there. However, I find I have less troubles picking up a Python pro…

> The code relies heavily on preprocessor macros and some weird gcc-only syntax that made my head hurt.

The preprocessor is generally recognized as one of C's biggest flaws, is not for nothing that Ken Thompson, the first C programmer and the greatest influence on the language other than DMR himself, cut down most of the preprocessor when he wrote his own set of C compilers for Plan 9: http://doc.cat-v.org/plan_9/4th_edition/papers/comp

And of course Go has no preprocessor.

As for your second complaint, one can't blame C for gcc's extensions ;)

You should try Go, many people would consider it C's spiritual successor (or as somebody put it: the language the people who created C would come up if they had 40 years to think about how to polish and improve it), it keeps all the simplicity of C, while being probably the most readable language I have used, it is concise but keeps everything explicit, and figuring what code does is very easy, because code does what it says and says what it does, no dark magic needed.

Re: A Boggling Return to C

#25
"By way of comparison, the Python program takes 1.5 seconds to run, so that's about a 10X speedup."

Only tenfold? Interesting. While Python is surely not the slowest interpreted language around, a result like that borders on the performance of Java. That seems unlikely, especially given the fact that Python version uses worse algorithm.

I would think about how big is the portion of time eaten by I/O - that is, actually reading the `words` file from disk. I wouldn't be surprised if it eats most of the ~100ms that C needs to performs the task, leaving only a tiny percent for actual computation.

Re: A Boggling Return to C

#26
post #4

I started with assembly language and I thought C was heaven. Of course, there are easier languages, there are more powerful languages, there are fancier languages and whatnot. I like Python and I adore Lisp. But I still love C most. C is the sweet spot where I can extend my programs to do high-level stuff while still keep my hands down on the actual hardware I'm programming. I like that a lot, probably because I grew…

My intro course in college was run this way as well and to this day, I'm very glad to have started my career bottom up instead of top down...

Re: A Boggling Return to C

#27

maybe the biggest improvement in c programming over the last decade is valgrind, making purify-like debugging available to everyone. it's completely removed a whole class of annoyingly hard to fix bugs from my code.

valgrind, is only available for a few platforms/architectures. If you are unable to writer proper C programs without valgrind's help, please go home. :-)

you write bug-free code? please, tell me more.

Re: A Boggling Return to C

#29
post #25

"By way of comparison, the Python program takes 1.5 seconds to run, so that's about a 10X speedup." Only tenfold? Interesting. While Python is surely not the slowest interpreted language around, a result like that borders on the performance of Java. That seems unlikely, especially given the fact that Python version uses worse algorithm. I would think about how big is the portion of time eaten by I/O - that is, actual…

Yeah, it was only a tenfold improvement because I was only benchmarking the solving of one board at a time, so a significant amount of time was spent on overhead, reading in the word list from disk, etc. I suspect if I ran multiple passes over larger boards, I'd see a much larger improvement. And the "worse algorithm" that the Python implementation used still wasn't that inefficient.

Ultimately though, this is still why Python gets used so much for real world work. Slow and inefficient as it might be compared to C, on real world problems where performance is dominated by disk seeks and network latency, it's good enough.

Re: A Boggling Return to C

#30
post #24
post #6

I absolutely love writing C. Up until late 2011, it was by far the language I used the most. I am now learning Lisp (not exactly, I'm using Lisp in SICP), and use Python more than before. One thing I realized, is that reading C is more tedious than code in other languages. Sure that's a gross generalization and is not true for every piece of code out there. However, I find I have less troubles picking up a Python pro…

> The code relies heavily on preprocessor macros and some weird gcc-only syntax that made my head hurt. The preprocessor is generally recognized as one of C's biggest flaws, is not for nothing that Ken Thompson, the first C programmer and the greatest influence on the language other than DMR himself, cut down most of the preprocessor when he wrote his own set of C compilers for Plan 9: http://doc.cat-v.org/plan_9/4th…

I second your thoughts about Go. Much like the author of the post, I was really tired of Java and all the bloat that went with doing most things. I was going to get back into C and I had even blown the dust off my K&R. By random coincidence I saw a post about Go on HN and I've been using it ever since. It's a really great language. It does everything I wanted to get back into C for without any of the things I was dreading.
Post reply on HN