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
  • When Default is not the default

    workspace
    3
    0 Votes
    3 Posts
    0 Views
    Sander RosselS
    You probably shouldn't use my initials in your code like that ;p Visit my blog at Sander's bits - Writing the code you need. Or read my articles at my CodeProject profile. Simplicity is prerequisite for reliability. — Edsger W. Dijkstra Regards, Sander
  • Switch boolean.... (reinventing if, unnecessarily)

    47
    0 Votes
    47 Posts
    81 Views
    B
    With "simple" booleans, a switch statement is not necessary. But what about "extended" boolenas (i.e. true, false, don_t_know, FILE_NOT_FOUND)? That's where a switch comes in very handy.
  • Fun with Generic Enum Constraint

    help regex question announcement learning
    11
    0 Votes
    11 Posts
    0 Views
    J
    In your last method, beside being awkward, you are boxing & unboxing the value. Which probably increase the time that method takes to run by at least one order of magnitude. A way to avoid this is to take advantage of something we already know... enums are `IConvertible`. void Main() { var b = new EnumDescConverter(); b.GetEnumValueT("Dummy desc").Dump(); } enum nums {zero, one, two, three}; enum Nums {Zero, One, Two, Three}; class EnumDescConverter { /// Simplified a bit for example. protected IConvertible GetEnumValue(string description) {return nums.one; } } class EnumDescConverter : EnumDescConverter where T : struct, IConvertible { public T GetEnumValueT(string description) { return (T) GetEnumValue(description);} } P.S. http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2557231-enums-constraint-for-generics[^] Truth, James
  • $%$PrInC%$% 8696109482 how to control wife by MaNtRa In Gurgaon

    tutorial
    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • $%$PrInC%$% 8696109482 how to control wife by MaNtRa In Gurgaon

    tutorial
    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • WPF ValidationErrors

    csharp wpf com help question
    10
    0 Votes
    10 Posts
    0 Views
    Richard DeemingR
    That would be a better solution. Now you just need to convince Microsoft to adopt it! :) "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
  • Code Puzzle

    question database docker
    28
    0 Votes
    28 Posts
    2 Views
    S
    Very nice, will order again ;) If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
  • Singleton Pattern

    csharp asp-net com design regex
    3
    0 Votes
    3 Posts
    0 Views
    CHill60C
    Anurag Gandhi wrote: this kind of articles should be removed from codeproject as it misleads young developers I completely agree, and you will pleased to hear that it has now been deleted! Don't forget that you can report articles as being "Inaccurate or Misleading" :thumbsup:
  • Why do they call it "hard" coding?

    question
    13
    0 Votes
    13 Posts
    0 Views
    S
    I did before I read your explanation, do I win a cookie? :-D If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
  • Now, that's a first...

    question help learning
    7
    0 Votes
    7 Posts
    0 Views
    S
    I think he simply asks WHAT book to read...its just bad English. But the fact that he doesn't know how to convert types...now, that is...wow. What is he (or maybe she) doing programming, he should be banned from computers! ;)
  • Radio button that is actually a checkbox

    com
    8
    0 Votes
    8 Posts
    0 Views
    A
    I had Narnians on my mind. :sigh: The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
  • VMWare API nonsense

    json question announcement
    9
    0 Votes
    9 Posts
    0 Views
    S
    You could keep concrete typename for particular installation in a config file (settings table or whatever) and instatiate via Activator class. Then it is only matter of keeping straight who uses what and adjusting the config.
  • What position is the letter A? Let's use a lookup table!

    ruby question
    25
    0 Votes
    25 Posts
    1 Views
    G
    I was thinking more of something like "1".tolower might work. “That which can be asserted without evidence, can be dismissed without evidence.” ― Christopher Hitchens
  • Overpaid, over engineered and totally in-yer-face...

    16
    0 Votes
    16 Posts
    1 Views
    D
    expected ';' ;P
  • IRS Developers gone wild ?

    question
    7
    0 Votes
    7 Posts
    2 Views
    C
    Well, thankfully, they haven't "lost" any of those documents ;) Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
  • SOMEONE had too much time on their hands...

    question com adobe architecture
    4
    0 Votes
    4 Posts
    0 Views
    M
    Good god, he implemented floating point math with integers to 4 digits after the decimal point of precision. Marc Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!
  • Property Change Notifications

    lounge
    9
    0 Votes
    9 Posts
    0 Views
    R
    In our code, it is all done via our own MVVM framework. I have a SetProperty method defined on a base class, using a [CallerMemberName] argument to specify the property, which performs the following actions: 1. If the value has not changed, exit immediately. 2. Use Reflection to check the property specified actually exists. 3. Call a method RaisePropertyChange to raise the event. RaisePropertyChange is designed to allow firing notifications on derived properties when a base property or other change occurs that would affect their value (similar to most MVVM frameworks). Effectively this just triggers the PropertyChanged event, passing a property name as a string. Note however that (perhaps unwisely) I didn't use reflection in RaisePropertyChange to check the property exists. The dev in question simply called this method, passing a string that doesn't correspond to a property name. I guess I didn't consider the probability of someone being that daft. (I've now added the code to check - shame as it decreases the efficiency somewhat as it has to use Reflection to check each property access, but it costs to defend against stupidity. I'm just glad all this is in a managed language, I dread to think what would happen if these muppets were let loose on C++). "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    1 Posts
    0 Views
    No one has replied