News for hackers. Stuff that matters.
Re:The Unreasonable Effectiveness of C by pcwalton on Thursday January 10, 2013 @12:15PM (#5038192)
Binary search trees cannot be implemented in 5 (reasonably-wide) lines of C.
Re:The Unreasonable Effectiveness of C by waffenklang on Thursday January 10, 2013 @12:25PM (#5038282)
And can't be _implemented_ in any language. C gives you at least the charming fact that you can implement one without any overhead of objects, classes, implicit memory management or some other concept, just having a lightweight implementation that you may use in an environment without any libraries, like std or else..
Re:The Unreasonable Effectiveness of C by tyree732 on Thursday January 10, 2013 @02:00PM (#5038971)
So what you're saying is that C lets you write it on your own. In fact, and this might sound crazy, but you can do that exact same thing in C++, it's just that people don't because the C++ standard library provides plenty of performant and featureful data structures for you.

Besides, anything the C++ standard template library map does when implementing a red-black tree is exactly what you would need to do if you wrote your own, minus having things like allocators (which are incredibly useful for those that need them). You speak of overhead due to "objects, classes and implicit memory management". Inevitably, any implementation of a data structure of substance in C ends up looking like c++-ified C. Want to create your hashtable? Call hashtable_init and get back a hashtable_t. Want to insert into it? Pass your hashtable_t, a key and a value into hashtable_insert. Even worse, you either have the choice of making all of your data void* in the data structure and casting into and out of your interface or making awful macros to define the various methods and structures for the types you would like to use. It's like you're stubbornly writing C++ in C.

Re:The Unreasonable Effectiveness of C by deelowe on Thursday January 10, 2013 @02:27PM (#5039151)
I'm confused.

C has libraries too. I personally like the headers used by openbsd: http://www.openbsd.org/cgi-bin/cvsweb/src/sys/sys/tree.h?rev...

Re:The Unreasonable Effectiveness of C by YZF on Thursday January 10, 2013 @10:01PM (#5041114)
I'm not sure why I'm getting sucked into this again :-) but it doesn't have standard, portable libraries. It also doesn't have the right abstractions in the language to provide clean and safe (i.e. no void* and no brittle preprocessor magic) implementations of such.

I've written C for most of my life, you can do great things with it. I also have a love/hate relationship with C++ and Python. There is no perfect language, they all have to make tradeoffs.

Re:The Unreasonable Effectiveness of C by waffenklang on Thursday January 10, 2013 @06:25PM (#5040395)
yes, even standard libs, but they arent that promoted as c++ std libs, as most of them are just apis for system interaction, only a minority are useful out of the box algorithms.

and third party libs are also possible, yes.

Re:The Unreasonable Effectiveness of C by waffenklang on Thursday January 10, 2013 @06:20PM (#5040374)
no its not c++ish, its simply an implementation which is technically similiar to c++, because they are at some core syntax/semantic similar. i didnt said that its the new wheel, or better or worse. its just free of third party stuff, which will be compilable anywhere only dependent of the compiler used. and i didnt exclude that this is exlusive for C, sure this applys to c++ as well. but not if you want to use feature complete c++.
Re:The Unreasonable Effectiveness of C by caf on Thursday January 10, 2013 @09:05PM (#5040969)
You do not need to cast to or from `void *` in C, and it's not idiomatic to do so.