Questionable sanity



  • I encountered some code today that makes me question not the competence of my peers but rather their sanity. The logic here is, if a row in a grid needs it, to set a "RecordChanged" boolean to true, so that later only changed records are processed. The variable rowIndex is the index of the row that has changed, and was set earlier in the function.

    For Each Column As Column In View.Grid.Columns

       Dim Cell As Cell = View.Grid.Cells(rowIndex, 2)

       If Column.Name = "RecordChanged" AndAlso Convert.ToString(Column.GetType).ToUpper = "CHECKBOX" Then

          Cell.Value = True

       End If

    Next

    1. Yes, it was originally double spaced. Double spacing is rather common in this code base, and I have no idea why.
    2. Checking type by casting the type to a string and using string comparison (also very common in this code base).
    3. It's looping through the columns to, supposedly, check their names, but it's ignoring the column when it actually sets the cell's value.
    4. It doesn't actually find the RecordChanged column, but rather confirms that it exists. If it does exist, but it's in column 3, then shit will hit the fan, since it'll set the wrong column to true.
    5. There's absolutely no reason for this check since it's guaranteed that RecordChanged will always be in column 2 of the grid.
    6. And finally, The Real WTF is that the system is designed in such that the only way to tell if a record has changed is by examining a column that exists only in the view and not in the underlying data structure. There's no way to query the DataTable underneath with a .select("RecordChanged = 1") call.


  •  No, TRWTF is VB...   ;-)

     (sorry, couldn't resist)



  • Looks like a case of programming by coincidence. The developer hacked on it every which way he thought it made sense,and when it finally worked, he left it alone. Code reviews can eliminate this kind of sloppy programming.

    However, your boss:

    1. probably wrote this code.
    2. may think this is the way you're supposed to program.
    3. may think you're trying to undermine him if you bring this up.

    Your best course of action is to lead by example, so start a programmer's lunch book club and discuss the Prgamatic Programmer, Code Complete, and other good titles to elivate the abilities of your shop. You can even make this one of your "yearly goals" so you can please management. Watch out though, they may want to put you in charge.

    Either that or look for a better shop.

    On the plus side, it doesn't look like they're using Hungarian Notation, so count your blessings!



  • @elamberton said:

    However, your boss:
    1. probably wrote this code.
    2. may think this is the way you're supposed to program.
    3. may think you're trying to undermine him if you bring this up.
    1. My boss doesn't write code
    2. Definitely doesn't think this
    3. Will not think this

    I don't know why you're making shit like this up, though I agree we really ought to be doing code reviews. Unfortunately we don't do that in our department, and so stuff like this can live in production for months before something goes wrote and causes me (the bug guy) to notice it.

    Regarding the book club idea, I think many here are beyond hope.



  • @Welbog said:

    I don't know why you're making shit like this up
     

    I'm just commenting based off of my personal experience in projects where I've seen this kind of code. And yes, I've been in situations where the boss: wrote this kind of code, didn't see any problems with it, and thought I was trying to undermine him when I fixed his poorly written code.



  • @TheRider said:

     No, TRWTF is VB...   ;-)

     (sorry, couldn't resist)

    I still wonder why the f(ailure) are people still using VB. Even Microsoft wants devs to migrate to their C# "I'm not Java! I swear!" prodigy child. Sticking to COBOL is understandable in the mainframe business, but VB can easily be replaced by C#, thanks to the .NET platform. :)


  • @danixdefcon5 said:

    I still wonder why the f(ailure) are people still using VB.
    Probably because VB and C# are the same thing so there's no reason to choose one over the other and anyone who doesn't understand this doesn't matter.



  • @Welbog said:

  • Yes, it was originally double spaced. Double spacing is rather common in this code base, and I have no idea why.
  •  

    Let me guess... They were coding in Notepad until someone complained about not using a "real IDE", so they switched to Word?



  • @Welbog said:

    @danixdefcon5 said:

    I still wonder why the f(ailure) are people still using VB.
    Probably because VB and C# are the same thing so there's no reason to choose one over the other and anyone who doesn't understand this doesn't matter.

     

    having used both.....I disagree.



  • @elamberton said:

    Looks like a case of programming by coincidence. The developer hacked on it every which way he thought it made sense,and when it finally worked, he left it alone. Code reviews can eliminate this kind of sloppy programming.

    However, your boss:

    1. probably wrote this code.
    2. may think this is the way you're supposed to program.
    3. may think you're trying to undermine him if you bring this up.

    Yeah, I worked for a guy like that.

    He thought anyone with a copy of "Learn PHP in 24 hours" was a qualified programmer.  He also gave up on hiring because he couldn't find any programmers in california willing to work for $30k a year (no benefits) -- this was after hiring 4 guys in the span of half a year who he terminated within a month after they displayed complete incompetence.  He did manage to find one competent guy willing to work at that rate, but refused to give him a raise, so he left for a job that payed twice as well.

    I stuck around because I needed to rack up some experience (it's easy to get a job if you have professional experience, or a degree.  I had neither, going into it), and because he actually paid me an almost-decent salary.

    I eventually got sick of working in that environment, so, in hopes of replacing me, he gave one of the customer service reps, who had no programming experience, a book on PHP, and told him to start reading.

     

    Not sure how that worked out for him.



  • @Welbog said:

    @danixdefcon5 said:

    I still wonder why the f(ailure) are people still using VB.
    Probably because VB and C# are the same thing so there's no reason to choose one over the other and anyone who doesn't understand this doesn't matter.

    I disagree, C# is more like a Java ripoff, while VB has one of the worst syntax I've ever seen in my life. About the only thing they have in common is that they run under the same framework. Which just strengthens my argument: WTF would anyone keep using that thing when C# is good enough for any new app?


  • Why the

    <font size=+1>

        vertical

        whitespace</pre></font>
    

    ?

    That's easy.

    <font size=+1>

        vertical

        whitespace</pre></font>
    

    is important,

    and all good programmers use it.

    Better

    programmers

    would, of course,

    use more.



    In other news, I've been there with the boss who thinks all corrections to his code are attempts to undermine him - even though he has since disclaimed any actual coding ability, so hires other people to do it. Not fun. On the bright side, the one time I had to deal with this, I fairly quickly recognized the fact that he had no sense of revision control, and really did keep hands off except for code reviews (which he did only randomly), and used this to my advantage: When I found a problem with his code, I simply wrote up some unit tests for it, re-wrote it, verified all the unit tests that previously worked still worked, and installed it without notice. The shit didn't hit the fan until one of my coworkers caught on to my scheme, and simply rewrote (fortunately, the last) some code and released it (no testing, other than the one path that he had a problem with). And, also fortunately, I know how to write in multiple coding styles (so all the code he'd never seen looked like that of people who'd left the group. He still strongly suspected me, as none of the new code had turned up bugs, and I was the only proponent of automated tests and such. But since there was no evidence any automated tests ever existed (heh) for that code, he had nothing to go on.) Most fortunate, of course, is the fact that I've been out of there for 10 years (as of tomorrow). WOOT!

    My question is why do people still trust Microsoft to not change the language mechanics significantly without real notice, thus screwing the people who've chosen to write code in Microsoftian languages? Not that I've been tracking Microsoft's propensity to do this for the last 10 years (as of tomorrow). WOOT!



  • @danixdefcon5 said:

    I disagree, C# is more like a Java ripoff...

    [citation needed] 


  • :belt_onion:

    @danixdefcon5 said:

    I disagree, C# is more like a Java ripoff, while VB has one of the worst syntax I've ever seen in my life. About the only thing they have in common is that they run under the same framework. Which just strengthens my argument: WTF would anyone keep using that thing when C# is good enough for any new app?

     

    You MUST be joking. Except for some differences in syntax, VB.NET and C# are quite similar. And I do know what I'm talking about having extensively used (in chronological order) C++, VB6, VB.NET and C#.

    http://www.codinghorror.com/blog/archives/000128.html



  • @eclipsed4utoo said:

    having used both.....I disagree.
     

    Having used both and actually knowing what I am doing in both.... I disagree with you.



  • @danixdefcon5 said:

    I disagree, C# is more like a Java ripoff, while VB has one of the worst syntax I've ever seen in my life. About the only thing they have in common is that they run under the same framework. Which just strengthens my argument: WTF would anyone keep using that thing when C# is good enough for any new app?
     

    Seriously, you are an idiot.

    Why do you even bother to keep opening your mouth?



  • @morbiuswilters said:

    @danixdefcon5 said:

    I disagree, C# is more like a Java ripoff...

    [citation needed] 

    That would be a Microsoft guy from Spain back in 2001, who did a conference at CIMAT, Guanajuato, Mexico. I didn't just jump into conclusions, he gave us the overview on the whole .NET platform, and that new-fangled thing called XML. The comparison even went down to some specific classnames and methods, where the only "difference" was that the first letter was uppercase/lowercase in each language. In fact, the original MS push looked like they wanted to kill VB off, but that old policy of "everything's backwards compatible" made them stick VB in there.

    Also, the C# language came right after the Microsoft J++ screwup, C# being basically a breakaway "Project Cool".

    Even the official MS documentation states that C# is "C++ evolved", though most of its "improvements" are basically Java's "improvements". (Except for transparent getters/setters, and some other quirks.) In any case, C# is more related to C++ / Java syntax than VB. Or will you argue that these two sentences are equal?

    Dim CrapVariable As SomeClass

    SomeClass crapVariable;

    I have refused to use VB since ancient times, however I admit that C# is actually a decent language even if I don't do .NET stuff. VB doing .NET stuff is kind of like hacking COBOL into doing OO or anything you'd expect from Java/C#/whatever.



  • @bjolling said:

    You MUST be joking. Except for some differences in syntax, VB.NET and C# are quite similar. And I do know what I'm talking about having extensively used (in chronological order) C++, VB6, VB.NET and C#.
    http://www.codinghorror.com/blog/archives/000128.html

    Ok, they are similar because the platform required doing some changes to VB. So VB6 code looks ugly, while VB.NET code might be matched to C#. But it still uses 'EndIf', 'End', and similar block-delimiters. C# uses the {} delimiters. Using tons of words as block delimiters is something I think about when reading COBOL code, not modern languages.

    That codinghorror link actually shows different point of views in the comments section. Basically it all boils down on the COBOL school of thinking, and those who follow "the C way". There's even a nice comment there explaining that in detail.


  • :belt_onion:

    @danixdefcon5 said:

    That would be a Microsoft guy from Spain back in 2001, who did a conference at CIMAT, Guanajuato, Mexico
     

    Ah, you're talking about .NET 1.0 or 1.1. In those versions there were indeed important differences between VB.NET and C#. But since the release of .NET 2.0, VB.NET has caught up with C#.

    @danixdefcon5 said:

    Or will you argue that these two sentences are equal?

    Dim CrapVariable As SomeClass

    SomeClass crapVariable;

    Yes, for me they are exactly the same. The only time when I really feel a difference in coding between the two is when working with event handlers. VB.NET code sometimes has to be structured in a different way than C# code. One language likes to use the BEGIN - END paradigma while the other one works with { }. Both do exactly the same thing: they define the scope. Any decent programmer can switch his mindset in a matter of minutes.

    It's not just the same framework, it's also the same run-time and the same intermediate language. Open a random .NET executable and try to tell in which language it was written.

     

     


  • Garbage Person

    @bjolling said:

    Open a random .NET executable and try to tell in which language it was written.
     

     

    Actually, I think there's some metadata that gives it away. 


  • :belt_onion:

    @Weng said:

    @bjolling said:

    Open a random .NET executable and try to tell in which language it was written.
     

     

    Actually, I think there's some metadata that gives it away. 

     

    Proving my point actually if people need the metadata to tell the difference ;-)



  • @bjolling said:

    @danixdefcon5 said:

    Or will you argue that these two sentences are equal?

    Dim CrapVariable As SomeClass

    SomeClass crapVariable;

    Yes, for me they are exactly the same. The only time when I really feel a difference in coding between the two is when working with event handlers. VB.NET code sometimes has to be structured in a different way than C# code. One language likes to use the BEGIN - END paradigma while the other one works with { }. Both do exactly the same thing: they define the scope. Any decent programmer can switch his mindset in a matter of minutes.

    It still looks ugly, though. Moreover, VB.NET still insults every variable.


  • @Welbog said:

    @danixdefcon5 said:

    I still wonder why the f(ailure) are people still using VB.
    Probably because VB and C# are the same thing so there's no reason to choose one over the other and anyone who doesn't understand this doesn't matter.

     

    How does one define an unsafe class in VB? 



  • @elamberton said:

    How does one define an unsafe class in VB?
    By defining the unsafe class in C# and calling it from VB...

    How do you handle low-level things like pointers in your high-level language? Answer: don't use a high-level language if you need to use pointers. Better answer: you probably don't need to be using pointers, and if you do then why aren't you using C in the first place?



  • @elamberton said:

    How does one define an unsafe class in VB? 
     

    Better question: Why would you declare an unsafe class in C# or anything else?



  • @MasterPlanSoftware said:

    @elamberton said:

    How does one define an unsafe class in VB? 
     

    Better question: Why would you declare an unsafe class in C# or anything else?

     

     

    because you want to do some real work?

     

    I kid i kid :D



  • @MasterPlanSoftware said:

    @elamberton said:

    How does one define an unsafe class in VB? 
     

    Better question: Why would you declare an unsafe class in C# or anything else?

     

    When you want all the benefits of Windows Forms but still need to do some "heavy lifting". Back in the .Net 1.1 days if you wanted to do any *serious* image manipulation it was pretty much a requirement. I don't know if GDI+ is any better now, but SetPixel used to be dog slow.


  • :belt_onion:

    @elamberton said:

    When you want all the benefits of Windows Forms but still need to do some "heavy lifting". Back in the .Net 1.1 days if you wanted to do any *serious* image manipulation it was pretty much a requirement. I don't know if GDI+ is any better now, but SetPixel used to be dog slow.
     

    I would use C++ with a managed interface (C++/CLI)  if I really needed to focus on performance in a .NET application. I wouldn't consider unsafe classes in C# for that. C++ is as unsafe as you can get! :-)

    http://en.wikipedia.org/wiki/C%2B%2B/CLI



  • @elamberton said:

    When you want all the benefits of Windows Forms but still need to do some "heavy lifting". Back in the .Net 1.1 days if you wanted to do any *serious* image manipulation it was pretty much a requirement. I don't know if GDI+ is any better now, but SetPixel used to be dog slow.
     

    It is pretty clear that you don't understand unsafe classes at all.



  • @MasterPlanSoftware said:

    @elamberton said:

    When you want all the benefits of Windows Forms but still need to do some "heavy lifting". Back in the .Net 1.1 days if you wanted to do any *serious* image manipulation it was pretty much a requirement. I don't know if GDI+ is any better now, but SetPixel used to be dog slow.
     

    It is pretty clear that you don't understand unsafe classes at all.

     

    From O'Reilly: "unsafe: A method modifier or statement that permits pointer arithmetic to be performed within a particular block."

    In order to perform certain tasks with the GDI liabrary in the Windows API, you need to use pointer arithmetic. One example of this is implementing your own Fill algorithm.

    I was merely trying to give a real life example of where one may have to use unsafe classes and pointer arithmetic.



  • @elamberton said:

    From O'Reilly: "unsafe: A method modifier or statement that permits pointer arithmetic to be performed within a particular block."

    In order to perform certain tasks with the GDI liabrary in the Windows API, you need to use pointer arithmetic. One example of this is implementing your own Fill algorithm.

    I was merely trying to give a real life example of where one may have to use unsafe classes and pointer arithmetic

     

    Once again:

    If you are doing this in C#, you are doing it wrong.



  • @elamberton said:

    When you want all the benefits of Windows Forms but still need to do some "heavy lifting". Back in the .Net 1.1 days if you wanted to do any *serious* image manipulation it was pretty much a requirement. I don't know if GDI+ is any better now, but SetPixel used to be dog slow.

     

    If you're using SetPixel in ANY language for image manipulation, I don't care if it's C/C++, C# or frigging QBASIC, you are doing something severely wrong. 

    Just create a byte array fill it with your image data, manipulate it all to your liking and then go display it to the user. Done. No unsafe classes or pointers necessary and performance wise should do just fine. Can also use a uint array if working with 32-bit color data and if you don't need byte access to the individual color channels.


Log in to reply