Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. This code is evil

This code is evil

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++question
14 Posts 12 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D den2k88

    something = Anotherthing - ((condition == 0) ? (assignment_here = object->method()) : someothervalue);

    So we have: an arithmetic expression of which one operand is actually the result of the ternary operator, which in turn assigns a value to another unrelated variable and calls a function... but only if the condition of the ternary operator is true. This thing is pure evil and is sapping away at my sanityk lanòsak òjslshf pAHRW R'LYEH.

    GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

    Sander RosselS Offline
    Sander RosselS Offline
    Sander Rossel
    wrote on last edited by
    #5

    Anotherthing is inconsistently cased, pure evil indeed!

    Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

    N 1 Reply Last reply
    0
    • D den2k88

      something = Anotherthing - ((condition == 0) ? (assignment_here = object->method()) : someothervalue);

      So we have: an arithmetic expression of which one operand is actually the result of the ternary operator, which in turn assigns a value to another unrelated variable and calls a function... but only if the condition of the ternary operator is true. This thing is pure evil and is sapping away at my sanityk lanòsak òjslshf pAHRW R'LYEH.

      GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

      N Offline
      N Offline
      Nathan Minier
      wrote on last edited by
      #6

      So.... We should both be very grateful that you don't do peer review for me. I would have tucked in an anonymous function just to piss you off.

      "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

      1 Reply Last reply
      0
      • Sander RosselS Sander Rossel

        Anotherthing is inconsistently cased, pure evil indeed!

        Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

        N Offline
        N Offline
        Nathan Minier
        wrote on last edited by
        #7

        That is indeed the real crime here.

        "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

        1 Reply Last reply
        0
        • D den2k88

          something = Anotherthing - ((condition == 0) ? (assignment_here = object->method()) : someothervalue);

          So we have: an arithmetic expression of which one operand is actually the result of the ternary operator, which in turn assigns a value to another unrelated variable and calls a function... but only if the condition of the ternary operator is true. This thing is pure evil and is sapping away at my sanityk lanòsak òjslshf pAHRW R'LYEH.

          GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

          M Offline
          M Offline
          Marc Clifton
          wrote on last edited by
          #8

          den2k88 wrote:

          but only if the condition of the ternary operator is true.

          There's certain elegance to that which I can't help but admire.

          Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

          1 Reply Last reply
          0
          • D den2k88

            something = Anotherthing - ((condition == 0) ? (assignment_here = object->method()) : someothervalue);

            So we have: an arithmetic expression of which one operand is actually the result of the ternary operator, which in turn assigns a value to another unrelated variable and calls a function... but only if the condition of the ternary operator is true. This thing is pure evil and is sapping away at my sanityk lanòsak òjslshf pAHRW R'LYEH.

            GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

            S Offline
            S Offline
            Slacker007
            wrote on last edited by
            #9

            At least it's all on one line. :)

            1 Reply Last reply
            0
            • D den2k88

              something = Anotherthing - ((condition == 0) ? (assignment_here = object->method()) : someothervalue);

              So we have: an arithmetic expression of which one operand is actually the result of the ternary operator, which in turn assigns a value to another unrelated variable and calls a function... but only if the condition of the ternary operator is true. This thing is pure evil and is sapping away at my sanityk lanòsak òjslshf pAHRW R'LYEH.

              GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

              B Offline
              B Offline
              Bernhard Hiller
              wrote on last edited by
              #10

              There's a lack of prefix and postfix operators, don't you see that? The code should be corrected to:

              something = Anotherthing - ((++condition == 0) ? (assignment_here = object->method()) : --someothervalue);

              Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

              D 1 Reply Last reply
              0
              • B Bernhard Hiller

                There's a lack of prefix and postfix operators, don't you see that? The code should be corrected to:

                something = Anotherthing - ((++condition == 0) ? (assignment_here = object->method()) : --someothervalue);

                Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

                D Offline
                D Offline
                den2k88
                wrote on last edited by
                #11

                There are in other bits of code. This is as of now the single line of code with the most horrors I ever seen.

                GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                D 1 Reply Last reply
                0
                • D den2k88

                  There are in other bits of code. This is as of now the single line of code with the most horrors I ever seen.

                  GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                  D Offline
                  D Offline
                  David ONeil
                  wrote on last edited by
                  #12

                  Add a lambda to it!

                  The forgotten roots of science | C++ Programming | DWinLib

                  1 Reply Last reply
                  0
                  • M MarkTJohnson

                    I would only make a couple of changes

                    something = Anotherthing - (condition ? someothervalue : (assignment_here = object->method()));

                    I never liked

                    condition == 0

                    I like

                    !condition

                    much better.

                    K Offline
                    K Offline
                    kalberts
                    wrote on last edited by
                    #13

                    Currently I am so fortunate that my programming is in a language where (numeric != bool) :-) In my last plain C project, I happened to set up a "#define ever ;;" so that I could write "for (ever) {..." to make an infinite loop, which is not uncommon in embedded code. (In the CHILL language, made for programming phone switches, "DO FOR EVER ..." is defined in the basic language.) One of the other team members reacted quite fiercly to this, searching through the entire code base for "for (ever)", adding a nasty commit message about "someone" who were trying to make funny jokes in the code, and he changed it to the proper "while (1)". The header project files did define "true" and "false" constants, but he woudn't accept even "while (true)": There is one proper way to make an infinte loop in C, and that is "while (1)". I was seriously considering to change it to "while (2)", with a commit message that 2 makes it twice as clear that the loop should run for (ever), but I decided not to. My relationship to that guy was bad enough without further provocations. So, provided "condition" is a bool variable, or an numeric variable that stores nothing but the value of bool expressions, I certainly agree that "!condition" is the proper way. But if "condition" is a numeric value treated as such (e.g. a counter from n down to 0), treating it as a bool for flow control is bad. Then "condition == 0" is far better. Same with pointers. I detest "if (!nextpointer) { /*leave loop*/" - that should be "if (nextpointer == null)" (or "nil" or "empty" or whatever your favorite language calls is). Which makes me think of that really nice construction I have encountered in a single language: "FOR currentpointer IN listhead:nextpointer DO..." - "nexpointer" being the name of a pointer member in the class "listhead" (and "currentpointer") points to.

                    1 Reply Last reply
                    0
                    • D den2k88

                      something = Anotherthing - ((condition == 0) ? (assignment_here = object->method()) : someothervalue);

                      So we have: an arithmetic expression of which one operand is actually the result of the ternary operator, which in turn assigns a value to another unrelated variable and calls a function... but only if the condition of the ternary operator is true. This thing is pure evil and is sapping away at my sanityk lanòsak òjslshf pAHRW R'LYEH.

                      GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

                      L Offline
                      L Offline
                      Lutoslaw
                      wrote on last edited by
                      #14

                      Well, object->method() could be a recursive call so it's not that bad.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups