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. You can always tell the guys who came from the world of C / C++

You can always tell the guys who came from the world of C / C++

Scheduled Pinned Locked Moved The Lounge
csharpc++javascriptcsscom
41 Posts 25 Posters 2 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.
  • C Christian Graus

    I personally think it's a huge gotcha to think that .NET manages memory. It really doesn't, not very well.

    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

    A Offline
    A Offline
    Andy Brummer
    wrote on last edited by
    #27

    Compared to what? Back when I did a lot of C++ I was skeptical about how well picking one general purpose memory allocation scheme could work. With C++ I could control allocation for every part of my app even if the default one was ridiculously slow. Almost 10 years later and I've only had to worry about memory allocation in C# for one app, and that was only when there were millions of objects taking up gigs of memory. Even then, I just switched from classes to arrays of structs and I got excellent performance.

    Curvature of the Mind now with 3D

    1 Reply Last reply
    0
    • C Christopher Duncan

      They're the ones who actually check for null before using an object. I've found that it's comparatively rare in the C# world to see this test as a standard coding practice. Who knows, maybe tripping over a null value is less evil in today's condom protected world of managed software development (and I'm talking about the programmers, not the code, being "managed") than it used to be. Try a stunt like that in the world of C and you might trash memory that you later regret. Loss of data, screw up the OS, spontaneously reboot the machine... shucks, there's just all sorts of havoc that a wild pointer can do in C. And don't even get me started on wild programmers. Maybe the memory management in .net makes it less hazardous to access a null object, but it sure as hell isn't any less embarrassing. I mean, it's bad enough if you do decent error handling / reporting and give the user a message that says, "Damn. That was embarrassing. Care to try again now that we're sober?" But to get a YSOD or system popup message saying something arcane about a null value being encountered is just amateur hour. Nowhere is this more prevalent than the world of client side javascript, something I've successfully avoided for years. Now that I'm digging into it a bit, it's just amazing to me the degree of half assed techniques, cryptic, one letter names, untested variables and other such grade school level sloppiness in what should be professionally written code. Write code like that in any other part of the system in a decent development shop and you may have a brief and unexpected encounter with the Exit sign. But as long as you're only writing javascript, I guess it's okay. I mean, it's not like a customer would see an embarrassing error message pop up out of their browser and make your company look stupid or anything. Actually, though it sounds like I'm cranky and having a bad day, at the moment I'm nose deep in a personal project and having quite the good time. But sometimes you just wanna whack someone upside the head with a whiteboard eraser, you know? :-D

      Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

      A Offline
      A Offline
      Andy Brummer
      wrote on last edited by
      #28

      I usually start out by beating sense into the dumbass that thought it was ok to return null as a common operation.

      Christopher Duncan wrote:

      But as long as you're only writing javascript, I guess it's okay.

      Actually if you are writing if (a == null) it probably isn't doing what you think it is. if (a === null) will do what you are probably thinking of, but it is probably not what you want. This has some of the pitfalls http://www.mapbender.org/JavaScript_pitfalls:_null,_false,_undefined,_NaN[^] I highly recommend: Javascript the good parts.

      Curvature of the Mind now with 3D

      R 1 Reply Last reply
      0
      • C Christopher Duncan

        They're the ones who actually check for null before using an object. I've found that it's comparatively rare in the C# world to see this test as a standard coding practice. Who knows, maybe tripping over a null value is less evil in today's condom protected world of managed software development (and I'm talking about the programmers, not the code, being "managed") than it used to be. Try a stunt like that in the world of C and you might trash memory that you later regret. Loss of data, screw up the OS, spontaneously reboot the machine... shucks, there's just all sorts of havoc that a wild pointer can do in C. And don't even get me started on wild programmers. Maybe the memory management in .net makes it less hazardous to access a null object, but it sure as hell isn't any less embarrassing. I mean, it's bad enough if you do decent error handling / reporting and give the user a message that says, "Damn. That was embarrassing. Care to try again now that we're sober?" But to get a YSOD or system popup message saying something arcane about a null value being encountered is just amateur hour. Nowhere is this more prevalent than the world of client side javascript, something I've successfully avoided for years. Now that I'm digging into it a bit, it's just amazing to me the degree of half assed techniques, cryptic, one letter names, untested variables and other such grade school level sloppiness in what should be professionally written code. Write code like that in any other part of the system in a decent development shop and you may have a brief and unexpected encounter with the Exit sign. But as long as you're only writing javascript, I guess it's okay. I mean, it's not like a customer would see an embarrassing error message pop up out of their browser and make your company look stupid or anything. Actually, though it sounds like I'm cranky and having a bad day, at the moment I'm nose deep in a personal project and having quite the good time. But sometimes you just wanna whack someone upside the head with a whiteboard eraser, you know? :-D

        Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

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

        Christopher Duncan wrote:

        Now that I'm digging into it a bit, it's just amazing to me the degree of half assed techniques, cryptic, one letter names, untested variables and other such grade school level sloppiness in what should be professionally written code.

        For the one-letter variable names, you could give them benefit of the doubt and assume they are running code through a minimizer to reduce download size. Realistically, that's probably not true though.

        1 Reply Last reply
        0
        • A Andy Brummer

          I usually start out by beating sense into the dumbass that thought it was ok to return null as a common operation.

          Christopher Duncan wrote:

          But as long as you're only writing javascript, I guess it's okay.

          Actually if you are writing if (a == null) it probably isn't doing what you think it is. if (a === null) will do what you are probably thinking of, but it is probably not what you want. This has some of the pitfalls http://www.mapbender.org/JavaScript_pitfalls:_null,_false,_undefined,_NaN[^] I highly recommend: Javascript the good parts.

          Curvature of the Mind now with 3D

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

          Andy Brummer wrote:

          I highly recommend: Javascript the good parts

          I think this should be required reading for any JS developer.

          A 1 Reply Last reply
          0
          • C Christopher Duncan

            They're the ones who actually check for null before using an object. I've found that it's comparatively rare in the C# world to see this test as a standard coding practice. Who knows, maybe tripping over a null value is less evil in today's condom protected world of managed software development (and I'm talking about the programmers, not the code, being "managed") than it used to be. Try a stunt like that in the world of C and you might trash memory that you later regret. Loss of data, screw up the OS, spontaneously reboot the machine... shucks, there's just all sorts of havoc that a wild pointer can do in C. And don't even get me started on wild programmers. Maybe the memory management in .net makes it less hazardous to access a null object, but it sure as hell isn't any less embarrassing. I mean, it's bad enough if you do decent error handling / reporting and give the user a message that says, "Damn. That was embarrassing. Care to try again now that we're sober?" But to get a YSOD or system popup message saying something arcane about a null value being encountered is just amateur hour. Nowhere is this more prevalent than the world of client side javascript, something I've successfully avoided for years. Now that I'm digging into it a bit, it's just amazing to me the degree of half assed techniques, cryptic, one letter names, untested variables and other such grade school level sloppiness in what should be professionally written code. Write code like that in any other part of the system in a decent development shop and you may have a brief and unexpected encounter with the Exit sign. But as long as you're only writing javascript, I guess it's okay. I mean, it's not like a customer would see an embarrassing error message pop up out of their browser and make your company look stupid or anything. Actually, though it sounds like I'm cranky and having a bad day, at the moment I'm nose deep in a personal project and having quite the good time. But sometimes you just wanna whack someone upside the head with a whiteboard eraser, you know? :-D

            Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

            S Offline
            S Offline
            Super Lloyd
            wrote on last edited by
            #31

            One reason to not test null value... what's the difference, really, between..

            void Foo(object mightbeNull)
            {
            if(mightBeNull == null)
            throw new NullArgumentException()
            // ...
            }

            or

            void Foo(object mightbeNull)
            {
            mightBeNull.Snafu()
            // ...
            }

            I test for null only if I can handle it. Or if there is multiple argument, so that I can throw an argument exception with a value added exception message! ;P

            A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

            1 Reply Last reply
            0
            • S S Senthil Kumar

              Christian Graus wrote:

              it's a huge gotcha to think that .NET manages memory. It really doesn't, not very well.

              Care to elaborate?

              Regards Senthil _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

              E Offline
              E Offline
              Erik Rude
              wrote on last edited by
              #32

              .Net collections and the large object heap[^]

              1 Reply Last reply
              0
              • C Christopher Duncan

                Michael J. Eber wrote:

                Of course if they slap try catches around it and ignore the exception..... :OMG:

                :omg: You mean that's legal? I thought they put you in jail for that sort of thing.

                Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

                D Offline
                D Offline
                dave dolan
                wrote on last edited by
                #33

                I think if you get a null, when you're not expecting one, most of the time you WANT to throw an exception anyway. I mean, what are you going to do anyway? Suppress the error and hang out? Personally, I usually check for them and try to throw 'informative' exceptions about what exactly was null, but beyond debugging this is really moot. An unexpected null means something is wrong, and you should probably let it blow up in grand style anyway.

                1 Reply Last reply
                0
                • C Christopher Duncan

                  Michael J. Eber wrote:

                  Of course if they slap try catches around it and ignore the exception..... :OMG:

                  :omg: You mean that's legal? I thought they put you in jail for that sort of thing.

                  Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

                  D Offline
                  D Offline
                  djdanlib 0
                  wrote on last edited by
                  #34

                  Sometimes, they probably should. Eating an exception ought to be an offense :) Then again, I've been guilty of eating an exception or two in my day... for example, in a particularly offensive project... when setting up logging to a file AND the event log AND email, it was okay if the email object couldn't be created sometimes as long as setting up the event log worked. "But officer, I swear, it's okay to eat just this one!"

                  1 Reply Last reply
                  0
                  • M Mycroft Holmes

                    Two things come to mind (I have never had the displeasure of working with c++)

                    Christopher Duncan wrote:

                    Try a stunt like that in the world of C and you might trash memory that you later regret. Loss of data, screw up the OS, spontaneously reboot the machine

                    I believe the consequences are not as dramatic in managed code.

                    Christopher Duncan wrote:

                    half assed techniques, cryptic, one letter names, untested variables and other such grade school level sloppiness

                    Does the corrollery to that indicate that people that use single character variables are steeped in javascript? It has always made me wonder when working through an example or a snaffled snippet when I come across a single character variable whether the coder was just too lazy to type more than 1 character.

                    Never underestimate the power of human stupidity RAH

                    D Offline
                    D Offline
                    djdanlib 0
                    wrote on last edited by
                    #35

                    I remember when BASIC (as in the old pre-GUI ones like BASIC/A, GWBASIC, etc) was the prime culprit for people who learned to use single-character variable names. Is Javascript the new BASIC? :~

                    1 Reply Last reply
                    0
                    • R Rob Grainger

                      Andy Brummer wrote:

                      I highly recommend: Javascript the good parts

                      I think this should be required reading for any JS developer.

                      A Offline
                      A Offline
                      Andy Brummer
                      wrote on last edited by
                      #36

                      Definitely, it's one of the things I ask about when interviewing candidates.

                      Curvature of the Mind now with 3D

                      1 Reply Last reply
                      0
                      • C Christopher Duncan

                        They're the ones who actually check for null before using an object. I've found that it's comparatively rare in the C# world to see this test as a standard coding practice. Who knows, maybe tripping over a null value is less evil in today's condom protected world of managed software development (and I'm talking about the programmers, not the code, being "managed") than it used to be. Try a stunt like that in the world of C and you might trash memory that you later regret. Loss of data, screw up the OS, spontaneously reboot the machine... shucks, there's just all sorts of havoc that a wild pointer can do in C. And don't even get me started on wild programmers. Maybe the memory management in .net makes it less hazardous to access a null object, but it sure as hell isn't any less embarrassing. I mean, it's bad enough if you do decent error handling / reporting and give the user a message that says, "Damn. That was embarrassing. Care to try again now that we're sober?" But to get a YSOD or system popup message saying something arcane about a null value being encountered is just amateur hour. Nowhere is this more prevalent than the world of client side javascript, something I've successfully avoided for years. Now that I'm digging into it a bit, it's just amazing to me the degree of half assed techniques, cryptic, one letter names, untested variables and other such grade school level sloppiness in what should be professionally written code. Write code like that in any other part of the system in a decent development shop and you may have a brief and unexpected encounter with the Exit sign. But as long as you're only writing javascript, I guess it's okay. I mean, it's not like a customer would see an embarrassing error message pop up out of their browser and make your company look stupid or anything. Actually, though it sounds like I'm cranky and having a bad day, at the moment I'm nose deep in a personal project and having quite the good time. But sometimes you just wanna whack someone upside the head with a whiteboard eraser, you know? :-D

                        Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

                        S Offline
                        S Offline
                        Stefan_Lang
                        wrote on last edited by
                        #37

                        I've found that NULL pointers are much less of a problem than uninitialized ones. The former gives you a nice NULL-Pointer exception that you can pinpoint and fix rather easily, the latter gives you a very hard to replicate and fix seg fault, but only in release mode, because compiler vendors for some obscure reason think it's a good idea to zero out all memory on debug builds, rather than make sure it does exactly what the release build does... :mad:

                        1 Reply Last reply
                        0
                        • C Christopher Duncan

                          They're the ones who actually check for null before using an object. I've found that it's comparatively rare in the C# world to see this test as a standard coding practice. Who knows, maybe tripping over a null value is less evil in today's condom protected world of managed software development (and I'm talking about the programmers, not the code, being "managed") than it used to be. Try a stunt like that in the world of C and you might trash memory that you later regret. Loss of data, screw up the OS, spontaneously reboot the machine... shucks, there's just all sorts of havoc that a wild pointer can do in C. And don't even get me started on wild programmers. Maybe the memory management in .net makes it less hazardous to access a null object, but it sure as hell isn't any less embarrassing. I mean, it's bad enough if you do decent error handling / reporting and give the user a message that says, "Damn. That was embarrassing. Care to try again now that we're sober?" But to get a YSOD or system popup message saying something arcane about a null value being encountered is just amateur hour. Nowhere is this more prevalent than the world of client side javascript, something I've successfully avoided for years. Now that I'm digging into it a bit, it's just amazing to me the degree of half assed techniques, cryptic, one letter names, untested variables and other such grade school level sloppiness in what should be professionally written code. Write code like that in any other part of the system in a decent development shop and you may have a brief and unexpected encounter with the Exit sign. But as long as you're only writing javascript, I guess it's okay. I mean, it's not like a customer would see an embarrassing error message pop up out of their browser and make your company look stupid or anything. Actually, though it sounds like I'm cranky and having a bad day, at the moment I'm nose deep in a personal project and having quite the good time. But sometimes you just wanna whack someone upside the head with a whiteboard eraser, you know? :-D

                          Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

                          P Offline
                          P Offline
                          patbob
                          wrote on last edited by
                          #38

                          "They're the ones who actually check for null before using an object." I'll give you a clue.. there's a reason we write code that way. In 10-20 years, you'll understand, and probably be doing it yourself.

                          patbob

                          1 Reply Last reply
                          0
                          • C Christopher Duncan

                            They're the ones who actually check for null before using an object. I've found that it's comparatively rare in the C# world to see this test as a standard coding practice. Who knows, maybe tripping over a null value is less evil in today's condom protected world of managed software development (and I'm talking about the programmers, not the code, being "managed") than it used to be. Try a stunt like that in the world of C and you might trash memory that you later regret. Loss of data, screw up the OS, spontaneously reboot the machine... shucks, there's just all sorts of havoc that a wild pointer can do in C. And don't even get me started on wild programmers. Maybe the memory management in .net makes it less hazardous to access a null object, but it sure as hell isn't any less embarrassing. I mean, it's bad enough if you do decent error handling / reporting and give the user a message that says, "Damn. That was embarrassing. Care to try again now that we're sober?" But to get a YSOD or system popup message saying something arcane about a null value being encountered is just amateur hour. Nowhere is this more prevalent than the world of client side javascript, something I've successfully avoided for years. Now that I'm digging into it a bit, it's just amazing to me the degree of half assed techniques, cryptic, one letter names, untested variables and other such grade school level sloppiness in what should be professionally written code. Write code like that in any other part of the system in a decent development shop and you may have a brief and unexpected encounter with the Exit sign. But as long as you're only writing javascript, I guess it's okay. I mean, it's not like a customer would see an embarrassing error message pop up out of their browser and make your company look stupid or anything. Actually, though it sounds like I'm cranky and having a bad day, at the moment I'm nose deep in a personal project and having quite the good time. But sometimes you just wanna whack someone upside the head with a whiteboard eraser, you know? :-D

                            Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

                            R Offline
                            R Offline
                            Rick Shaub
                            wrote on last edited by
                            #39

                            I prefer managed code because an unitialized reference is always null. In C or C++, an unitialized pointer could be any value. Also, there's a big advantage to letting the exception be thrown if you don't have a way to handle a null reference. If it's your responsibility to initialize the reference, then you'll find out your mistake as soon as you test the code.

                            1 Reply Last reply
                            0
                            • C Christopher Duncan

                              Michael J. Eber wrote:

                              Of course if they slap try catches around it and ignore the exception..... :OMG:

                              :omg: You mean that's legal? I thought they put you in jail for that sort of thing.

                              Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

                              P Offline
                              P Offline
                              PHLIPH
                              wrote on last edited by
                              #40

                              I thought if you programmed in C# you alrteady were in jail. :)

                              1 Reply Last reply
                              0
                              • C Christopher Duncan

                                They're the ones who actually check for null before using an object. I've found that it's comparatively rare in the C# world to see this test as a standard coding practice. Who knows, maybe tripping over a null value is less evil in today's condom protected world of managed software development (and I'm talking about the programmers, not the code, being "managed") than it used to be. Try a stunt like that in the world of C and you might trash memory that you later regret. Loss of data, screw up the OS, spontaneously reboot the machine... shucks, there's just all sorts of havoc that a wild pointer can do in C. And don't even get me started on wild programmers. Maybe the memory management in .net makes it less hazardous to access a null object, but it sure as hell isn't any less embarrassing. I mean, it's bad enough if you do decent error handling / reporting and give the user a message that says, "Damn. That was embarrassing. Care to try again now that we're sober?" But to get a YSOD or system popup message saying something arcane about a null value being encountered is just amateur hour. Nowhere is this more prevalent than the world of client side javascript, something I've successfully avoided for years. Now that I'm digging into it a bit, it's just amazing to me the degree of half assed techniques, cryptic, one letter names, untested variables and other such grade school level sloppiness in what should be professionally written code. Write code like that in any other part of the system in a decent development shop and you may have a brief and unexpected encounter with the Exit sign. But as long as you're only writing javascript, I guess it's okay. I mean, it's not like a customer would see an embarrassing error message pop up out of their browser and make your company look stupid or anything. Actually, though it sounds like I'm cranky and having a bad day, at the moment I'm nose deep in a personal project and having quite the good time. But sometimes you just wanna whack someone upside the head with a whiteboard eraser, you know? :-D

                                Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011

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

                                I feel your pain. One of the problems I see people running the most (and myself when using other people's code) is the NullReferenceException. Although I have some C/C++ background, it's not one with lots of experience, but I don know that checking for null is a very good practice. It surprises me that some people try to argue against checking for null saying: "But it will never be null! You don't need to check that!", and often these people don't realize all possible ways a variable can become null or never instantiated. And the same people complain over and over because they don't know why such an exception is being thrown :doh: Good thing I don't have a JS background, I'd hate to have created nasty habits like the ones possible in JS.

                                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