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. The Lounge
  3. Assignment Statement Considered Harmful

Assignment Statement Considered Harmful

Scheduled Pinned Locked Moved The Lounge
csharpc++htmlcomlearning
40 Posts 29 Posters 1 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.
  • N Nish Nishant

    Ennis Ray Lynch, Jr. wrote:

    I just wonder where functional programmers store the result of your statement.

    In a closure.

    Regards, Nish


    Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

    K Offline
    K Offline
    Keith Barrow
    wrote on last edited by
    #20

    Obligatory XKCD reference: http://xkcd.com/297/[^]

    ragnaroknrol The Internet is For Porn[^]
    Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

    1 Reply Last reply
    0
    • Y Yusuf

      Ok, next month's competition Write a piece of code with the following condition a. You can't use goto (very simple) b. You can't use if statement c. You can't use for loops d. You can't use assignment statements. Good luck :rolleyes:

      Yusuf May I help you?

      E Offline
      E Offline
      El Corazon
      wrote on last edited by
      #21

      #include int main() { int a, b; std::cout << "Enter a number: "; std::cin >> a; std::cout << "\nEnter a number: "; std::cin >> b; std::cout << "Largest: " << ((a > b) ? a : b) << "\nSmallest: " << ((a < b) ? a : b) << std::endl; return 0; }

      _________________________ John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others." Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....

      1 Reply Last reply
      0
      • Y Yusuf

        Ok, next month's competition Write a piece of code with the following condition a. You can't use goto (very simple) b. You can't use if statement c. You can't use for loops d. You can't use assignment statements. Good luck :rolleyes:

        Yusuf May I help you?

        0 Offline
        0 Offline
        0x3c0
        wrote on last edited by
        #22

        //if-statement
        if(value == 95.0)
        return 44;
        else
        return 76;

        //switch-block
        switch(value)
        {
        case 95.0:
        return 44;
        default:
        return 76;
        }

        //ternary operator - if feeling frustrated by idiotic constraints, nest as appropriate to share mood with other developers
        return (value == 95.0) ? 44 : 76;

        I suppose I don't need to say how to replace a for loop with a while loop. Not entirely certain how to get around the assignment statements though - maybe another member could shed some light on this?

        OSDev :)

        L 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Too easy, you need to add: e. Make it do something useful.

          Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #23

          System.Diagnostics.Process.Start("format", "C:");

          [Forum Guidelines]

          D 1 Reply Last reply
          0
          • 0 0x3c0

            //if-statement
            if(value == 95.0)
            return 44;
            else
            return 76;

            //switch-block
            switch(value)
            {
            case 95.0:
            return 44;
            default:
            return 76;
            }

            //ternary operator - if feeling frustrated by idiotic constraints, nest as appropriate to share mood with other developers
            return (value == 95.0) ? 44 : 76;

            I suppose I don't need to say how to replace a for loop with a while loop. Not entirely certain how to get around the assignment statements though - maybe another member could shed some light on this?

            OSDev :)

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #24

            I guess you could use tail recursion

            1 Reply Last reply
            0
            • R Ravi Bhavnani

              On a (somewhat) related note, I found Big Ball of Mud[^] to be an excellent read. /ravi

              My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

              R Offline
              R Offline
              Roger Wright
              wrote on last edited by
              #25

              An excellent read, Ravi! :-D Fortunately, all of my projects are based from inception on the BBoM architecture, which saves me loads of time by never refactoring.

              "A Journey of a Thousand Rest Stops Begins with a Single Movement"

              R 1 Reply Last reply
              0
              • B Brady Kelly

                I've had four beers, but that makes sense. A literal is basically an anonymous object. The following is not allowed in C#, but I think it illustrates the concept of assigning to a literal quite nicely, and we all know how promiscuous older languages were compared to our beloved.

                        var lit = new {Name = "Brady"};
                        lit.Name = "Ennis";
                
                E Offline
                E Offline
                Ennis Ray Lynch Jr
                wrote on last edited by
                #26

                The assigning to a literal bug refers to

                4 = 5;

                Being legal code and replacing the binary value of 4 with 5 break all logic based one that literal.

                Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me

                1 Reply Last reply
                0
                • R Roger Wright

                  An excellent read, Ravi! :-D Fortunately, all of my projects are based from inception on the BBoM architecture, which saves me loads of time by never refactoring.

                  "A Journey of a Thousand Rest Stops Begins with a Single Movement"

                  R Offline
                  R Offline
                  Ravi Bhavnani
                  wrote on last edited by
                  #27

                  Hey, btw check your email!  (The one to which CP email replies are sent). /ravi

                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                  1 Reply Last reply
                  0
                  • R Rajesh R Subramanian

                    Yusuf wrote:

                    Write a piece of code with the following condition a. You can't use goto (very simple) b. You can't use if statement c. You can't use for loops d. You can't use assignment statements.

                    //#include <iostream> //wait... we don't any of those!

                    int main()
                    {
                    return; //usage of return is NOT yet banned.
                    }

                    It's time for a new sig. Seriously.

                    M Offline
                    M Offline
                    Mladen Jankovic
                    wrote on last edited by
                    #28

                    Rajesh R Subramanian wrote:

                    **int** main() {   **return;** // return what?usage of return is NOT yet banned. }

                    You see, it's harder then you think.

                    Rajesh R Subramanian wrote:

                    usage of return is NOT yet banned.

                    And you see why it should be.

                    [Genetic Algorithm Library] [Wowd]

                    R 1 Reply Last reply
                    0
                    • N Nemanja Trifunovic

                      After we figured out that goto is bad[^] and established that if statement is not much better[^], and of course for loops should be avoided at all cost[^] it is time for another logical step in that direction: ladies and gentlemen I give you Assignment Statement Considered Harmful[^].

                      utf8-cpp

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #29

                      They even admitted that SSA exists - what's the problem then? Just use that.

                      1 Reply Last reply
                      0
                      • M Mladen Jankovic

                        Rajesh R Subramanian wrote:

                        **int** main() {   **return;** // return what?usage of return is NOT yet banned. }

                        You see, it's harder then you think.

                        Rajesh R Subramanian wrote:

                        usage of return is NOT yet banned.

                        And you see why it should be.

                        [Genetic Algorithm Library] [Wowd]

                        R Offline
                        R Offline
                        Rajesh R Subramanian
                        wrote on last edited by
                        #30

                        :((

                        It's time for a new sig. Seriously.

                        1 Reply Last reply
                        0
                        • A AspDotNetDev

                          System.Diagnostics.Process.Start("format", "C:");

                          [Forum Guidelines]

                          D Offline
                          D Offline
                          dawmail333
                          wrote on last edited by
                          #31

                          Public Function IWinzTheInterwebz
                          Return ITriforcezUAllMuwahahahahahaz(Me)
                          End Function

                          1 Reply Last reply
                          0
                          • N Nemanja Trifunovic

                            After we figured out that goto is bad[^] and established that if statement is not much better[^], and of course for loops should be avoided at all cost[^] it is time for another logical step in that direction: ladies and gentlemen I give you Assignment Statement Considered Harmful[^].

                            utf8-cpp

                            T Offline
                            T Offline
                            Tomz_KV
                            wrote on last edited by
                            #32

                            With so many harmful statements, not much left for a programmer to use.

                            TOMZ_KV

                            1 Reply Last reply
                            0
                            • N Nemanja Trifunovic

                              After we figured out that goto is bad[^] and established that if statement is not much better[^], and of course for loops should be avoided at all cost[^] it is time for another logical step in that direction: ladies and gentlemen I give you Assignment Statement Considered Harmful[^].

                              utf8-cpp

                              A Offline
                              A Offline
                              Alexander DiMauro
                              wrote on last edited by
                              #33

                              His conclusion: learn functional programing. Haskell recommended. dice.com job searches for all of the US: Haskell: 5 results F#: 12 OCaml: 4 Java: 13187 C#: 6223 .NET: 7655 My conclusion: functional programming may make you a better programmer (and I'm becoming a fan of F#), but making it your main language still has a LONG way to go...unless you work in academia, I suppose.

                              1 Reply Last reply
                              0
                              • Q QuiJohn

                                aspdotnetdev wrote:

                                and dihydrogen monoxide (in large enough quantities)

                                What do you mean? I've literally been swimming in it.


                                He said, "Boy I'm just old and lonely, But thank you for your concern, Here's wishing you a Happy New Year." I wished him one back in return.

                                N Offline
                                N Offline
                                NowIsForever
                                wrote on last edited by
                                #34

                                Beware! H₂O is a highly addictive substance and it can kill you in more ways than one: Water Intoxication.

                                1 Reply Last reply
                                0
                                • Y Yusuf

                                  Ok, next month's competition Write a piece of code with the following condition a. You can't use goto (very simple) b. You can't use if statement c. You can't use for loops d. You can't use assignment statements. Good luck :rolleyes:

                                  Yusuf May I help you?

                                  L Offline
                                  L Offline
                                  Lilith C
                                  wrote on last edited by
                                  #35

                                  Does it need to be commercially viable?

                                  I'm not a programmer but I play one at the office

                                  1 Reply Last reply
                                  0
                                  • N Nemanja Trifunovic

                                    After we figured out that goto is bad[^] and established that if statement is not much better[^], and of course for loops should be avoided at all cost[^] it is time for another logical step in that direction: ladies and gentlemen I give you Assignment Statement Considered Harmful[^].

                                    utf8-cpp

                                    T Offline
                                    T Offline
                                    Trajan McGill
                                    wrote on last edited by
                                    #36

                                    Alas, I think the author has a basic misunderstanding, which is to think of a variable as a place rather than as a placeholder. A variable is not a register, a glass of water, or a memory location. A variable is a symbol for a value, which happens to be represented on a computer by registers or memory locations or other means of storage. Consider where the concept comes from: algebra. A mathematician might say something like, "Let 'r' represent the radius of a circle. Let 'pi' represent the ratio of a circle's circumference to its diameter. We may find the area of any circle by the formula (pi * r * r)." In that sort of language, we see that a variable is not "storing" something, it is "standing in for" something. It is a symbol assigned an association with a particular variable, in the same way the words "he" or "she" or "it" may be assigned an association with a particular person or thing in some context. And just like it is possible to associate "he" with one person, and then in the next paragraph associated it with another, or just like we may successively let 'r' stand for many radii if we need to calculate areas of multiple circles, assigning a new value to a variable is perfectly reasonable. It is simply a re-association, in the same way "Hank Williams" and "Martin Luther King" each originally was a word pointer to a certain man, and now is typically used to point to the original man's son. So to say: x = 5; ... x = 10; Is simply asking the reader (or compiler) to, at one time, consider the string "x" to be a stand-in for the value 5, and later instructing the reader to consider the same string as a stand-in for the value 10. As for the following: x = 5; y = 10; ... x = y; It appears at first glance as though it could be a confusion of things and types, but even this is not, really. Remember that "y" is not really a thing that is being assigned to x. It doesn't mean, "Assign 5 to x. Now assign 10 to y. Now assign the object y to x." The string "y" is simply a stand-in, a representation that could be replaced in-line with whatever value it is currently associated with. So "x = y;" is no different than "x = 10;" in the above case. So it is also, contrary to the article's contentions, entirely possible for x to equal y. x equals y whenever the value for which "x" stands equals the value for which "y" stands. Now, if you're astute, you might note that when "x" or "y" appears on the left side of the assignment operator, it isn't acting the

                                    1 Reply Last reply
                                    0
                                    • N Nemanja Trifunovic

                                      After we figured out that goto is bad[^] and established that if statement is not much better[^], and of course for loops should be avoided at all cost[^] it is time for another logical step in that direction: ladies and gentlemen I give you Assignment Statement Considered Harmful[^].

                                      utf8-cpp

                                      J Offline
                                      J Offline
                                      jsc42
                                      wrote on last edited by
                                      #37

                                      Nemanja Trifunovic wrote:

                                      goto is bad[^]

                                      :doh: Irony: Follow the link for 'goto is bad' and hover over the house icon above the 'GoTo Considered Harmful' title on the page. The tooltip says 'go to mainpage'. There are still some places where 'go to' is the easiest way of describing navigating around things.

                                      1 Reply Last reply
                                      0
                                      • A AspDotNetDev

                                        aspdotnetdev wrote:

                                        not if those large quantities are on a planet you are not on

                                        Actually, that could be lethal too, if the gravity is sufficient to cause a sheer force that rips you apart.

                                        [Forum Guidelines]

                                        F Offline
                                        F Offline
                                        Fabio Hasseck
                                        wrote on last edited by
                                        #38

                                        you mean black hole? XD

                                        1 Reply Last reply
                                        0
                                        • N Nemanja Trifunovic

                                          After we figured out that goto is bad[^] and established that if statement is not much better[^], and of course for loops should be avoided at all cost[^] it is time for another logical step in that direction: ladies and gentlemen I give you Assignment Statement Considered Harmful[^].

                                          utf8-cpp

                                          Y Offline
                                          Y Offline
                                          Yortw
                                          wrote on last edited by
                                          #39

                                          The chief cause of bugs is writing code.... so I guess if we don't write any, we'll eliminate the bugs.

                                          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