Skip to content

The Weird and The Wonderful

It was the best of code, it was the worst of code. Coding Horrors, Worst Practices, and flashes of brilliance

This category can be followed from the open social web via the handle the-weird-and-the-wonderful@forum.codeproject.com

1.8k Topics 20.7k Posts
  • What would he do if it were floats?

    help question
    5
    0 Votes
    5 Posts
    1 Views
    T
    an old textbook way to improve your efficiency when your boss is using TLOC :) using float will make him much more efficient. :-D
  • There are errors and errors...

    help
    7
    0 Votes
    7 Posts
    1 Views
    R
    s_mon wrote: All errors are equal, but some errors are more equal than others... Seems I've heard that before. Maybe at that farm I used to work at? :cool:
  • Not a coding horror as such, but...

    4
    0 Votes
    4 Posts
    2 Views
    B
    No, that's not a horror. That is someone giving stating what really needs to happen in order for the project to work. ;) :-D Just because the code works, it doesn't mean that it is good code.
  • It's the thought that counts

    13
    0 Votes
    13 Posts
    1 Views
    B
    Yes, sometimes is a good reason to use an empty catch. It still only acceptable if it is well documented as to why it was done so that some poor programmer a few years down the road doesn't have to waste time trying to figure out how the exception should really be handled. Just because the code works, it doesn't mean that it is good code.
  • MSDN example [modified] (oops, my bad!)

    php visual-studio linq com beta-testing
    20
    0 Votes
    20 Posts
    1 Views
    S
    For that approach to work, wouldn't you have to add 306 days to both the birthdate and the present time before using the Year and DayOfYear properties? The notion that someone born on 2/28/2000 would have had to wait 366 days to be "one year old", while someone born on 3/1/2000 would only have to wait 365 days, is somewhat artificial but it is certainly well-established. #2/28/2000#.DayOfYear == 59 #2/28/2001#.DayOfYear == 59 #3/1/2000#.DayOfYear == 61 #3/1/2001#.DayOfYear == 60 #2/28/2000#.AddDays(306).DayOfYear == 365 #2/28/2001#.AddDays(306).DayOfYear == 365 #3/1/2000#.AddDays(306).DayOfYear == 1 #3/1/2001#.AddDays(306).DayOfYear == 1 Of course, adding 306 days has an ugliness all its own. My own preference would probably be to simply format the thing as MMDDHHMMSS, do a string compare, and adjust the year appropriately, but another option would be to format as YYYYMMDDHHMMSS, convert to a long or double, subtract, and divide by 10,000,000,000.
  • How to increment a variable [modified]

    tutorial
    22
    0 Votes
    22 Posts
    5 Views
    OriginalGriffO
    I don't like to think what would happen to "i = i++" if "i" is truely volatile. Would the post increment be actioned on an interrupt modified value? Now that would be a good bug to find!
  • Guess His Experience Level

    30
    0 Votes
    30 Posts
    4 Views
    OriginalGriffO
    I sort of agree, but rather than: MenuItemNode child = tvMenu.SelectedNode as MenuItemNode; if (child == null) return; MenuItemNode parent = child.Parent as MenuItemNode; if (parent == null) return; MenuItemNode swap = child.PrevNode as MenuItemNode; if (swap == null) return; //Code Here I would prefer: MenuItemNode child = tvMenu.SelectedNode as MenuItemNode; if (child == null) { return; } MenuItemNode parent = child.Parent as MenuItemNode; if (parent == null) { return; } MenuItemNode swap = child.PrevNode as MenuItemNode; if (swap == null) { return; } //Code Here Just to remind me if I add a statement before the return.
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • The Horror... [modified]

    learning csharp c++ oop architecture
    12
    0 Votes
    12 Posts
    2 Views
    J
    Reminds me of a database course I had to take once. The teacher insisted that each table had to be placed in a separate database. She gave us a simple accounting example that ended up with 10 databases. Account database, Client database, Invoice database, InvoiceItem database etc. Attempts to show how all the tables could be housed in one database were marked wrong & returned for reworking. She even refused to accept it was bad purely on performance grounds, which we could easily demonstrate (it was glacially slow)!
  • Good if paid by number of lines!

    code-review
    11
    0 Votes
    11 Posts
    1 Views
    D
    Rauhotz wrote: I always do ... switch (x) { case 0 : y = 0; break; case 1 : y = 1; break; case 2 : y = 2; break; ... ... } At last you forgot to write default case. default: y = x; Do not trust a computer... Always check what computer is doing regards, Divyang Mithaiwala Software Engineer
  • Since you all like his code so well.

    3
    0 Votes
    3 Posts
    2 Views
    F
    I think I need a lobotomy... strCH = strData.Substring(intLoop, 1) this is to extract the char of strData in each iteration, rigth? Argh! X|
  • Initializing an array of structures

    data-structures
    23
    0 Votes
    23 Posts
    1 Views
    P
    That would go // Set field to 1: anArray [ // index 0 ]. // field name field1 // value 1; Don't attribute to stupidity what can be equally well explained by buerocracy. My latest article | Linkify!| FoldWithUs! | sighist
  • The "Yeah baby" increment way...

    database
    11
    0 Votes
    11 Posts
    1 Views
    A
    Collin Jasnoch wrote: for tracking Yes its a product tracking software indeed.
  • VB Select Case statement incarnation of C# if (true = [condition])

    csharp help
    6
    0 Votes
    6 Posts
    2 Views
    M
    Think of it as If ElseIf statements with uniform indentation of the conditionals. Of course in this case it could be reduced to: If [failure condition 1] Then _ Throw New Exception("Condition 1 failed.") If [failure condition 2] Then _ Throw New Exception("Condition 2 failed.") 'etc... 'Success! But in defence of Select Case True, it used to be the easiest way to get short-circuiting in VB6. Could this code have been around long enough to have been converted? Regards, Mark Hurd, B.Sc.(Ma.) (Hons.)
  • Just amusing...

    7
    0 Votes
    7 Posts
    0 Views
    D
    In this case, it was for setting the position for modifying a string, so it could certain make sense for clarifying exactly where the update is inserted/replaced. But still, the "magic numbers" were there, not variables.
  • FTW?

    csharp ruby collaboration question
    10
    0 Votes
    10 Posts
    5 Views
    B
    Clearly, that would be _way_ too easy! ;) Just because the code works, it doesn't mean that it is good code. modified on Friday, March 20, 2009 4:41 PM
  • Nice usage of foreach

    19
    0 Votes
    19 Posts
    0 Views
    P
    Ummm... yeah, so? :confused:
  • If File exist

    com sysadmin help question workspace
    7
    0 Votes
    7 Posts
    5 Views
    Y
    dojohansen wrote: but a lot of people still attempt to keep a full version history in the latest version of the code - never removing anything, but commenting it out and usually adding their initials and the date and time, as if this would actually help anyone later on. In my view it just distracts sometime, only on certain conditions, I leave old code behind commented out. Such as if I am making major logic change and what is change is not big piece of code I leave it for historical comparison. Beyond that I don't get it what the code needs to be polluted with old code. :| Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
  • WTF Name Field [modified*2]

    database csharp design tutorial
    6
    0 Votes
    6 Posts
    0 Views
    Z
    I can't resist. "Standards are slipping!"
  • Zero-choice alternative

    csharp
    24
    0 Votes
    24 Posts
    3 Views
    S
    hey, if would b gr8 if u could explain wat u mean by variable being volatile This is not a place for programming questions, but in this context, a 'volatile' variable is one that is marked with the 'volatile' keyword. If a variable is declared volatile, expressions involving that variable may not be optimized. If 'foo' were not volatile, the code (assume foo, bar1, bar2, and bar3 are of type int): foo = bar1; bar2 = foo*25; bar3 = foo*25; foo = 8; could be safely replaced with: bar3 = bar2 = bar1 * 25; foo = 8; and indeed some compilers would make such a replacement. If 'foo' were volatile, however, all four of the original statements would have to be performed as-is, in sequence.