- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Stop Poking Me!
- Operation Erred Successfully
- A Dark Turn
- Nothing Doing
- Home By Another Way
- Coast Star
- Forsooth
- Epic
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I think these all make sense.
Admin
If only people had some sort of way of examining how code got to the point it is over a period of time....much might be revealed....
Admin
the job of dev is not to write code, his job is to know exactly what mood was last dev in while writing the code currently on screen - maybe his wife left him? were his kids good at school? is his pet okay?
Admin
sometimes the new guy has to repair/patch/improve/change what the old guy did.... and in most of these cases the old guy built a boat when what he needed to build was a car.. with some serious effort you can perhaps convert a boat into something that resembles a car just to find out, after deployment, what the client actually want, is a plane.....
Admin
"Effects may proceed without cause."
WTF? With respect, Remy, you're challenging Aristotle and Aquinas. What are you, some kind of heretic, overturning dogma handed down from the ancients?
No?
A 21st century programmer?
Oh, righto. Forgive the interruption. Carry on. :-)
Admin
We should all start adding Facebook style emotion messages to our version control logs:
Fixed CN-43502 causing crash of system when empty string is entered for date. -- Feeling amused :-)
Admin
Not quite what you said, but close...
https://github.com/sasstools/sass-lint/
Admin
str(date) will not correctly display january as "0", as our requirements apparently are saying
Admin
I skimmed through some SQL-Queries buried deep in stored procedures and such. They all begin their where clause with
"WHERE 1 > 0 AND [...]"
The reason is, if you change that to say "WHERE 1=0" it's never true and the update or insert will not be executed. But it's still a head scratching moment when you see something like this for the first time. "What? On which occasion would 1>0 NOT be true?"
Also, simply commenting out the unwanted statements seems to be too much hassle... or maybe it's just TOO obvious? Wouldn't it be funny to change a few of those statements to something like "WHERE 1 < 0" and then everyone could dive into the code trying to figure out what the hell wents wrong.
Admin
I've seen this, but because each condition was "AND x=y" on its own line. You can move conditions around and un/comment them by line without having to make sure all the ANDs still line up. Much like comma-separated arguments with lines of ", argumentN" so that there isn't a dangling "," to mess things up.
Admin
At least for once, the WTF was not the choice of date format.
Admin
By "commenting out the unwanted statements" I meant like, commenting out the entire insert or update statement, not simply change around one condition in the where clause. Forget to change it back and it can be a bitch to track down. Try skimming through dozens of SQL queries and try to spot the one query with "WHERE 1=0" instead of "WHERE 1>0". If the whole statement is commented out, it becomes obvious in an instand. Provided the tool you use offers syntax highlighting.
Admin
How boy was I disappointed when I saw in the source that it was just your surname...
Admin
Oh, right. Yeah, that sucks. I don't suppose the Resident Ninja comes out and says "well duh, that's my supreme coding standards"?
Admin
There is a way. It is called version control.
Admin
Biggest whoosh ever! Congratulations ;-)
Admin
But what system controls the version of the version control system?
Admin
It's amazing how many people cannot manage to format a (UK) telephone number correctly, even though there are only three rules: 01nnx abcdef n!=1 else 02x abcdefgh else 0xxx abcdefg
Admin
A self-hosting version control system...the code for the version control system is hosted within a running copy of the version control system itself...
....now if you host the code for the main website for the version control system in a running copy of the version control, you've gone to the next level...
...and if you're running the main website for the version control system from a running copy of the version control...
...you've got the 'Fossil' source control system: https://www.fossil-scm.org/index.html/doc/trunk/www/index.wiki
Admin
It's version control systems all the way down. <smug>
Admin
Nope https://en.wikipedia.org/wiki/Telephone_numbers_in_the_United_Kingdom
Admin
Still contemplating the edge cases for WHERE 1 > 0
Admin
I hate hate hate lines starting with ','. It's so painful to read. Yet people think it's such a good idea that clang-format will do that for member initialisation lists and it is horrible (and it doesn't work very well if you happen to want to comment out the first initialiser).
Admin
I looked at our codebase, most of the worst was made by "Commit, Initial". I hate that guy.
Admin
I swear I saw the last code block somewhere online as an answer to a syntax-related question, trying to show the various ways of converting date-time.
Admin
Yeah, well my guess is that's what the "where 1>0 " is doing, so they can just go in and blindly comment out conditionals without fretting about the syntax. My first thought was that this is someone building the where clause using string concatenation elsewhere and didn't want to bother checking for the first/last condition to avoid an extra " and ". One mess hiding another.
Either that or they are checking the space time-continuum is still functioning correctly, we wouldn't want to go spitting out misleading results if suddenly up=down or datediff(day, today, tomorrow)<0.
Admin
01nn..., n != 1? That rules out many major cities. (Someone else has already linked you to the Wikipedia article)
Also, the only formatting rules for tel numbers are that global numbers begin with +. Any other number is subject to routing/interpretation by exchanges, so you can't reasonably be expected to be able to know any number belongs to any region and then format it as such.
It's much like email in that the best way to deal with it in all practical cases is to leave it as a plain text field.
Admin
WHERE 1>0 (I actually use WHERE 1=1, more obvious) is the oldest trick in the book for building dynamic queries. Once in place you can easily add 'AND so and so' where you're applying an unknown quantity of multiple Filters from a user screen.. The true beauty is that you never need to know or care how many Filters were actually requested, as it also covers the case where there are no filters at all (you don't need to check to check first and omit the WHERE when none). The presence of this construct in an SP simply means that the Filters were passed onward to an SP to do the work rather than the running dynamic SQL.
Admin
My general thinking with styling is that I want to be able to quickly find relevant portions of the query/code, and I can do that if I try to ensure that everything is always in the same place.
In a comma separated list, the line lengths are not predictable, but the beginning is. Thus, if the comma is at the beginning of the line, I know exactly where to look. It may not seem like much, but in my line of work (database engineer supporting BI platforms with databases older than me), I'm constantly parsing through SQL queries that are around 1,000 lines with hundreds of columns. If I can easily find where the definition of each column starts, my life is way easier (also why I prefer [alias] = value rather than value as [alias]). This is especially helpful when the results are complicated expressions that either go off to oblivion or span multiple lines.
When it comes to aliasing a table, once again, the position of the end of the line is unpredictable, but the beginning is not. Thus, I put the alias on a new line. I also treat it as I do a variable in code and use a meaningful value for it. If the table is [Address] and I'm joining to it from a column like [WorkAddress], I'd alias it workAddr. I hate it when I see a table aliased as the first letter or so. When I'm using the value elsewhere, a.[Status] doesn't tell me nearly as much as workAddr.[Status]. In either case, if I'm still unsure about what the alias represents, I could go back to the join to see where it came from, and it's a hell of a lot harder to find the source if I can predictably find the alias at the beginning of its own line.
Overall, I wish that people would appreciate whitespace in SQL like they do in other code. I'm not reading these queries like a novel, so don't write it like one. I just want to be able to look at an expression and be able to find where the data comes from.
Admin
Woops, the last sentence of the penultimate paragraph should be:
In either case, if I'm still unsure about what the alias represents, I could go back to the join to see where it came from, and it's a hell of a lot easier to find the source if I can predictably find the alias at the beginning of its own line.
Admin
yeah sarcasm, i know
Admin
That last one might be even more awesome than explained.
Does the format string passed to strptime mean you don't get leading zeros?
But then they did the whole str() the different struct parts because they wanted them??
Admin
I like this kind of CodeSOD. Lots of little, unrelated, anonymous WTFs. Y'all should do this regularly ... kinda like Error'd for code snippets. Good show.
Admin
Come for the fails, stay for the philosophy.
Admin
Commenting out the SQL will break the stored procedure. Compiler will barf an error about e.g. SQL code behind the stored procedure taking 0 parameters, 3 provided or something along these lines. The approach of if(false&...) makes the query no-op, but doesn't prevent the code from running, accepting all inputs, and returning properly formatted table of 0 rows.
Admin
In the 70s and 80s we had automatic file versioning in operating systems. Saved many millions of programmer hours... if that technology had matured, instead of being discarded, the arcane incantations of (relatively primitive) modern source control systems would be completely unnecessary.
But sadly, although 64-bit computing has been rediscovered, automatic file versioning is gone, thanks to Dunning-Kruger and the Blub paradox. The only place is lingers in on CDs, in the sadly dated ISO9660 spec, and OSes generally make sure you can't see it even there.