• 516052 (unregistered)

    It's been a while since I worked with C but I could swear it had a way FOR doing loops.

  • Prime Mover (unregistered)

    Writing in c is a WTF all of its own. For this sort of thing you should use Fortran instead. You know it makes sense.

  • Rocky (unregistered) in reply to 516052

    Why loops? Just use printf/fprintf, it has no problems printing padded fixed width fields with arbitrary sizes determined at runtime.

  • Hanzito (unregistered)

    I'm so glad that minimum values are separated from max and (well, eh, equal?) values. Imagine the possibilities!

  • Pag (unregistered)

    Remember NINE_11

  • I dunno LOL ¯\(°_o)/¯ (unregistered)

    I was expecting a huge switch() block, but it seems these must have been inserted inline in the code. I still doubt that they had the C chops to know that they could do something like: printf("%s", "|" SPACE_57 "|");

  • (nodebb)

    Ahh, what beauty! Sheer poetry!

  • gguueesstt (unregistered)

    wearing their tab key out

    Joke's on you, this file was generated by a simple COBOL script!

  • (nodebb)

    For me, the WTF starts(1) with the name of the file. FFS, guys, constants.h ????

    (1) It might as well end there, frankly. The contents of such a file are neither here nor there compared to having an amorphous mass of "constants".

  • 516052 (unregistered) in reply to Rocky

    You are correct.

    With the caveat that your solution is a tad too advanced for this situation in that it requires basic knowledge of the basic points of the C language. And it is clear that the creator of that code needs to first master basic knowledge of the basics of programming as a whole. So whilst for you and I it solves the problem I would not be confident he would get it.


  • (nodebb)

    It has been a while.. But doesn't C do "\0" termination? And wouldn't that make ZERO_10 actually 12 wide?

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered)

    Clearly they skipped LABEL_SIZE13 because 13 is an unlucky number. (And maybe they thought all the rest of the skipped numbers are unlucky too.)

  • Sole Purpose Of Visit (unregistered) in reply to Steve_The_Cynic

    Actually, in C, I vastly prefer to have a single header file containing all the "application constants."

    It's just .... none of the ones in this file are actual "application constants."

  • King (unregistered)

    Here is how they use the file: There is a need for one of the strings in constants.h somewhere in their codebase. They open up that file and ctl-f to the line that has the needed string, then they copy the string and paste it where string is needed. They have thoroughly debugged constants.h so they are sure the strings are correct. This is how copy paste should be used!

  • Sole Purpose Of Visit (unregistered) in reply to Dlareg

    Depends what you mean by "wide" in C. Also depends upon whether you are dealing with 8-bit char termination or 16-bit char termination (WCHARs in MS-C use the latter). Also depends upon the usage of that "wide-ness." And I fully expect the usage of anything in this header file to be maximally borked and inconsistent.

    It's a splendid example of a useless header, though. As per above, this is best done by (s/f)printf. Wrap a small function around that, parameterising the layout requirements and thus creating the format string, and you're done for every single format you could ever need ... well, excepting I18N, I suppose. You'd have to have a separate outside wrapper for that.

    C and C++ (both of which I love, under the right circumstances) are and always have been used by people who think that they are smarter than the average bear/cobol programmer. It often turns out that they are far more dangerous than the average cobol programmer, though I suppose slightly less dangerous than the average bear.

  • Mark (unregistered) in reply to Dlareg

    "\0" is not 2 characters. It is a non-printable character so it is represented by 2 characters for programmers. In most languages the \ character is an escape character in code so we can put in characters that can't be directly put in for various reasons (\t is a tab, \n is newline, \r is carriage return, " is how you represent a quote inside a string). It would actually be 11 characters wide.

  • matt (unregistered)

    And when will TDWTF writers realize "which" is not a conjunction?

  • I know this person.. (unregistered)

    I believe I know the person who created this.

    The reason that you have "LABEL_SIZE10", instead of "10", is because: what if you want to change the size from 10? Then you need to change it in every place that "10" occurs, rather than changing "LABEL_SIZE10" in just one place. Imagine the much more ease, accuracy, and lack of errors if you just do "#define LABEL_SIZE10 14"!

    ... what a moron. Someone like this made my life hell for a year before I said get me the hell out of this group or I quit. Now he's doing doing it to someone else in my former position, and that someone else is about to quit. Surprise.

  • Edd (unregistered)

    Fixed width is something awk is very good at

  • Brian Boorman (unregistered)

    I laugh. People suggesting printf and for loops. That all takes extra CPU cycles. If you have memory to spare, using the #defines results a single "load register with address" instruction to put the necessary string data in the place where it's needed. Much more cycle-efficient than building strings at runtime with a loop.

    There's probably a better way to make each one on the fly than typing them all out - some preprocessor language trickery that I won't bother trying to work out here.

  • Barf4Eva (unregistered)

    It's ART!

  • Barf4Eva (unregistered)

    Seriously, this is art. Slap an NFT on it and roll in the millions!

  • Sole Purpose Of Visit (unregistered) in reply to matt

    I'd argue that it is a conjunctive noun, which is how it is used here (and here).

    The conjunction "and" can be used to convert the above to "It is a [noun], and it is how it is used here." The repeat of the noun "it" via the conjunction "and" makes it reasonably plain that there is a conjunction going on, which/and is the same conjunction that is evident in the first formulation. You may wish to be a gas bag and use something like the second form, or you may just decide that it's not worth a toss and simpler is better.

    Your choice, really. You can also complain about things that don't matter a toss until you bring them up, and even then they don't matter.

  • matt (unregistered) in reply to Sole Purpose Of Visit

    How you use it in your first sentence is not the sort of usage I object to. Look at this more closely: "Today's submitter goes by "[object Object]", which I appreciate the JavaScript gag even when they send us C code." From "I appreciate" to the end is a complete clause on its own, something you find after a conjunction, whereas "is how it is used here" does not have a subject until the relative pronoun "which" is employed. Conversely, the relative pronoun needs to find and occupy a space in its subordinate clause, and in that quotation, it can't.

    Here are some grammatically correct versions: "Today's submitter goes by "[object Object]", and I appreciate the JavaScript gag even when they send us C code." (Now that's a conjunction, and depending on the sentence, others such as but or though can be used to highlight contrast.) "Today's submitter goes by "[object Object]"—I appreciate the JavaScript gag even when they send us C code." "Today's submitter goes by "[object Object]", which I appreciate as a JavaScript gag even when they send us C code." "Today's submitter goes by "[object Object]", a JavaScript gag which I appreciate even when they send us C code." (This one doesn't even need the "which" in standard English.) Do you see the difference?

    I think we see this because people only think a few words in either direction when putting a sentence together, especially in speech (where the natural "which" is found too late not to resolve well and is abandoned in aposiopesis), and the overall structure often gets lost or twisted. It's one reason we wind up with redundant prepositions ("for which we're looking for", for example), and would you defend them? Do you get really defensive about dangling participles? On the other hand, people reading or listening to a sentence use grammatical structures and transitional words to make sense as a sentence gets completed, and sloppiness like this leads to confusion, misunderstanding, or at least stumbling, as from expecting one more (or fewer) stair in a staircase.

  • DrFloyd5 (unregistered) in reply to I know this person..

    You could find and replace label_size10 to label_size14.

  • löchleindeluxe (unregistered)

    So that's somebody who didn't get the "Find a minimal set of numbers so that every number in 1..n is the sum of at most three numbers" question in their interview… (Remind me, does C just merge adjacent string literals?)

  • Nico (unregistered) in reply to gguueesstt

    Defintely. We all know that this is the result of a refactor from something even worse.

  • D J Hemming (unregistered) in reply to löchleindeluxe

    What three numbers is 1 the sum of?

  • ZZartin (unregistered)

    I don't hate this for building fixed width files. Without seeing how they're using it I'm guessing they're using it to fill in default fields and it's easier to read SPACE_23 + real value + SPACE_19.

  • (nodebb) in reply to löchleindeluxe

    does C just merge adjacent string literals?


  • negativ (unregistered) in reply to D J Hemming

    2 , 3 and -4.

  • (nodebb)

    .comment has a weird white top border that causes #define NINE_29 to look like it's struck out with a white line

  • (nodebb)

    Honestly, fixed width isn't relegated to legacy software. A program requiring fixed width as input? That yes, no program should fail of the input contains an extra space.

    For formatting output files to be human readable, particularly when the output takes the form of tabular data, it is quite useful.

    ... and usually realized with f-strings or .format(), since it usually is enough to have a reasonable guess for the width and doesn't matter if a few cells end up exceeding their width. After all calculating column widths from the data requires calculating the whole table before starting output.

    ... unless you're processing encoding-agnostic data streams since python has no fb"" literals. I forget if there is a bytes.format, probably not.

    Addendum 2021-09-11 03:52: Checked the docs. bytes has the % operator for formatting, python2-style, but no .format method and no f-string equivalent.

  • Alan (unregistered)
    Comment held for moderation.
  • DsK Astrology (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to D J Hemming

    What three numbers is 1 the sum of?

    It says at most three numbers. So any set including 1 will do for that.

  • Clubs21ids (unregistered)
    Comment held for moderation.

Leave a comment on “Columns of a Constant Length”

Log In or post as a guest

Replying to comment #:

« Return to Article