• (nodebb)

    int a = 123; int b = a + 1234; int c = b - 1234;

    // hooray, we did it! c is now equal to a!!

  • (nodebb)

    And Python actually has an Enum class.

  • SteeVeeTee (unregistered) in reply to dkf

    Which is stated in the article.

  • (nodebb)

    That's called "I learned this but don't know how to use it" and is not a WTF. TRWTF is never going back to learn how to use it.

  • charles (unregistered)

    Or possibly some poor guy started down the Correct Path of using an enum//define, but both misunderstood how it should work and never got back to it.

  • (nodebb) in reply to SteeVeeTee

    The Enum class has been there for quite a few years. It was even backported to 2.7 (I used to have code that used it.)

    More horrible was the IntEnum for people who insist on making their enumeration values support arithmetic operations.

  • matt (unregistered)

    Please for the love of cthulhu will you stop using WHICH as a conjunction? It boggles the mind that a website devoted to encouraging better code through pointing out tiny deviations from sensible and readable style can't get its own English better written.

  • Charles (unregistered)

    Depending on what's in the rest of the code, it may be useful. After the assignment, 'operation' is guaranteed to have one of the valid values. This means later uses can safely use it to construct strings which otherwise would be vulnerable to injection attacks.

  • Barry Margolin (github) in reply to matt

    Are you talking about the sentences that begin with "Which"? What's wrong with that?

    However, I think "Strings which have" should probably be "Strings that have".

  • matt (unregistered) in reply to Barry Margolin

    "This Python class essentially emulates an enumeration, which while enumerations are now available in Python, it's perfectly plausible that this code predates it and it's fine." That one is acting as a conjunction; "and" would make more sense, perhaps "but", depending on the intended tone. "Which" makes no sense in that sentence. An enumeration, which IS... what? which DOES... what? which something else acts upon in some way? Even "which is now an available feature of Python" makes sense. Here it's just a train of thought that runs out of track.

  • (nodebb)

    Meanwhile me, wishing that Fortran had a proper typesafe enum concept.

    Though it can be emulated easily with a user-defined type with one value, named integers abound :( Heck, just using string constants would be better, but somehow Fortran programmers seem to think that string comparisons are expensive. Sure

    i_type == TYPE_A
    

    Is faster than

    c_type == TYPE_A
    

    but unlikely to actually make a difference...

  • nz (unregistered)
    Comment held for moderation.
  • whitewalter (unregistered) in reply to Charles

    Look best college essay writing service www.essayshark.com here in link. This service provide best help in writing essay in the USA.

  • (nodebb) in reply to R3D3

    If they are Fortran programmers, they would think that

          IF i_type .EQ. TYPE_A
    

    Is faster than

          IF c_type .EQ. TYPE_A
    

    and they would be right unless c_type and TYPE_A are small enough to fit into a single INTEGER value.

  • (nodebb) in reply to Steve_The_Cynic

    As I said -- it is faster. It just doesn't actually make a difference. These type comparisons are very rarely an "inner loop" situation. And even then you could easily emulate type-safe enums with something like

    TYPE :: element_type_t
        INTEGER :: id
        CHARACTER(13) :: name
    END TYPE
    
    TYPE(element_type_t), PARAMETER :: &
        et_connection = element_type_t(1, "et_connection"), &
        et_rigid = element_type_t(2, "et_rigid"), &
        et_flexible = element_type_t(3, "et_flexible"), &
        et_all(3) = [et_connection, et_rigid, et_flexible]
    

    and get barely a performance penalty for doing

    et_type%id == et_connection%id
    

    For most cases though, using some CHARACTER(LEN=8) will not make a relevant performance difference to using an integer, be more useful when debugging, and help to catch at least some bugs (e.g. passing arguments in the wrong order).

    Addendum 2023-02-28 04:30: I missed the change for making an et_al "typo".

  • Ricky Rosello (unregistered)

    Caiganle encima a esa puta.

  • (nodebb) in reply to Ricky Rosello

    Judging by google translate, that comment should probably be removed.

  • Your Name (unregistered) in reply to matt
    Comment held for moderation.
  • Your Name (unregistered) in reply to matt
    Comment held for moderation.
  • Your Name (unregistered) in reply to Barry Margolin
    Comment held for moderation.
  • Virgilreurl (unregistered)

    A pagina de login do 1win Casino (https://1win-slots.com/pt/1win-cassino-login/) e a porta de entrada para uma experiencia de jogo emocionante e repleta de diversao. Ao acessar a pagina de login, os jogadores podem criar uma conta e ter acesso a uma ampla variedade de jogos de cassino, incluindo slots, jogos de mesa e muito mais.

  • ghonshonmargo (unregistered)

    Hi) Maybe you are still in university and you have an essay assignment) And if you want to get help with writing texts, then I offer you this essay writing service! It's the guys from https://www.wiseessays.com, they have never let me down yet)

  • cambridgejessy (unregistered)
    Comment held for moderation.
  • cambridgejessy (unregistered) in reply to whitewalter
    Comment held for moderation.
  • MarkHubbard (unregistered)
    Comment held for moderation.

Leave a comment on “Magic Strings Attached”

Log In or post as a guest

Replying to comment #:

« Return to Article