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
  • Throwing exception

    10
    0 Votes
    10 Posts
    17 Views
    raddevusR
    OOAD commandments: "Thou shalt not use exceptions for flow control." Right. Because exceptions used for flow control are gotos. :) The code jumps to the exception handling routine on error, just as a goto jumps to another place.
  • NEW

    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • XPath string comparisons

    xml csharp database debugging
    4
    0 Votes
    4 Posts
    0 Views
    Richard DeemingR
    OK, the "less than" and "greater than" operators don't work for strings, as per the specification: XML Path Language (XPath)[^]: When neither object to be compared is a node-set and the operator is <=, <, >= or >, then the objects are compared by converting both objects to numbers and comparing the numbers according to IEEE 754. I'd be very surprised if that wasn't also the case with the old MSXML library. But then again, it was written by 90's Microsoft - they weren't the best at sticking to the specifications! :-D There's no obvious sign of Microsoft implementing XPath 2 or 3 in .NET; there's an open suggestion from 2013[^] which is "under consideration", with no sign of any action. There's also an MSDN blog post from 2004[^] suggesting they would be working on XQuery instead. Again, no sign of any progress on that front. It's also worth pointing out that you can't use the less than or greater than operators on strings in .NET code either. Instead, you have to use the CompareTo method. You can get close by using LINQ to XML, but that obviously requires you to load the entire document into memory: var doc = XDocument.Parse(@"<?xml version='1.0'?> <bookstore xmlns=""urn:newbooks-schema""> <book genre=""novel"" style=""hardcover"" publish_date=""1825-04-02""> ... </bookstore>"); var nodes = doc.Descendants(doc.Root.Name.Namespace + "book") .Where(el => ((string)el.Attribute("publish_date")).CompareTo("1901-10-29") >= 0); // Or: var nodes = doc.Descendants(doc.Root.Name.Namespace + "book") .Where
  • Two easy lines for web copy to clipboard

    javascript com adobe cryptography business
    2
    0 Votes
    2 Posts
    3 Views
    N
    :thumbsup: M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
  • 0 Votes
    12 Posts
    1 Views
    D
    I agree, if you are actively developing software for paying customers. David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
  • Prepping for SQL Server Update

    sql-server database sysadmin announcement career
    17
    0 Votes
    17 Posts
    0 Views
    T
    It's because she has chesticles and you don't #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
  • Why Static Const Almost Always Trumps Const

    question com data-structures help
    5
    0 Votes
    5 Posts
    0 Views
    D
    Thanks much for duplicating the observation with the other popular C compiler. As I said, I observed the same thing about a dozen years ago, but I had forgotten the details. Anyway, so far as I know, the same holds whether your code is straight ANSI C or ANSI C++. The test case that I cited in the Stack Overflow article is straight ANSI C. David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
  • Good Regular Expression Fiddle

    regex javascript python php com
    8
    0 Votes
    8 Posts
    1 Views
    D
    There are probably more RegExp fiddle forms than there are JSFiddle, JSONFiddle, and all the rest combined. What appealed to me about this one was the clear feedback about text entered into the test text box. David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
  • Freestanding Color Picker Programs

    com help
    27
    0 Votes
    27 Posts
    0 Views
    H
    word is in c# ushort In Word you can only store 2 bytes. That is why I use Writer.
  • Repurposing VarChar columns

    database question
    13
    0 Votes
    13 Posts
    25 Views
    D
    GuyThiebaut wrote: have seen them to help in making the developer's life easier by keeping problematic data out of a database. I agree with you 100%, and I rely on foreign keys for precisely that reason. Nevertheless, I think it's important to be aware that having one doesn't excuse the developer from handling exceptions. In the situation under discussion, you are trading one kind of exception for another, albeit, more useful, one. I don't think it would affect the view, either, but I thought it prudent to allow for some technical detail that I might have overlooked. I usually don't construct any views until I have my foreign keys defined, so that I can leverage them to help create the views. David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
  • Recursion in SQL

    database javascript sql-server com
    9
    0 Votes
    9 Posts
    0 Views
    D
    IMO, recursion is inherently dangerous, and must be avoided whenever possible. Moreover, when you must use recursion, you must also take steps to ensure that your recursive routine converges and unwinds its recursive stack. Every recursive routine must incorporate a test that stops the recursion in such a way that the recursion depth is self-limiting. This is true regardless of the programming language in which the recursion occurs. Whenever I encounter a recursion, my first thought is to investigate other algorithms that don't rely on recursion. More often than not, I have managed to succeed in finding one. David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
  • Is it my fault?

    csharp oracle question
    33
    0 Votes
    33 Posts
    105 Views
    D
    Eddy Vluggen wrote: Best practice means not to discourage the use of exceptions, simply because someone thinks that they slow the system. As you can see, it doesn't take much time to invoke the entire exception stack, as it can be done several thousand times in a second. I've seen a few exceptions that consumed viscerally measurable time, but they were thrown deep in the stack, but the first exception handler that could catch them was in or near the main routine, many layers up the call stack. Hence, there was a lot of stack to unwind. Eddy Vluggen wrote: Too many idiots avoiding exceptions altogether and using booleans instead :thumbsup: If it is an error, throw an exception, it is that simple. Too many people being too lazy to use their God given brains as intended. Programming is, after all, all about thinking. Best practices are intended to serve as rules of thumb, not ironclad rules. David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
  • 0 Votes
    6 Posts
    0 Views
    D
    Thanks for calling my attention to the debugger command. Though I vaguely remember a reference to it, I've never seen it in action. I'll do my best to remember to do so the next time I'm working on some JScript that runs in a Web browser. David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
  • Sunday morning, and Microsoft has rebooted my laptop...

    help
    36
    0 Votes
    36 Posts
    41 Views
    C
    You are missing my point entirely. thrice, so, rather than hash a dead horse, have a nice day. Charlie Gilley <italic>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
  • English question

    question
    18
    0 Votes
    18 Posts
    0 Views
    K
    Most probably the verb like 'spell' or 'pronounce' Still when working on a few morphology related papers with jetwriters I've seen a couple of times phrases like 'use a phonetic alphabet' So far I haven't seen any other collocations used with the word 'alphabet'
  • reassigning static variable

    adobe performance question
    6
    0 Votes
    6 Posts
    0 Views
    Richard DeemingR
    KarstenK wrote: the ref counter of the original object is set to zero If it's .NET, there's no ref counter. Instead, the GC will detect that the object is no longer reachable. That way, circular references won't leak memory. :) "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
  • Isomorphic Git

    question javascript com adobe collaboration
    8
    0 Votes
    8 Posts
    0 Views
    S
    Lol! That's what I am talking about! :-D :laugh: A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
  • Time Stamps Rendered by CMD.exe

    help
    12
    0 Votes
    12 Posts
    27 Views
    D
    I haven't gotten to PowerShell, per se. However, since it runs atop the .NET Framework, I expect it to exhibit the same (correct) behavior as my test program. Hence, between that and the fact that I seldom use PowerShell, I wasn't planning a separate evaluation of it. David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
  • Who wrote this code?

    javascript python visual-studio com question
    8
    0 Votes
    8 Posts
    19 Views
    R
    So that must be: Quote: Love and marriage, love and marriage They go together like a horse and carriage This I tell you, brother You can't have one without the other Congratulations !
  • Mystery of the Missing (foreign) Keys

    database
    6
    0 Votes
    6 Posts
    0 Views
    P
    The application must not rely on such things for proper functioning!