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
  • How to zero-pad a number?

    tutorial question
    20
    0 Votes
    20 Posts
    2 Views
    D
    Wonderful code! When I was new to programming I used to do something like this too. Then I figured out a trick: just add 1.000.000.000 to the number and take the last 4 characters. Now I just use PadLeft, PadRight or Format
  • Why is my code so slow??

    testing beta-testing question
    18
    0 Votes
    18 Posts
    0 Views
    S
    vonb wrote: To 4'999??? or to 1?? :) Silly, to -1. (Incidentally, sleeping for 0 cycles has "special behaviour")
  • Can I copy that?

    question announcement
    3
    0 Votes
    3 Posts
    0 Views
    N
    try deleting them and see if anybody notices :laugh:
  • Anyone see the problem here?

    help question
    9
    0 Votes
    9 Posts
    0 Views
    B
    The next gem is to be expected in the Untested Sql Procedure (usp_) ErrorLogInsert: in case of an exception happening there, it will check the location parameter, and if it starts with "insertErrorLog" not throw an exception but set errorID to null (that's why it's nullable). And the guy never checks the value of errorID after execution!
  • Hardcoded Teacher Passwords

    sysadmin security help tutorial question
    13
    0 Votes
    13 Posts
    0 Views
    H
    Besides this one you mean? Windows 8 is the resurrected version of Microsoft Bob. The only thing missing is the Fisher-Price logo. - Harvey
  • something weird

    3
    0 Votes
    3 Posts
    0 Views
    P
    It may a language with which neither of us is familiar. ;P But, yes, more likely a language with which the poster is unfamiliar. :sigh:
  • Don't you hate it when you do that?

    announcement database question
    5
    0 Votes
    5 Posts
    0 Views
    B
    Yeah that comes from somewhere quite deep in hell. When I want you to synchronise with an external data provider/sink, I'll tell you with a method call! I don't like entity mapping tools that are too clever for their own good.
  • 0 Votes
    17 Posts
    1 Views
    J
    Read it again. ahah
  • I fixed it... some day

    help announcement
    7
    0 Votes
    7 Posts
    0 Views
    G
    Evidently I came back in time, and just got stupid with the date, because the described fix is in the code. Software Zen: delete this;
  • How about some paradox

    6
    0 Votes
    6 Posts
    0 Views
    F
    Yes, it should. And this little change makes the diffrence between a loop that runs once and a loop that runs forever. :) The good thing about pessimism is, that you are always either right or pleasently surprised.
  • how about some fun

    adobe help
    3
    0 Votes
    3 Posts
    0 Views
    L
    Damn syntax errors
  • Most Unhelpful Message Ever

    learning
    48
    0 Votes
    48 Posts
    51 Views
    P
    I don't think that someone would want to handle the failure of core functions and thread creation is quite a core feature in my opinion. Even if you would want to handle errors after every single line of code you would fail. The solution to your problem is building an automatic document save/backup function into your crash handlers/critical function. This way you guarded your program not only against thread creation errors but a lot of other bugs/crashes too! BTW, in most of my programs I usually create all needed threads at program startup (in pools) and destroy them at cleanup. In this case a CRITICAL is valid even without document saver. Most multithreaded programs work with a fixed or predictable number of threads that you can precreate.
  • Something original

    csharp com graphics game-dev
    24
    0 Votes
    24 Posts
    4 Views
    M
    As I sat here working I thought about your signature again: What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake. What struck me is that most of my career has been in high-resolution measurement and robotic control. And I specifically remember two projects where this signature almost became truth. First was a big Sieko SCARA robotic disk sorter. This robot measured almost 4 feet at its longest extension and it could retract and move 180 degrees and extend out 4 feet in the other direction in just about 1/10 of a second. The thing was bloody fast! We of course built a plexiglass sensor tripped cage around the thing so no idiot would get it it's way. Well one did. He removed the plexiglass portion where he needed to work, jumped the sensor and leaned in slightly to look at an issue with a printer. He spent about a week in the hospital after the bump on the head. The next was an instrument down the line from the disk sorter. It was a combiner. It had a big chuck on it to pick up about 25 disks and it would move laterally left/right to combine disks into caddies for shipment. Of course it needed to be fast so we used the biggest NEMA steppers and drivers we could find. This thing could traverse about 4 feet in 1/10 of a second. It too had a plexiglass cage. But one day I was working underneath it looking at some issues with the conveyor, I was well clear but then I heard this scream and instinctively I hit one of the gazillion estop buttons we'd wired in. A young assemply worker had her hand caught between the side of the machine and the moving carriage. Crushed quite a few bones. Why she had her hand in there was beyond me. But of course it was the software's fault for not "knowing" that a hand was in the way and gracefully stopping. Sigh... Third was an instrument that spun silicon wafers to coat them for prep. It used a big servo motor for the spinner. They had to spin pretty fast. They would come in, a mechanical centering device would center them on the vacuum chuck, retract then they would lower into a bowl and the big servo motor would spin them up to a fairly high speed. Well those of you familiar with servos know they need to be tuned. Kd, Ki, Kp, etc. Usually you have to do it under load. So stupid me put a 300mm wafer on the chuck, centered it, lowered it in to the bowl, opened the protective lid, jumped the protection sensor and hit go on the tuning algorithm. That thing
  • How about this little c# code

    csharp question
    12
    0 Votes
    12 Posts
    1 Views
    B
    You need this![^] Keep Clam And Proofread -- √(-1) 23 ∑ π... And it was delicious.
  • Points, Points Everywhere

    csharp ruby visual-studio question
    11
    0 Votes
    11 Posts
    2 Views
    M
    The programmer has exactly 50 days left on his/her contract. Out door and wait for the frantic "It's broken call... please come fix it at 3x your previous rate!!!" Just a guess. We had a bug tracking system written some time ago that had a primary record holder delared something like DefectRecord Records[50]; Because he/she never thought anyone would have more than 50 defects to see at one time on a report. Guess they never ran into a project like the one I'm currently on.
  • 0 Votes
    10 Posts
    0 Views
    D
    It wasn't a hypothetical for me either. X| 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
  • If only there were a language construct to handle this case...

    database
    5
    0 Votes
    5 Posts
    0 Views
    R
    Thank you for saving me the effort, exactly my point. "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
  • Best Function Ever

    javascript collaboration tools question
    17
    0 Votes
    17 Posts
    0 Views
    E
    Bingo!!! Where is such company that pays that way... Can I have address and name of HR and name of the bar she frequents after work?
  • So you think you know what double.Parse does?

    question
    12
    0 Votes
    12 Posts
    3 Views
    E
    Feds are gonna investigate and file a report on whoever has done this heinous crime ...
  • 0 Votes
    1 Posts
    0 Views
    No one has replied