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
  • It was the 13th hour of the 13th day of the 13th month...

    23
    0 Votes
    23 Posts
    0 Views
    K
    Quote: It was the 13th hour of the 13th day of the 13th month... Nice subject! :-D
  • What a gem.

    ruby com
    37
    0 Votes
    37 Posts
    1 Views
    K
    Quote: ' This code will retrieve the BatteryLifePercent property and convert it to a percent. Really? Why would someone convert something to percent which is already in percent?
  • Gem code

    ruby asp-net
    6
    0 Votes
    6 Posts
    3 Views
    K
    And don't forget to declare both the field and the property as private. Otherwise other bad programmers might accidentally access them.
  • Gem... As time goes by..

    ruby
    35
    0 Votes
    35 Posts
    5 Views
    K
    But there is a fix for that issue... string ampm = GetTime("Blahblahblah", strTime); if (strTime = "24" && ampm = "PM") { ampm = "AM"; } See! It's easy. ;P
  • Bad filtering

    database algorithms json performance help
    5
    0 Votes
    5 Posts
    0 Views
    K
    Jtai wrote: Select field1,field2,field3 From table1 Where type="EDU" When I read the code, I thought it was a pity that Active wasn't in the DB so you could restrict the number of lines based on Active. Then I thought, don't even run the logic if Active isn't true. As I continued reading, I realized the real condition. Did you drop the Active check in the code along with modifying the select? If it's still a large # of rows being read, you might want to include your condition checks in the selection criteria. Also, hopefully, you are really running a sproc to get your data. Here's an example of using 4 condition checks with very different selection criteria. If two condition checks overlap then the data produced would overlap. The table had 5K rows in it, the selection had 39 rows in it. declare @tbl table (Cond int, sTotID int, stot1 int, stot2 int, stot3 int) insert into @tbl values (1,-1, 20, -1, 49), (2, 203148, -1, -1, -1), (3, -1, 15, 29, -1), (4, -1, 25, 32, -1) SELECT TOP 1000 Cond, TotID ,NumbRecs ,tot1 ,tot2 ,tot3 FROM dbo.ThreeNumberSum JOIN @tbl on (sTotID = -1 or sTotID = TotID) AND (stot1 = -1 OR stot1 = tot1) AND (stot2 = -1 OR stot2 = tot2) AND (stot3 = -1 OR stot3 = tot3) Your code could just check 1 value to match all the multiple conditions. Here is an extract of all the rows: Cond TotID NumbRecs tot1 tot2 tot3 1 202749 32 20 27 49 ... middle number 28-30 1 203149 208 20 31 49 1 203249 184 20 32 49 1 203349 128 20 33 49 1 203449 56 20 34 49 1 203549 8 20 35 49 1 203649 8 20 36 49 2 203148 424 20 31 48 3 152940 24 15 29 40 3 152941 40 15 29 41 3 152942 32 15 29 42 3 152943 48 15 29 43 3 152944 8 15 29 44 3 152945 8 15 29 45 4 253228 28956 25 32 28 4 253229 49698 25 32 29 ... last number 30-35 4 253236 595694 25 32 36 4 253237 529858 25 32 37 ... last number 38-48 4 253249 8 25 32 49
  • DAO Framework

    database business tools performance help
    25
    0 Votes
    25 Posts
    1 Views
    J
    I had to do stuff like that in the 90s when my company was playing musical chairs with SQL vendors. Our server side apps ended up being able to run seamlessly on SQL Server, Sybase and Oracle. That probably doesn't sound like a big deal now, but driver standardization wasn't so far along when NT 3.51 was king. Under the hood, the Microsoft code does similar tasks to what is suggested here...
  • Connectivity test

    com sysadmin question
    17
    0 Votes
    17 Posts
    0 Views
    D
    How do you differentiate between "Our server has gone boom, hoepfully our internal monitoring app has paged a sysadmin to fix it." and "Your Internet connection is busted; yell at your ISP." Testing several major internet sites is really the only way to go there since I've encountered more than a few cases where something in my/my isps networking gear went splat and Windows never got a clue. Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
  • Strictly Short Circuit

    csharp com help
    37
    0 Votes
    37 Posts
    72 Views
    L
    Jörgen Andersson wrote: Naerling wrote: Our company has a product where turning Option Strict On results in probably 1000's of errors Then you need to start fixring now. ...snip... If it's not the highest priority your company has problems. FTFY
  • Code should be 5 or anything above 7 long...

    css question
    30
    0 Votes
    30 Posts
    7 Views
    Sander RosselS
    Indeed, not enough Objects... ;p It's an OO world. public class Naerling : Lazy<Person>{ public void DoWork(){ throw new NotImplementedException(); } }
  • The beauty that is the default conversion...

    database
    9
    0 Votes
    9 Posts
    0 Views
    G
    In my experience, once you turn them into embedded programmers, they always think they have to roll their own. We've got a guy in our group like that. We're constantly having to tell him "No, just use class Mousetrap. Yes, yours is cool and all, but we've got lots of time on Mousetrap, plus it works with the rest of the architecture. No, yours doesn't." Software Zen: delete this;
  • Enabling backwards compatibility

    c++ security tutorial question announcement
    15
    0 Votes
    15 Posts
    0 Views
    M
    They kind-of have that already. You might say public class UserID : String { }
  • Code Optimize

    com code-review
    53
    0 Votes
    53 Posts
    0 Views
    C
    Rob Grainger wrote: Hey, no harm done. I'm left feeling much better from the whole encounter now. As am I. Rob Grainger wrote: I know the feeling re. terrible project decisions, I'm having to live with some at the moment, and it can grind you down. Yes, it can. Luckily, our heads are made of stuff too hard to grind to meal, isn't it? ;-)
  • Classical unitialized C pointer

    help
    20
    0 Votes
    20 Posts
    1 Views
    J
    YvesDaoust wrote: Strange that the warning levels did depend on the optimization levels. In theory, optimization is fully transparent to the program semantics, isn't it ? Of course. But the used compilers are historic. YvesDaoust wrote: "Code is not allowed to be released, if there are any warnings": it is tempting for some developers to bypass this by just disabling the warnings. As heavy as this may be, such twists should be appropriately commented. They must be commented. But there are situations where warnings may be disabled. An example would be using DAO which floods the output with C4995 warnings (name was marked as #pragma deprecated).
  • 0 Votes
    12 Posts
    0 Views
    Y
    There could be a cleaner, pedantic-like way: #pragma warning(suppress: 4700) int x; // Value defined in the inner 'for' loop, we cannot determine what it will be yet, hence the pragma
  • Logical AND with false...

    c++
    9
    0 Votes
    9 Posts
    0 Views
    A
    englebart wrote: Personal Pet Peeve: initializing variables to 0 or null when you can safely initialize a few lines later. I'm sure somebody else' pet peeve is... "wait to initialize variable when you could've just done it with the declaration". Most C programmers do it that way...
  • Test-driven voodoo magic

    database wcf sysadmin business regex
    13
    0 Votes
    13 Posts
    1 Views
    P
    that is the default testing technique used by millions of programmers. unless you have good dedicated programmers who really care about their code this unit testing BS will not yield any fruit...and the catch is if you have good programmers then very rarely they would need unit tests as they will write it right the first time. I deal with such programmers everyday they add 5 items to a list then check if the list has 5 items as if there was some leak in CLR.
  • Zombie Application?

    ruby question
    5
    0 Votes
    5 Posts
    0 Views
    L
    I wish I could do more than 5
  • Why is dates so difficult?

    question
    4
    0 Votes
    4 Posts
    0 Views
    F
    You mean, why is grammars for naturals language so difficults, right? ;P Well, one explanation could be that the speaker is not a native speaker. But I agree, I'm annoyed by bad grammar too.
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • Code Repeating

    javascript html algorithms business performance
    8
    0 Votes
    8 Posts
    0 Views
    B
    I was going to suggest exactly this little trick. It can really help with refactoring old crap.