|
I don't have an answer for you, but to keep it on-topic, this confusing overloading of the meaning of * was a major flaw in MC++, and it's been fixed in C++/CLI by denoting GC handles with ^ instead.
|
|
|
|
|
Method name (only) changed. It shouldn't even have been public in the first place. Even if you disregard the blatant coding guidelines violations, I think this is a shame.
public string getFormattedDate(string date)
{
string concat ="";
if (null != date)
{
int i;
String dateTimeChar = new String(date.ToCharArray());
for(i=0;i<(date.Length-4);i++)
{
concat = concat+ dateTimeChar[i];
}
concat = concat+ ",";
for(i=4;i<(date.Length-2);i++)
{
concat = concat+ dateTimeChar[i];
}
concat = concat+ ",";
for(i=6;i<(date.Length);i++)
{
concat = concat+ dateTimeChar[i];
}
DateTime dt = DateTime.Parse(concat);
concat = dt.ToString("yyyy-MM-dd");
}
return concat;
}
|
|
|
|
|
Arrgggghhhhh - that's horrible. Let's ignore the fact that the method name is camel cased and hit a particular arrogant nasty. Unless you have a really, really, really good reason (and by that I mean that you can prove to me that you know me much much better than I know myself), don't presume to know how to format a date that I will like. I hate it when people force these cultural settings on me, and I have refused to use some software in the past because it has presented regional variations on me that I don't like because they are downright confusing.
As an example, what date is this?
06/05/07
Is it the 6th May 2007, the 7th May 2006, the 5th of June 2007?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
It's a very good practice to ensure that any date strings you output to a file that will be consumed by another program have a fixed format. It doesn't much matter what that format is, but there's an ISO standard for yyyyMMdd, so that's what I normally use. (SQL Server is happy to consume that format and do so consistently whatever regional settings are applied).
|
|
|
|
|
Yes, for outputting to a file or other method of "data interchange" use ISO 8601, for output to a person, allow that person's culture to format the date.
|
|
|
|
|
I once got burned by a ASP/ access database site that would create utter crap when move from an english development to a german production server. (Or the other way round? I forget).
|
|
|
|
|
Ick. The obvious solution is
return date.Substring(0,4) + "-" + date.Substring(4,2) + "-" + date.Substring(6,2); Goes nowhere near the risk of DateTime.Parse doing something different in a different locale.
|
|
|
|
|
Even ignoring the language, there are too many things wrong. The most important being that the characters are not being gathered based on their value.
while( date[i] == ‘y’ )
Concat += date[i++];
Or something similar.
I have know idea why the new String is even present, other than to waste time and memory.
The given code is just asking for the call to pass the wrong format, so that it can throw an exception.
In general, this code would receive a ‘D’ at best and an ‘F’ in any production code.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I'm guessing using the .ToString([inserted quoted format here]) was too difficult. What a shame.
Phil
|
|
|
|
|
Superb HORROR
Regards,
Sylvester G
sylvester_g_m@yahoo.com
|
|
|
|
|
hi all,
can we declare a class without constructor in c++... is it a good way of coding..
thanks,
Vimal
If U Get Errors U Will Learn
If U Don't Get Errors U Have Learnt
|
|
|
|
|
Repeat yourself here instead :
http://www.codeproject.com/script/comments/forums.asp?forumid=3785
Kochise
In Code we trust !
|
|
|
|
|
More people might follow the links that you post if you make them clickable which is very easy to do.
|
|
|
|
|
If he can't copy/paste, I think he shouldn't even bother coding. I'm not here to wipe his nose (or other ends) when it's messy, or prechew his meat to feed him like a young bird...
Kochise
In Code we trust !
|
|
|
|
|
Kochise wrote: If he can't copy/paste, I think he shouldn't even bother coding.
lol, i hear that . I probably copy/paste more than i type. Why, right now i just copy/pasted the text "copy/paste".
But this is getting too far off topic
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
If you can't highlight the few letters of a URL and click 'link' I think you shouldn't bother posting a URL. It's not wiping anyone's nose. It's being a responsible poster and I am astounded that someone has to "wipe your nose" and inform you of that. I wouldn't have bothered but I have noticed it more than once from you. Do you need someone to post an article here to show you how to do this ?
|
|
|
|
|
Rick York wrote: If you can't highlight the few letters of a URL and click 'link' I think you shouldn't bother posting a URL.
I ditto that. Posting a clickety isn't all that tough to do
|
|
|
|
|
In good forums I'm used to log in, when you post a URL, it is automatically parsed and made clickable. Perhaps a matter of forum settings, I don't know...
Kochise
In Code we trust !
|
|
|
|
|
Not long ago my company hired another software company to develop a tool for us, because we didn't have the resources to do it ourselves at that time. After they delivered several versions that were all buggy and did not work properly we took the code and I had to finish it. Some endless loops and horrible try { ... } catch { // do nothing here } later I discovered the following beauty in the code:
<br />
<br />
public bool AskForSureBox(string Message, string Title)<br />
{<br />
MessageBox.Show(Message, Title, MessageBoxButtons.YesNo);<br />
if (DialogResult.Yes.ToString() == "Yes")<br />
return true;<br />
else<br />
return false;<br />
}<br />
<br />
I afterwards took the liberty to write to the CEO of that company, asking him how long the programmer who wrote the code was already coding for his company...
Until today I didn't get an answer.
Have fun coding!
|
|
|
|
|
Thanks for sharing this beauty.
It has give me hope to crawl to the rest of my day
codito ergo sum
|
|
|
|
|
Optimus Chaos wrote: I afterwards took the liberty to write to the CEO of that company, asking him how long the programmer who wrote the code was already coding for his company...
Until today I didn't get an answer.
and let me guess, the person responsible is the ceo's favorite child.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
It was probably the CEO who wrote it!
|
|
|
|
|
Nah - CEO's only code in Excel.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Here is another good one
int a = 5;
if (a == a) {
a = a + 1;
}
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
Thanks for sharing that..I got one hell of a laugh outta it. Even my 16 y.o. non-programming son knew it was screwed.
Mike
Light travels faster than sound. That's why some people appear right until you hear them speak.
|
|
|
|