3 ms·
The subject matter is interesting enough. But if it's a discussion on style, why is the code presented so unbelievably bad? Needless duplication of code; simp
by ajross 15y ago
The subject matter is interesting enough. But if it's a discussion on style, why is the code presented so unbelievably bad?
Needless duplication of code; simple one-line declarations (i.e. a struct with three doubles) spread out over 5; empty constructors with trivial initializer lists defined outside the class header; needless empty destructors defined (again, outside the class declaration) for classes without virtual functions; "} else {" spread out across three lines (pet peeve of mine).
The disaster of an Error enumerant deserves a paragraph all by itself. It's got only two values, "OK" and "FAIL". Guess which one evaluates to boolean truth? (And yes, I'm aware of how errno and the like work -- but error codes tend to be something other than "FAIL").
This looks like code generated by an IT employee at a local soap manufacturing company, not something to be seriously considered by people interested in C++ evolution.
- hythloday 15y agoGuess which one evaluates to boolean truth? The one that is an error?
- ajross 15y agoNo. If there is more than one error condition that needs to be handled by the caller, then sure. Enumerate them and provide a "SUCCESS" value. But if you are seriously arguing that "enum { OK, FAIL };" is good code, I weep. edit to avoid stringy flame thread: but it's a discussion on STYLE. If this was an example of how to write an error API, I wouldn't care (I probably wouldn't read it either). But it's a discussion about how C/C++ is written by presumably talented authors, and by inference how other people should write code. And the code sucks, sorry. And I'm horrified at your identification of dead code and needless whitespace as "syntactic fluff" not worthy of consideration as an important part of style.
- hythloday 15y agoTo clarify, I assume you mean that FAIL is the one that enumerates to true, but that you dislike this idiom. "For the purposes of the exercise I’ve deliberately limited the amount of error checking; this isn’t meant to be industrial-strength code (so don’t gripe to me that I haven’t covered all the error cases!)" I think it's pretty clear (at the very least, it's charitably inferrable) that the author is accustomed to errno-flavour error codes. Everything else you gripe about is just syntactic fluff* that makes no difference whatsoever to the analysis, and is dialect-invariant anyway. * Edit: by syntactic fluff I mean that it has both the properties of being easy to mechanically change and that the given mechanical change wouldn't turn bad code into good. One can have strong feelings about the density of white space in code or the proper place of constructor definitions for a class not defined in a header file (I don't, but whatever), but when the solution to it is to run it through a program for a perfect result, I think it becomes not worth discussing.
- ajross 15y agoFor clarity: having a symbol in a program named "FAIL" which evaluates to boolean truth is simply wrong, without room for reasonable disagreement. The errno trick is accepted because of the need to enumerate the "failing" space, it is never used in situations where there is only one kind of failure. And even if there were, it should (again, without argument) be called something specific (e.g. "NO_REAL_ROOT"). As to the latter point about a hypothetical machine I could use: I'd be very surprised if you had a tool which mechanically removes empty destructors, as that changes the semantics of the code (e.g. they can start being POD objects which get different initialization semantics). But in this code they were verifiably needless, which is bad style. Are you in the habit of writing other noop functions "just because?". And I'm amused at your "not worth discussing" point, given that you jumped into a discussion about exactly that. :)
- mseebach 15y ago> This looks like code generated by an IT employee at a local soap manufacturing company Too bad you go and ruin a perfectly reasonable comment with that crap.
- ajross 15y agoWhich moral calculus allows you to call someone else's work "crap", where I can't cast aspersions on the quality of technology adoption in the soap manufacturing industry?
- mseebach 15y agoI didn't know the phrase "cast aspersions", so I went to look it up. It means "to slander". I'm sorry I slandered your slander.
- ajross 15y agoTo be clear: I was just pointing out the hypocrisy in pulling out my (admittedly) mildly ad hominem slur comparing the OP author with an IT robot and calling it "crap". You can't reasonably demand civil discourse if you aren't willing to practice it. But to be honest: I don't think my quip was really that bad. Did I hit too close to home? Do you do soap automation?
- Danieru 15y agoMseebach was insulting your words, based on their content. You were insulting people, based on their jobs. And now you're attacking mseebach. In truth you don't sound very repentant.
- ajross 15y agoSo my crime is the use of a mild (and very common) ad hominem in a context where I would expect most people would see the humor, not being uncivil? And it's OK to call things "crap" just so long as I don't make an ad hominem argument in doing so? Sorry, your argument is steaming crap. The idea that one can't invoke the pervasive metaphor of bad IT-generated code (or, I guess, imply that the local soap industry might do it) but that it's OK to flame away at the author who does is just dumb. And for the record: I don't believe I expressed any repentence. :)