- Feature Articles
- CodeSOD
- Error'd
- 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
The reason Oracle is hated so much, are "developers" like these. And the pricing. The reasons Oracle is hated so much, are "developers" like these, and the pricing. And the tooling. Amongst the reasons Oracle is hated so much, are "developers" like these, the pricing, and the tooling.
Nobody expects code like this.
Admin
So this code is the Spanish Inquisition?
Admin
ROFL
Admin
I think I would actually prefer the Spanish Inquisition than maintaining that codebase.
Jokes aside, good luck to Mateus!
Admin
There are two rules of data, that everyone feels compelled to break at some point because it it seems like it would make the immediate problem so easy, but will almost unfailingly lead future problems that are far more difficult t solve.
With probably half my career in information systems now in the rear-view mirror if there were two things I tell new people what your information theory text said on these subjects is entirely correct, just treat it as gospel, take it as an article of faith it will make your life better, those would be it.
Admin
The code really sucks but it is not about city names, it is actually about the states in Brazil. Some of our state capitals share the same name as their states like São Paulo and Rio de Janeiro, for example, adding to the confusion.
What is even worse, Brazil only has 26 states plus the capital, which is kind of treated as a state. This means this code has some items that should be impossible as it has 30 replaces.
Admin
Unfortunately if you want to do this directly in an SQL SELECT, nested REPLACE may be your only option. If it's Oracle though, DECODE would be rather more readable
Admin
The most dangerous words in the English language are "this time, it's different."
Admin
So not only is it horribly implemented, it is horribly implemented with incorrect data. It's a WTWTF. Nice.
Admin
EX and XX are not states, RN is replaced twice, that explains the 30 replaces
Admin
Or the ruthless inefficiency.
Admin
And they entries will now all have a trailing space.
Admin
The flaw in your reasoning is in assuming that the programmer who wrote the code and the sucker who has to maintain it are the same person.
Admin
String processing in SQL sucks. Before REGEXP_REPLACE was added, this was the way to do multiple replacements.
Admin
Closely followed by "We'll fix it later"
Admin
ROFL (YSST) ;-)
Admin
I came here to say the same thing; those abbreviations are for the states. TRWTF is storing the city and state in the same database field. If the state were its own field, it would be so much easier to select all the cities within a given state. I may be wrong, but I think "EX" might stand for exemplo (Example), "DF" for the "Distrito Federal" (Federal District / Brasilia), and "XX" for unknown / not available.
In a weird twist of fate, I think a REGEX to remove the state abbreviation might be the solution easiest to read.
Admin
Comparing the hard-coded list to this,
https://en.wikipedia.org/wiki/Federative_units_of_Brazil#List
the count in the program is 30 instead of 27 because "XX" and "EX" are not Federative Units, and "RN" is included twice. I suspect the two codes containing "X" have some sort of special meaning.
Admin
Can't he use SELECT LEFT and CHARINDEX together to fetch everything before '('? It's even cleaner than REGEX and IIRC existed way before REGEXP_REPLACE was added.
Admin
How about STRING_SPLIT at the position of '(' determined by CHARINDEX? Not quite most optimum, but less pessimum... four! Four biggest SQL manglers!
Admin
Apparently the table definitions are sacred. Create column 'state_code' and fill it with the two char codes . Then you can isolate the name from the code and combine it in all the places where you want to see it together.
How many time are values combined in a column where it should idealy be 2 or more. Does oracle charge by the number of columns now?
Admin
Not zo, that's what the RTRIM is for.