Click here to Skip to main content

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrasing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
GeneralRe: A MySQL horrormemberFlorin Jurcovici27 Aug '12 - 1:56 
Michael K Gray wrote:
Another good reason to buy SQL Server, or ORACLE, etc.

That's plain wrong. It all depends on the business model and on the app using the database.
 
Besides, MySQL does have its strengths - it beats any commercial offering from MS or Oracle when 90% of the workload is reads performed by a server with limited hardware (depending on the table type being used).
GeneralRe: A MySQL horrormemberenglebart27 Aug '12 - 5:17 
We have (for many years now) a worse problem in Or-ache-le.
A query should return 3000 rows.   It just returns 1200 and does not generate any error.
 
A corrupted value in a key terminated the retrieval, but it still returned success.
GeneralString.Format - I'm sure there must be a worse way to do this. [modified]memberRCoate15 Aug '12 - 16:08 
I'm a bit surprised there isn't an embedded String.Concatenate call in there as well.
 
DateTime dt = DateTime.Now;
 
// Get year, month, and day
string year = dt.Year.ToString();
string month = dt.Month.ToString();
string day = dt.Day.ToString();
 
// Format month
if (month.Length == 1){ month = "0" + month; }
 
// Format day
if (day.Length == 1){ day = "0" + day; }
 
string DocumentName = string.Format("Application - [{0}] - " + year + month + day, this.Person.RegistrationNo.ToString());
 
I'm thinking that there is a ToString() call missing just before the final ; too.
 
Oh - and this one too.
TRIMSDK.Location trimLocation = trimLocation = trimManager.FindLocationFromNickname(string.Format("{0}", this.Person.RegistrationNo.GetValueOrDefault(0).ToString()));
 
I think I need a Rum! WTF | :WTF:

modified 15 Aug '12 - 23:47.

GeneralRe: String.Format - I'm sure there must be a worse way to do this.memberegenis15 Aug '12 - 18:36 
RCoate wrote:
// Format month
if (month.Length == 1){ month = "0" + month; }
 
// Format day
if (day.Length == 1){ day = "0" + day; }

 
Now if that had been done with a StringBuilder... I would have been impressed!
Shucks | :->
GeneralRe: String.Format - I'm sure there must be a worse way to do this.memberRCoate15 Aug '12 - 18:56 
// Format month
var sbMonth = new StringBuilder();
if (month.Length == 1)
{
    sbMonth.Append("0");
}
sbMonth.Append(month); 
 
Awesome! I knew there was another method missing!
Smile | :)
GeneralRe: String.Format - I'm sure there must be a worse way to do this.memberPIEBALDconsult16 Aug '12 - 3:43 
Now try it with Insert.
GeneralRe: String.Format - I'm sure there must be a worse way to do this.memberRCoate16 Aug '12 - 12:25 
Got your insert right here.
// Format month
var sbMonth = new StringBuilder();
sbMonth.Append(month);
if (month.Length == 1)
{
    sbMonth.Insert(0, "0");
}
 
I'm sure if the genius who wrote this was aware of Insert and string builders, it would have been used.
 
Can't complain too much. At least the code actually produces the required outcome. I can't always claim that. Smile | :)
GeneralRe: String.Format - I'm sure there must be a worse way to do this.memberSlacker00716 Aug '12 - 22:53 
String.Remove() and String.Insert() - I use these a lot. BTW, I hardly use StringBuilder(), but that's just my style.
 
Wink | ;)
GeneralRe: String.Format - I'm sure there must be a worse way to do this.member0bx19 Aug '12 - 8:50 
var sbMonth = new StringBuilder();
try
{
  int x = 1 / month.Length -1;
  sbMonth = AppendMonth(sbMonth);
}
catch
{
  sbMonth = AppendMonth(sbMonth, "0" + month);
}
 
private StringBuilder AppendMonth(StringBuilder sb, string s)
{
    string x = sb.Append(s).ToString();
    StringBuilder y = new StringBuilder();
    return y.Append(x);
}
Giraffes are not real.

GeneralRe: String.Format - I'm sure there must be a worse way to do this.memberRCoate19 Aug '12 - 13:06 
OMG | :OMG: Yep. That's worse.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 24 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid