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. Into bad habits

Into bad habits

Scheduled Pinned Locked Moved The Lounge
csharpjavascriptcomhelp
40 Posts 18 Posters 0 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.
  • J Jim Crafton

    Bah, for a second I thought this was about real software. Then I saw the name "MelonCard", and "techcrunch" and realized they were talking about web "programming". Next they be crying about the time they found out that they were not in fact visited by magical flying unicorns.

    ¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Blow

    F Offline
    F Offline
    Fabio Franco
    wrote on last edited by
    #6

    LOL But c'mon, the topic is about real software and how, as you put it, web "programming" can impair one's ability to right one.

    "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

    J 1 Reply Last reply
    0
    • F Fabio Franco

      LOL But c'mon, the topic is about real software and how, as you put it, web "programming" can impair one's ability to right one.

      "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

      J Offline
      J Offline
      Jim Crafton
      wrote on last edited by
      #7

      Yes, and another reason why using a stateless protocol for applications, especially applications that specifically *need* state, is such a horrible idea. Bring on Web 4.1! But I did go back and read more - and even learned something new about JS!

      ¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Blow

      F 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Strict languages help a lot - if you listen to the warnings they give. (Personally I run with "treat warnings as errors" set on). For example: if(myInt & 0x80 != 0) in C# is an error - the result is not bool. In C++ it just doesn't do what you expect... This one caught me in an answer in Q&A because I had got so used to C# telling me off that I assumed the operator precedence was correct when C++ didn't give me a warning or error...

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        F Offline
        F Offline
        Fabio Franco
        wrote on last edited by
        #8

        OriginalGriff wrote:

        if(myInt & 0x80 != 0)

        When I first saw this I was tempted to reply with a: "Whats wrong with this on C#?" Since I'm not used to perform bitwise ANDs on my dayly work I didn't realize that comparison operators had precedence over bitwise operators. I guess in C++ the result would be false (0) if myInt is different from 1?

        "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

        OriginalGriffO B 2 Replies Last reply
        0
        • J Jim Crafton

          Yes, and another reason why using a stateless protocol for applications, especially applications that specifically *need* state, is such a horrible idea. Bring on Web 4.1! But I did go back and read more - and even learned something new about JS!

          ¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Blow

          F Offline
          F Offline
          Fabio Franco
          wrote on last edited by
          #9

          The very word "stateless" creeps me out...

          "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

          1 Reply Last reply
          0
          • F Fabio Franco

            OriginalGriff wrote:

            if(myInt & 0x80 != 0)

            When I first saw this I was tempted to reply with a: "Whats wrong with this on C#?" Since I'm not used to perform bitwise ANDs on my dayly work I didn't realize that comparison operators had precedence over bitwise operators. I guess in C++ the result would be false (0) if myInt is different from 1?

            "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #10

            Yep! Annoying that, isn't it? As a result, I always used brackets - which made the code messy - until I got well into C# where they aren't so necessary. So I stopped. :doh: That's also why I always use redundant brackets for if and for constructs:

            if (condition)
            {
            statement;
            }

            Because in the old days (pre auto formatting)

            if (condition)
            statement;
            statement;

            Looked too much like it executed both on the condition...

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            F H 2 Replies Last reply
            0
            • OriginalGriffO OriginalGriff

              Yep! Annoying that, isn't it? As a result, I always used brackets - which made the code messy - until I got well into C# where they aren't so necessary. So I stopped. :doh: That's also why I always use redundant brackets for if and for constructs:

              if (condition)
              {
              statement;
              }

              Because in the old days (pre auto formatting)

              if (condition)
              statement;
              statement;

              Looked too much like it executed both on the condition...

              Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

              F Offline
              F Offline
              Fabio Franco
              wrote on last edited by
              #11

              Oh yeah, those kind of things can make you run around in circles for an unpleasant amount of time :sigh:

              "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

              OriginalGriffO 1 Reply Last reply
              0
              • F Fabio Franco

                Oh yeah, those kind of things can make you run around in circles for an unpleasant amount of time :sigh:

                "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #12

                I was sooooo happy when compilers started giving a warning on

                if (condition);
                {
                statement;
                }

                :laugh:

                Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                F H 2 Replies Last reply
                0
                • OriginalGriffO OriginalGriff

                  I was sooooo happy when compilers started giving a warning on

                  if (condition);
                  {
                  statement;
                  }

                  :laugh:

                  Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                  F Offline
                  F Offline
                  Fabio Franco
                  wrote on last edited by
                  #13

                  Oh yes, received a couple of those myself. Bless the little green underline. :)

                  "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                  1 Reply Last reply
                  0
                  • F Fabio Franco

                    So, today I saw this on CP's daily news: How One Missing `var` Ruined our Launch[^] There's always been endless discussions that it's not about the language, but about the programmer when bad practices arise. Like endless flaming wars against languages VB and JS. Now, to add some more fuel to the debate I'd like to ask: Why some mistake like that happened? It was a simple mistake with serious consequences. The first thing that came to my mind was that, I'd never make such a mistake (ok, maybe 0.00000001% of chance to make it). To me it's like driving without seat-belts. There's no way I'd do it because Brazilian traffic laws are so strict about it that I got very used to it, the same way I'm used to wear clothes when I leave home. Now, by programming on strict languages for the most part of my professional life, declaring variables became the same way, it's just natural, it would feels wrong and just the thought of it bothers me. Would it be the same if I got used developing on more forgiving languages like JS? Do forgiving languages make us more sloppy? I think the forgiving languages may shape us to acquire bad habits. That's one of the reasons I favor C# to VB.Net. There were countless times that I heard: "Bad code can be written in any language". But that's not the point. I'm sure that if I had done more work in more forgiving languages I'd be much more likely to commit mistakes like that. That's why I favor strict languages more. They help you develop good habits that are independent of the fact of a good or bad programmer. Thoughts?

                    "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                    J Offline
                    J Offline
                    Joe Woodbury
                    wrote on last edited by
                    #14

                    Except the problem here really wasn't with 'var' but with scope and scope can get you in most languages. Of course, if you want to start a list of what's wrong with javascript, it's going to get mighty long.

                    F 1 Reply Last reply
                    0
                    • J Joe Woodbury

                      Except the problem here really wasn't with 'var' but with scope and scope can get you in most languages. Of course, if you want to start a list of what's wrong with javascript, it's going to get mighty long.

                      F Offline
                      F Offline
                      Fabio Franco
                      wrote on last edited by
                      #15

                      Joe Woodbury wrote:

                      Except the problem here really wasn't with 'var' but with scope and scope can get you in most languages.

                      But clearly for what the author said, he didn't have the intention to declare a global variable and that he had forgotten to use the var keyword. Combining that with JS behavior generated the problem. But again, the root of the problem is that javascript does not enforce variable declaration, creating a big potential for bad habits.

                      Joe Woodbury wrote:

                      Of course, if you want to start a list of what's wrong with javascript, it's going to get mighty long.

                      Couldn't agree more. This makes even more important having good habits.

                      "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                      W 1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        Strict languages help a lot - if you listen to the warnings they give. (Personally I run with "treat warnings as errors" set on). For example: if(myInt & 0x80 != 0) in C# is an error - the result is not bool. In C++ it just doesn't do what you expect... This one caught me in an answer in Q&A because I had got so used to C# telling me off that I assumed the operator precedence was correct when C++ didn't give me a warning or error...

                        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                        G Offline
                        G Offline
                        Gary R Wheeler
                        wrote on last edited by
                        #16

                        That's why I never bother learning the precedence rules in a programming language, and fully parenthesize expressions. Yeah, the hoi polloi will look down their noses at my pansy-assed, belt-and-suspenders way of doing things, but then I don't have to debug stupid mistakes like in your expression.

                        if ((myInt & 0x80) != 0)

                        My mistakes are far more intelligent, and only make me want to stab someone in the face with a spoon. For example, today I had a project that kept getting unresolved references at link time, even though the import library was in the correct location, and a number of other projects linked to it with no problems. I spent four hours playing with linker options, copying the import library to various locations, and so on, before I finally found the problem. The compiler on the DLL project was set to not treat wchar_t as a builtin type, while the compiler on project using the DLL was set to do so. The function signatures in the DLL therefore didn't match because of name mangling differences. Grrr... BTW: I was the one who screwed this up and had the compiler set differently in the two projects. One spoonicide, coming up.

                        Software Zen: delete this;

                        1 Reply Last reply
                        0
                        • J Jim Crafton

                          Bah, for a second I thought this was about real software. Then I saw the name "MelonCard", and "techcrunch" and realized they were talking about web "programming". Next they be crying about the time they found out that they were not in fact visited by magical flying unicorns.

                          ¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Blow

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

                          Finally somebody who says it :)

                          And from the clouds a mighty voice spoke:
                          "Smile and be happy, for it could come worse!"

                          And I smiled and was happy
                          And it came worse.

                          1 Reply Last reply
                          0
                          • F Fabio Franco

                            Joe Woodbury wrote:

                            Except the problem here really wasn't with 'var' but with scope and scope can get you in most languages.

                            But clearly for what the author said, he didn't have the intention to declare a global variable and that he had forgotten to use the var keyword. Combining that with JS behavior generated the problem. But again, the root of the problem is that javascript does not enforce variable declaration, creating a big potential for bad habits.

                            Joe Woodbury wrote:

                            Of course, if you want to start a list of what's wrong with javascript, it's going to get mighty long.

                            Couldn't agree more. This makes even more important having good habits.

                            "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                            W Offline
                            W Offline
                            was8309
                            wrote on last edited by
                            #18

                            good habits like using JSLint

                            R 1 Reply Last reply
                            0
                            • OriginalGriffO OriginalGriff

                              Yep! Annoying that, isn't it? As a result, I always used brackets - which made the code messy - until I got well into C# where they aren't so necessary. So I stopped. :doh: That's also why I always use redundant brackets for if and for constructs:

                              if (condition)
                              {
                              statement;
                              }

                              Because in the old days (pre auto formatting)

                              if (condition)
                              statement;
                              statement;

                              Looked too much like it executed both on the condition...

                              Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                              H Offline
                              H Offline
                              hairy_hats
                              wrote on last edited by
                              #19

                              I really don't like indented braces. Just saying.

                              1 Reply Last reply
                              0
                              • OriginalGriffO OriginalGriff

                                I was sooooo happy when compilers started giving a warning on

                                if (condition);
                                {
                                statement;
                                }

                                :laugh:

                                Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                                H Offline
                                H Offline
                                hairy_hats
                                wrote on last edited by
                                #20

                                I look forward to the day when compilers give a warning because you've indented the braces... ;)

                                OriginalGriffO N 2 Replies Last reply
                                0
                                • H hairy_hats

                                  I look forward to the day when compilers give a warning because you've indented the braces... ;)

                                  OriginalGriffO Offline
                                  OriginalGriffO Offline
                                  OriginalGriff
                                  wrote on last edited by
                                  #21

                                  :laugh: Tough!

                                  Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                  1 Reply Last reply
                                  0
                                  • OriginalGriffO OriginalGriff

                                    Strict languages help a lot - if you listen to the warnings they give. (Personally I run with "treat warnings as errors" set on). For example: if(myInt & 0x80 != 0) in C# is an error - the result is not bool. In C++ it just doesn't do what you expect... This one caught me in an answer in Q&A because I had got so used to C# telling me off that I assumed the operator precedence was correct when C++ didn't give me a warning or error...

                                    Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                                    B Offline
                                    B Offline
                                    BobJanova
                                    wrote on last edited by
                                    #22

                                    This is why precedence rules are stupid and a position based ordering is much better – it's unambiguous and simple, even with functions you haven't seen before.

                                    1 Reply Last reply
                                    0
                                    • F Fabio Franco

                                      OriginalGriff wrote:

                                      if(myInt & 0x80 != 0)

                                      When I first saw this I was tempted to reply with a: "Whats wrong with this on C#?" Since I'm not used to perform bitwise ANDs on my dayly work I didn't realize that comparison operators had precedence over bitwise operators. I guess in C++ the result would be false (0) if myInt is different from 1?

                                      "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                                      B Offline
                                      B Offline
                                      BobJanova
                                      wrote on last edited by
                                      #23

                                      If myInt doesn't have the 1 bit set, i.e. if it's even.

                                      F 1 Reply Last reply
                                      0
                                      • W was8309

                                        good habits like using JSLint

                                        R Offline
                                        R Offline
                                        Rob Grainger
                                        wrote on last edited by
                                        #24

                                        Most essential comment on the thread. Could only be improved by a link: JSLint[^]

                                        J 1 Reply Last reply
                                        0
                                        • L Lost User

                                          I don't have a choice, I have to use C, but I do like using the easier languages. You can get more done with less pitfalls than with hard languages. But I think you are right. Yo need exposure to the hard ones to know how the machine realy works. That way you write better code in easy languages.

                                          ============================== Nothing to say.

                                          R Offline
                                          R Offline
                                          Rob Grainger
                                          wrote on last edited by
                                          #25

                                          I think that's a different issue. C++, used as a better C, issues a lot more type warnings, forcing you to check usage of types and catching certain classes of errors at compile time. A language can be low- or high-level, but still enforce type-checking to various degrees. Static typing can help catch a whole class of errors before running the program.

                                          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