|
PIEBALDconsult wrote: Shows lack of clarity of thought
Or simple ignorance.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Or casting pearls before swine.
|
|
|
|
|
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I think maybe he didnt care about the difference
I think if I'd been starting out trying to do this I might have started the same way - expecting beginners in C# (ie me) to know why you wouldnt use convert, vs parse is probably not so important as getting the job done - make it work, then make it pretty. Maybe in a test case I'd have found out about how Convert handles (cough) nulls in input and gone 'hmmm, that'll need to change' - not sure the speed difference would be noticeble in the areas - batch processing - that I'd be using it
'g'
|
|
|
|
|
If he were doing VB I'd agree.
|
|
|
|
|
A parser isn't really applicable here: you can't exactly parse a string of digits into English...
|
|
|
|
|
Convert.ToInt32(N % p);
Use a cast.
There is only one useful method in Convert -- ChangeType. For all other uses for Convert, there are better alternatives.
|
|
|
|
|
|
Dan Sutton wrote:
Really? Convert's slow? Thanks!
Good luck ever finding a real application where that has even a measurable impact on performance though.
|
|
|
|
|
I didn't do one big enum because it's kind of a hack: if you look at the numbers I've made the things equal, it sort of corresponds to the values of my variables, so there's less screwing around to do: for example, the powers of ten thing is really the value of the iterator in the loop that's running through them...
|
|
|
|
|
What I would ask myself is:
Why did you re-invent the wheel? Was this good value for money for your employer? There are many many solutions available to do this (for free) on the interwebs.
Why did it need to be 'terse and fast' - surely better to be 'easily readable, debuggable and maintainable'?
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
Curmudgeon
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
Those who seek perfection will only find imperfection
nils illegitimus carborundum
me, me, me
me, in pictures
|
|
|
|
|
mark merrens wrote: Curmudgeonprofessional
ftfy
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
_Maxxx_ wrote: Curmudgeonprofessional Pompous ass.
That should do it.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
Those who seek perfection will only find imperfection
nils illegitimus carborundum
me, me, me
me, in pictures
|
|
|
|
|
|
Well f*** you
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
No sir, f*** you. I would suggest purchasing a sense of humor: you plainly lack one and are so far up your own ass I can't believe you can see well enough to have written these posts. Have a nice day, twat.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
Those who seek perfection will only find imperfection
nils illegitimus carborundum
me, me, me
me, in pictures
|
|
|
|
|
mark merrens wrote: No sir,
Nice of you to call me Sir, anyway.
mark merrens wrote: would suggest purchasing a sense of humor: you plainly lack one
So you calling me a pompous ass is funny but me saying "f*** you" isn't? And you want me to get a sense of humour?
mark merrens wrote: so far up your own ass
I honestly don't see why you are having a go at me at all!
The OP said "at work today: I wrote something to take a number and convert it into English"
I asked "Why did you re-invent the wheel? Was this good value for money for your employer? There are many many solutions available to do this (for free) on the interwebs.
Why did it need to be 'terse and fast' - surely better to be 'easily readable, debuggable and maintainable'?"
which I feel is a fair and reasonable set of questions.
Later the OP pointed out that they are self employed and were writing for fun - which is fair enough and negates my questions.
In what way, then, is that pompous? In what manner does that show me to be up my own ass?
mark merrens wrote: Have a nice day, twat.
I have reported this post as abusive, as it clearly is.
feel free to report my 'f u' post as abusive if, for some reason, my short insult post cannot be amusing while yours can.
In the meantime, may I suggest you look around for a cheap, second hand sense of humour, and take a large chill pill?
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
I won't be so childish as to report you and I didn't say f*** you: that was your game. So, again, feel free to do one.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
Those who seek perfection will only find imperfection
nils illegitimus carborundum
me, me, me
me, in pictures
|
|
|
|
|
Because I felt like it. And I am my employer, so it was excellent value!
|
|
|
|
|
As a purely fun exercise it's the kind of thing I enjoy doing;
I don't think it was good financial value regardless as to who the employer was - although keeping the staff happy is equally important
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
Oh, yeah - I wouldn't bother unless I had a slow day: in this case, I did - it was purely for fun.
|
|
|
|
|
You had to go no further than our very own CP[^]
or I stole this from StuckOverflow...
public static string NumberToWords(int number)
{
if (number == 0)
return "zero";
if (number < 0)
return "minus " + NumberToWords(Math.Abs(number));
string words = "";
if ((number / 1000000) > 0)
{
words += NumberToWords(number / 1000000) + " million ";
number %= 1000000;
}
if ((number / 1000) > 0)
{
words += NumberToWords(number / 1000) + " thousand ";
number %= 1000;
}
if ((number / 100) > 0)
{
words += NumberToWords(number / 100) + " hundred ";
number %= 100;
}
if (number > 0)
{
if (words != "")
words += "and ";
var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
if (number < 20)
words += unitsMap[number];
else
{
words += tensMap[number / 10];
if ((number % 10) > 0)
words += "-" + unitsMap[number % 10];
}
}
return words;
}
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
Yeah - I thought about doing it that way but it wasn't fun to write! I'm sure I overcomplicated it, but - whatever - I had fun!
|
|
|
|
|
|