• Pedro (unregistered)

    No WTF in this code. Nothing to see here, move along. Also, !FRIST // not-ing FIRST is pure speculation

  • Steve_The_Cynic (nodebb)

    The obvious WTF is a function that returns true/false for fuccess or sailure. (I put it like that because there's no way to tell which way round a particular function is, since people use both true-success and false-success in the same codebase. In general, though, people who do that should be shot.)

    There's a case for false=success, because that way you can easily change to a numeric code and keep "!f(params)" meaning "f succeeded.

    There's also a case for using an enum all of whose members are NOT zero, including success, precisely to discourage that.

    Or you use an object that asserts if it is not checked. And then people will write code like this: f(params).succeeded();. This is the voice of experience speaking. We had a framework that included such a status class, and one guy on the team would write that just to stop the code from exploding.

    There's NO easy solution to this. The solution that is the least likely to be disastrous is to pass the return status as an "out" parameter rather than returning it, although that tends to annoy people who call the interface because they can't be lazy about things.

  • Pedro (unregistered) in reply to Steve_The_Cynic

    Just stick to the same convention throughout your code. Returning 0 (int) for success is a C convention, where you return an int to specify 1 of many possible outcomes (error code). Many other languages prefer the Bool convention, where you return True for success, and possibly throw an Exception on fatal errors, or return false on mild errors.

  • Quite (unregistered) in reply to Pedro

    My current workload concerns a backend which returns a status report where the convention is precisely the opposite: 1 for success, and 0 for failure -- along with a complex data structure containing all there is to know of any importance about the nature of the failure.

    Fortunately it is rigorously consistent, so just as soon as I found someone who could explain what all that data structure meant, and how it should be treated at the front end for each category of error, coding up the error page became a straightforward task that could be considered done and dusted.

    The moral of the story, ladies and gentlemen, is that the guy who originally stated something like "A foolish consistency is the hobgoblin of little minds" was no software engineer. Quick google: Emerson. That explains it.

    "Good, he did not have enough imagination to become a mathematician". -- Hilbert

  • Paul (unregistered)

    I think the original coder was trying to check if all of those returned true, and return that result. Of course using &= would have been a better solution...

  • jkshapiro (nodebb) in reply to Quite

    To be fair to Mr. Emerson, he did specify a "foolish" consistency. Much of the time, consistency is anything but foolish.

  • EvilSnack (unregistered)

    I beg to differ. The purpose of code comments is to minimize the cost of code maintenance, and it does this by declaring what the code is supposed to be doing. That way, when the code has to be changed by someone who is seeing it for the first time, they can find the code block that is supposed to be doing X, either so that they can code it to do Y, or fix it so that it really is doing X.

  • Bananafish (nodebb)

    It's only redundant placing the same comment after each statement. There should be only one instance of the comment - perhaps after NotResult is defined. The rest of the code is rather clear, and the existence of the comment after each statement is a real PITA when that stuff word-wraps.

    I do not agree with Paul's statement regarding &= rather than |=. If the code utilized &= there would be a failure only if all of the updates fail. Using |= will flag a failure if any of the updates fail, which is more likely to be a case to flag a failure.

    TRWTF: If only one of those template updates fails, we have !Success. Great, we know it didn't work. However, we don't know which update failed, and so we have no way to roll anything back. True, we can't see what happens when this returns, but I doubt there is any type of cleanup if the coder has no way to signal where the actual failure occurred.

  • Jeff Dege (unregistered)

    I think my favorite rule-of-thumb in this area is:

    "If the code doesn't match the comments, they're both probably wrong"

  • Necropaw (unregistered) in reply to Bananafish

    @Bananafish: Paul is right. Using the De Morgan's laws the whole code can be simplified. Instead of "return !(!A | !B | !C) " it can be transformed into "return A & B & C"

  • Brad Wood (google)

    As Homer would say, "I'm not not licking toads."

  • Carl Witthoft (google)

    Or the other old saying: "Two wrongs don't make a right, but three lefts do."

  • Dave (unregistered)

    As others have said, surely something like this could be done instead? :

    static BOOLEAN UpdateFileStoreTemplates () { BOOLEAN Result = TRUE;

    /* attempt all updates and return FALSE if any were unsuccessful */ Result &= UpdateFileStoreTemplate (DC_EMAIL_TEMPLATE); Result &= UpdateFileStoreTemplate (DC_TABLE_HEADER_TEMPLATE); Result &= UpdateFileStoreTemplate (DC_TABLE_ROW_TEMPLATE); Result &= UpdateFileStoreTemplate (DC_TABLE_FOOTER_TEMPLATE); Result &= UpdateFileStoreTemplate (WS_EMAIL_TEMPLATE); Result &= UpdateFileStoreTemplate (WS_TABLE_HEADER_TEMPLATE); Result &= UpdateFileStoreTemplate (WS_TABLE_ROW_TEMPLATE); Result &= UpdateFileStoreTemplate (WS_TABLE_FOOTER_TEMPLATE);

    return Result; }

  • Dave (unregistered)

    Sorry, didnt know the formatting would do that... in future, should it be surrounded by bla or somethine like that?

  • Dave (unregistered)

    As others have said, surely something like this could be done instead? : static BOOLEAN UpdateFileStoreTemplates () { BOOLEAN Result = TRUE;

    /* attempt all updates and return FALSE if any were unsuccessful */ Result &= UpdateFileStoreTemplate (DC_EMAIL_TEMPLATE); Result &= UpdateFileStoreTemplate (DC_TABLE_HEADER_TEMPLATE); Result &= UpdateFileStoreTemplate (DC_TABLE_ROW_TEMPLATE); Result &= UpdateFileStoreTemplate (DC_TABLE_FOOTER_TEMPLATE); Result &= UpdateFileStoreTemplate (WS_EMAIL_TEMPLATE); Result &= UpdateFileStoreTemplate (WS_TABLE_HEADER_TEMPLATE); Result &= UpdateFileStoreTemplate (WS_TABLE_ROW_TEMPLATE); Result &= UpdateFileStoreTemplate (WS_TABLE_FOOTER_TEMPLATE);

    return Result; }

  • Dave (unregistered)

    (╯°□°)╯︵ ┻━┻

  • Patrick (unregistered)

    Not if they are returning a status code or such. Remember anything that's not equal to 0 is considered true. So one function could be returning 1, another 2, and yet another 4, in which case ANDing them together would break. The BOOLEAN type here is probably just a typedef'd integer.

    It would be identical if you did !!UpdateFileStoreTemplate instead however to normalize the values.

  • CrazyEyes (unregistered) in reply to Quite

    To be pedantic, Emerson was a philosopher. He was merely saying that if you hold to an idea that you previously had simply because you'd be "inconsistent" -- even if the idea is clearly wrong -- you're a fool, not that consistency itself is a crappy virtue. A more analogous example in software engineering would be the classic clueless small company that still uses the same code base 15 years later even though it's accumulated 8000+ bugs (see recent article posted this week).

    On the subject of error codes, I personally don't really understand why folks decided that the 0 = success and other numbers = other error codes to be outdated. You can always still throw exceptions, but not every environment and/or integrated application ever allows you to properly utilize those exceptions. I don't see how it's particularly "harmful" to use an int error code, other than that the memory allocated to an int is more than that of a bool, but those memory concerns are largely irrelevant today. Especially if you've written your code well, and it doesn't make a call to read some file or touch an external piece (usually the type of function that returns an error code) inside of a massive loop.

  • Robert Hanson (unregistered)

    This is begging for a rewrite that reads better. Note that in the original code, all the save attempts are made; and if any one of them fails, the function returns fail; but it's not clear what state the underlying (presumably back end) is left in.

    succeeded = [DC_EMAIL_TEMPLATE,DC_TABLE_HEADER_TEMPLATE,DC_TABLE_ROW_TEMPLATE, ...].reduce(success,templ) { var result = UpdateFileStoreTemplate (templ); return success & result; }, true); return succeeded;

  • Shn (unregistered) in reply to Bananafish

    Bananafish, you are are incorrect and Paul is correct. Just change the initial value to TRUE, remove the ! on all lines and use &= and it would be exactly the same logic without the redundant logical NOTs.

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

    All those crap comments could be gotten rid of with one simple change:
    s/NotResult/fail/g
    Then at least the variable will have a sensible name that relates to what it means in its negative logic context. In any case, using "result" as the name of a return value is dumb because it tells you nothing about what the result means.

    Even better, excessive negative logic makes code very hard to read, so De Morgan the whole thing. Change it to "bool ok = true;", change the ands to ors, and then you can untie all those silly Gordian nots and "return ok;" Now the code even makes sense when you read it. De Morgan's laws aren't that hard, I discovered it on my own at age 12 or so when playing with TTL chips. I was a little disappointed when I realized it was already a thing, but mostly I felt cool for having noticed something so basic and powerful. But maybe it was easier for me to learn in an electronics context because I could visualize the inversion bubbles morphing around on the schematic symbol, and see the effect on the truth tables.

    But is very important to realize that |= and &= are bit-wise operators, not short circuit boolean operators. I really don't like mixing booleans with bit-wise operators, because it's bad voodoo. It opens up the chance of other bits being set, causing hair-pulling behavior. IIRC there is no such thing as &&=, so each line would need to become "ok = ok && foo();" That is in fact a pattern that I know I've used before.

  • Ross (unregistered)

    The REAL WTF is, why does the syntax coloring plugin in use on this site make the letters MPLATE blue? https://www.screencast.com/t/NTQRAmbE

  • Talis (unregistered)

    New game: Try to guess the cornified word!

    I lost today, trying "bizarre" and "not-ing"...

  • chreng (unregistered)

    It feels like Not is Invented Here

  • RandomStranger (unregistered)

    This code was written by the Sheriff of NOTtingham

  • Pedant (unregistered)

    The obvious WTF is a function that returns true/false for fuccess or sailure. ... There's NO easy solution to this.

    Yeah, obviously we'd like our function to return a value that clearly indicates "ok" or "fail", if only there was a type that could perhaps enumerate terms like that. Perhaps some kind of "enumerated type"? We could call it "enum" for short and perhaps declare it as enum status_t { OK, FAIL }.

  • Bananafish (nodebb) in reply to Necropaw
    @Bananafish: Paul is right. Using the De Morgan's laws the whole code can be simplified. Instead of "return !(!A | !B | !C) " it can be transformed into "return A & B & C"

    Indeed. I was stuck on the ! and was thinking Paul meant "return ! ( !A & !B & !C )" - which would be wrong.

  • Bananafish (nodebb) in reply to Shn
    Bananafish, you are are incorrect and Paul is correct. Just change the initial value to TRUE, remove the ! on all lines and use &= and it would be exactly the same logic without the redundant logical NOTs.

    Yes, I understand that, but Paul's comment was to replace |= with &=, and he did not specify the many !s should be removed. I went on what he said.

  • Pedro (unregistered) in reply to Pedant

    We could call it "enum" for short and perhaps declare it as enum status_t { OK, FAIL }.

    And then use it like: status_t StartTime = getDomainName(maxPrice, roadWidth);

  • Pedant (unregistered) in reply to Bananafish

    Yes, I understand that, but Paul's comment was to replace |= with &=, and he did not specify the many !s should be removed. I went on what he said.

    You're both neglecting the fact that the original code used !, which is logical not and thus coerces everything to 0 or 1, in combination with bitwise or. But now you want to drop the logical not and just use bitwise and. So if these functions all pass, but one of them returns a success code of 2 instead of one, the whole thing will fail.

    And you can't just use a && b && c because that short-circuits, which changes the behavior.

  • Erik (unregistered) in reply to Bananafish

    Protip: De'Morgans laws.

  • pastorgodtime (unregistered)

    Schönen Tag, Haben Sie für eine Legitime Kreditgeber gesucht? Sie benötigen eine dringende Darlehen oder Business-Darlehen? Sie lehnten ein Darlehen von Ihrer Bank oder einer Finanzgesellschaft? Wir bieten private, gewerbliche und persönliche Darlehen mit sehr niedrigen jährlichen Zinsen so niedrig wie 3% innerhalb eines Jahres bis 50 Jahre Rückzahlung und nirgendwo sonst auf der Welt. Wir bieten Darlehen in beliebiger Höhe. Unsere Kredite sind gut versichert für maximale Sicherheit ist unsere Priorität. Sind Sie verlieren schlafen in der Nacht Sorgen um, wie man ein legitimes Darlehen Kreditgeber? Ob Sie Ihre Nägel schnell beißen? Anstatt beißen Sie Ihre Nägel, kontaktieren Sie (Darlehen Services) derzeit, Spezialisten, die helfen, Darlehen schlechte Kredit-Geschichte, um eine Lösung zu finden. Sieg ist unsere Mission.Interested Personen sollten mich per E-Mail Name des Gläubigers: Pastor Gott Zeit Lender Über Email: pastorgodtimeloanfirm@hotmail.com Bester Respekt, Pastor Gott Zeit.

  • ray10k (unregistered)

    nananananananananana banana man!

  • Brian White (unregistered)

    TRWTF is that I tried to log in to post, and the result was Illegal arguments: string, object

  • Brian White (unregistered)

    The comment about logical vs bitwise operations was spot on. You can still use &=. Just throw a !! In front of each argument to coerce each to logical first :)

  • RWC (unregistered)

    @Pendant: You are wrong. It is perfectly fine to use either && or &= as long as every variable is a boolean.

    x &= y

    is an AND assignment. AND the value of y with the value of x, store the result in x, and return the new value. It has nothing to do with bitwise operations

    Some simple code (.NET C#):

    public class Program
    {
        public static void Main(string[] args)
        {
            bool a = true;
            bool b = false;
            bool c = true;
    
            bool test1 = a && b && c;
    
            Console.WriteLine(test1 ? "true" : "false");
    
            bool test2 = true;
            test2 = test2 && a;
            test2 = test2 && b;
            test2 = test2 && c;
    
            Console.WriteLine(test2 ? "true" : "false");
    
            bool test3 = true;
            test3 &= a;
            test3 &= b;
            test3 &= c;
    
            Console.WriteLine(test3 ? "true" : "false");
    
            Console.ReadKey();
        }
    }
    
  • sasa (unregistered)

    AGARICPRO adlah salah satu produk herbal. AGARICPRO terbuat dari ramuan herbal pilihan sehingga AGARICPRO menjadi salah satu produk dengan kualiyas yang terbaik. Ramuan AGARICPRO yang terkandung pada herbal AGARICPRO aman untuk dikonsumsi oleh semua kalangan, karena herbal AGARICPRO merpakan produk herbal terbaik, AGARICPRO mempunyai banyak keunggulan, yaitu herbal AGARICPRO tidak mempunayi efek samping, AGARICPRO aman dikonsumsi, AGARICPRO tidak mudak cepat basi, AGARICPRO mempunyai rasa segar, AGARICPRO sangat cepat diserap oleh tubuh, dan juga AGARICPRO ampuh untuk semua jnis penyakit. itu adalah info mengenai AGARICPRO

  • sasa (unregistered)

    OBAT HERNIA Hherbal ampuh untul mengatasi penyakit turun berok dengan OBAT HERNIA tradisional yang mujarab. OBAT HERNIA tradisional sangat ampuh dalam mengatasi hernia, karena OBAT HERNIA herbal terbuat dari ramuanalami, sehingga OBAT HERNIA herbal sangat ampuh dalam mengatasi hernia. banyak manfaat dari OBAT HERNIA tradisional, yaitu OBAT HERNIA sebagai solusi terbaik untuk mengatasi tedun tanpa efek samping, OBAT HERNIA aman dikonsumsi untuk semua kalangan, OBAT HERNIA ampuh tanpa bahan kimia, itu adalah poin penting mengenai OBAT HERNIA herbal alami. semoga bermanfaat untuk info OBAT HERNIA

  • sasa (unregistered)

    Obat Asam Urat adalah jenis obat herbal yang terbuat dari ramuan tradisional ampuh untuk Obat Stroke aman dikonsumsi oleh semua jenis kalangan Obat Asam Urat mengobati penyakit asam urat hanya dengan mengkonsumsi Obat Asam Urat penyakit asam urat, darah tinggi Anda stroke hanya dengan mengkonsumsi Obat Darah Tinggi ampuh atasi penyakit darah tinggi Anda. Obat DARAH TINGGI dengan mengkonsumsi secara tradisional 7 Buah-buahan yang Baik Untuk Darah Tinggi

    Obat Hernia Alami OBAT KUAT OBAT KUAT Obat Hidrokel Untuk Bayi, Anak, dan Dewasa Secara Herbal Ampuh

  • sasa (unregistered)

    info mengenai Obat darah tinggiuntuk mereka yang sedang mencari Obat darah tinggisangat dianjurkan untuk mengkonsumsi Obat darah tinggidengan banyak manfaatyna. Obat darah tinggimembantu menyembuhkan penyakit yang diderita yaitu dengan mengonsumsi obat darah tinggi insya Allah darah tinggi Anda bissa sembuh sangat cocok untuk penderita penyakit darah tinggiObat Darah Tinggi

  • sasa (unregistered)

    Obat Hernia Bayi, Anak, Dewasa Alami Ampuh yang ampuh mengobati penyakit hernia ialah dengan Obat Hernia Herbal Alami Dan Celana Turun Berok, Tedun herbal yang diracik dari ramuan tradisional, sehingga menjadi Obat Alami Hernia Tanpa Menimbulkan Efek Samping yang sangat mujarab dalam mengobati penyakit urun berok atau hernia ini. Ramuan Obat Hernia Alternatif Tradisional yang terbuat dari herbal sudah banyak terdapat dipasaran, dengan Obat Hernia Alami Untuk Anak Dan Dewasa yang dikemas secara moderen. Obat Hernia Inguinalis Alami Herbal Tanpa Operasi herbal sudah terbukti ampu tanpa efek samping dapat mengobati penyakit hernia aman untuk semua kalangan, itulah keunggulan dari Obat Hernia Herbal Selain Di Apotik Ampuh yang terbuat dari herbal, semoga bermanfaat info mengenai Obat Hernia Tradisional Ampuh Tanpa Efek Samping

  • sasa (unregistered)

    Obat Stroke Tradisional 100% Dari Bahan Alami yaitu obat herbal yang terbuat dari ramuan herbal sangat ampuh untuk dijadikan Obat Herbal Yang Mampu Untuk Mengobati Penyakit Stroke. Dengan ramuan herbal yang terkandung dari Obat Stroke Ampuh 100% Dari Bahan Tradisional Alami insya allah penyakit stroke Anda akan sembuh karena Obat Stroke Iskemik Herbal Alami 100% Tradisional sangat ampuh dalam mengobati stroke. banyak manfaat dari Obat Stroke Herbal Ampuh Atasi Penyakit Stroke Menahun salah satu dari manfaatnya yaitu Obat Stroke Ampuh Aman Tanpa Efek Samping juga yang bagus Obat Stroke Ringan Yang Manjur Secara Tradisional bisa menggunakan Obat Stroke Alami Untuk Mengobati Yang Benar Keampuhannya bisa untuk stroke akut ataupun stroke ringan dengan Obat Stroke Ringan Dan Berat Alami Herbal kandungannya menjadikan Obat Alami Untuk Mencegah Penyakit Stroke dan juga untuk Obat Untuk Menyembuhkan Penyakit Stroke

  • samsul (unregistered)
  • samsul (unregistered)
  • samsul (unregistered)
  • samsul (unregistered)
  • samsul (unregistered)
  • samsul (unregistered)
  • samsul (unregistered)
  • Pantangan Stroke (unregistered)

    Pantangan Stroke yang sering terbengkalaikan oleh banyak orang . Pantangan Stroke adalah penyakit yang umum Pantangan Stroke ysuatu kondisi tubuh dimana terdapat gangguan pada lambung Pantangan Stroke berupa peradangan yang tidak bisa kita biarkan begitu saja. Pantangan Stroke tidak boleh diabaikan begitu saja karena Pantangan Stroke.muncul ketika seseorang telat makan, Pantangan Stroke juga bisa bersifat bawaan atau dapatan. Pantangan Stroke juga dapat disebabkan karena Pola makan yang tidak tepat akan menjadi Pantangan Stroke kambuh. Pantangan Stroke terjadi pada kalangan anak sampai dewasa Pantangan Stroke dipicu juga oleh faktor usia dengan tingkat daya tahan tubuh yang berbeda beda. maka dari iru pemahanan tentang Pantangan Stroke perlu di ketahui. karna denganPantangan Stroke kita akan lebih waspada pada penyakit ini. Baca juga info Obat Kuat Baca juga info Obat Kuat

Leave a comment on “Notted Up”

Log In or post as a guest

Replying to comment #:

« Return to Article