4 ms·
Ugly and unportable code. I can't see practically any benefit. #ifdef __GNUC__ value = c->kind == Volvo ? ({
by vardump 10y ago
Ugly and unportable code. I can't see practically any benefit.
#ifdef __GNUC__
value = c->kind == Volvo ? ({
struct Volvo* it = &c->Volvo;
itoa(it->x, temp, 10);
})
: c->kind == Ferrari ? (void)c->Ferrari.model, c->Ferrari.brand
: c->kind == Fiat ? c->Fiat.model
: union_fail("Not a valid car type");
testCar(c, value);
#endif // __GNUC__
}
- bluetomcat 10y agoAgreed, "functional" code in C is when you write pure functions with no side effects and nest them like `f(g(h(x)))`. Everything else is an abomination.
- theprotocol 10y agoI love this style. I accidentally "discovered" that pure functions were good through trial and error in my younger days, before I'd looked into functional programming. However, while I'm not necessarily a gigantic fan of functional languages, I think functional principles should be taught to everyone.
- noobermin 10y agoMacros can clean this up a little. Still, all C is ugly.
- bluetomcat 10y agoC can be beautiful if you use it in the way it was intended. Code that mimics OO or functional patterns from other languages is certainly not.
- jonathankoren 10y agoOh god, flashbacks to Gtk+, and it's "objected oriented C". C is the easiest to bind to, and anyway, C++ is just syntactic sugar! Now, let's define class by creating a struct that will hold your vtable and static properties, and another that will hold your instance data... Such bullshit.
- spriggan3 10y agoGtk+ is nice as long as you don't have to define your own classes with GObject . But in that case, there is Vala which compiles to C which makes more sense. To bad this project doesn't get more traction, it's actually well designed and the generated C code is quite readable. I personally prefer Vala to D from a design perspective.
- jonathankoren 10y agoI actually liked Gtk+ when I used it. It's layout managers were easy to use (if Java AWT like), and I rather liked playing with Glade and being able to use scripting languages to build apps. Alas, the greater GNOME attitudes that began to copy the worst aspects of Windows after the fateful (and correct) Sun Microsystems of user experience study in the late 90s of GNOME 1.x [0], which came back with "You literally have five different clocks, including one named 'Another Clock' [1], are asking people to identify video cards by chipset, and have odd settings that are explained solely by acronyms. Get your house in order." to then mean "No options at all!", and the bad copying of the worst ideas of windows to the bad copies of the worst ideas of Apple (e.g. undiscoverable keypresses and file choosers without directory path inputs) turned me off to the whole mess. [0] https://web.archive.org/web/20010725052737/http://developer.gnome.org/projects/gup/ut1_report/summary_recs.html https://web.archive.org/web/20010725052737/http://developer.... [1] http://www.linuxselfhelp.com/gnome/users-guide/clock-applets.html http://www.linuxselfhelp.com/gnome/users-guide/clock-applets...
- arethuza 10y agoWas Gtk+ a descendant of things like Xt Intrinsics? I seem to remember having to work with "object oriented C" in the mid '90s and not liking it at all.
- zump 10y agoC pet peeve: typedef structures for_incredibly_esoteric_type_t.
- bluetomcat 10y agoI too hate typedef except for integer/FP types where the new name would carry semantics, like, for example, `pid_t` or `time_t`. `point_t` instead of `struct point`, `color_t` instead of `enum color` or worse, `pint` instead of `int *` is stinky because it hides the actual operations which are only applicable to a struct, an enum, or a pointer, respectively.
- astrange 10y agoI've noticed a lot of people like to end their types in _t, maybe because it looks cool, but POSIX actually says all those names are reserved for the system. Oh well. http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2...
- noobermin 10y agoThe way it was intended? You mean by K&R? Seems like you are making a subjective judgement because I hardly doubt the majority of C hackers use C "as it was intended" in 1973. I'll postfix this by saying I actually don't consider the code snippet as ugly but that's because I like C. Most people consider C ugly because they use stuff like Python or C++ which hides some details. Macros can hide details too, they are just difficult to use. Therefore, for most people C will always be "ugly", but then again, beauty is in the eye of the beholder.