|
I don't think I understand how this is a coding horror... I see this as a great learning experience. The more you learn the under-the-hood stuff, the better
|
|
|
|
|
Every coding horror might be considered a learning experience (assuming you learn from it). In this case, I think I learned patience. Doesn't make it any less horrific.
|
|
|
|
|
I agree; not much of a horror. I think its pretty cool actually Not that I'd prefer to do it over using a font, but it looks like you did a pretty good job of procedurally rendered text.
|
|
|
|
|
I did something similar long ago (around 1977): lots of measurements on electronic circuitry, getting automated using a PDP11 minicomputer (RSX11 operating system) and Fortran IV, and results plotted by an HP plotter lacking any (or any decent?) text output capability. So I did create a font, not as a giant switch statement, as a big table of strokes. The result was nice graphics (for that era at least) with labeled axes and legends.
|
|
|
|
|
Luc Pattyn wrote: table of strokes
Visited the massage parlor recently, eh?
Actually, I did something like that for my Cargobay game (listed on the same page as that Tetris game). I stored the game board as an array or something like that. I found that to be somewhat more reasonable than hardcoding the building of each game board.
Luc Pattyn wrote: 1977
They had computers then? I wasn't born for another 8 years.
|
|
|
|
|
aspdotnetdev wrote: They had computers then?
yes, that was the computer era. It ended in the eighties, when they introduced "PC's", which weren't computers at all.
They were a bit large; you could easily fit the content of your wardrobe in them without disturbing much; a 10MB (later 50MB) harddisk had the size of a modern dish washer.
And that was more than enough to drive a pen plotter and more.
|
|
|
|
|
Yup and if you wanted to use any Maths Libraries on a Prime Computer that I used, you had to grab the MathsLibrary, literally!
It was something a similar size to a drum in a washing machine and you had to screw it into the top of the computer. It did have a disk/human interface to make it more interactive, yeah ok it was just a plastic handle but it was bloody heavy with all those disk platters inside.
He took it all too far, but boy could he play guitar!
|
|
|
|
|
Sounds like you wrote some cool code. I suspect that it was a lot more work than simply using an available font.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
Hey, I don't see anything wrong with that. One of my first coding tasks at university was the other way round: a 'function plotter' that would take a function as input and 'draw' the graph on a text-only line printer using a 'resolution' of 132x66 characters (and using 'x' as pixels).
I later adapted this little gem to print out a two-dimensional representation of a four-dimensional simplex (four dimensional equivalent of a three dimensional 'cube' if you will). Ok, it was a bit hard to actually 'see' anything, but it worked
Now, if I still had the code (IIRC I let the stack of punch cards drop and eventually discarded them to save me the bother of sorting) I could try and combine it with yours to actually draw the 'x' characters that were meant to represent the pixels of what I wanted to draw.
|
|
|
|
|
It is portable, I'll give it that.
|
|
|
|
|
As some of you may know, I created a Tip/Trick recently about converting numbers to the word equivalent (523 to "Five hundred and twenty three"). With my tongue firmly rammed into my cheek, I suggested that a switch statement would be a good way to do it.
Well, it's Saturday, and I thought to myself "A switch has got to be faster than the proper way - I wonder how much faster?" So I thought I'd check.
I wrote and tested a proper version and used it to generate the Big Switch code I'd need, writing it to a text file "BigSwitch.cs". Then I could include this and do a side-by-side comparison. Initial testing of the "proper" way to do it suggested that one million iterations should test all code paths and eliminate cached jitter in the results.
So, I made my mistake. I double clicked on the "BigSwitch.cs" file I had created. VS2008 started to load it.
I'm still not sure if it would have suceeded; I killed the process after 30 minutes. Note to self: Do not attempt to load 82.7 Mb code fragments into VS again...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Indeed, just compile it at the command line.
|
|
|
|
|
I knew there was a simple solution!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I suspect that a Web service, backed by a database, might be worth a try...
|
|
|
|
|
OOO! Now there is an idea for the "Extra Credit" version - can I steal it?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
That's waaaaay over 9000 lines o_O
|
|
|
|
|
Two million and six, indented for readability!
(that may have contributed to the load time... )
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
To bad you don't get paid per line right?
|
|
|
|
|
I don't get paid on Saturdays anyway
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Maybe your app should have emitted IL code rather than C# code.
|
|
|
|
|
Luc Pattyn wrote: hould have emitted IL code
Good idea - but it would have defeated the purpose of the timing tests. I would have written the IL code as assembler: numeric index into jump table, or string pointer table maybe. I was more interested in how the compiler would handle the problem than I was in how I would handle it!
PiebaldConsult came up with an idea for a web service backed by a database, so I mocked up the database version (with a SqlCE DB) that works up to 1,000,000 - a total of a 92MB DB - it seems pretty fast and the code is pretty small. Do you think I should post it as a new Tip / Trick: "Numbers to words : the Extra Credit version"?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: it would have defeated the purpose
rather than write code, you should have read this then: Something You May Not Know About the Switch Statement in C/C++[^]. And if you are convinced C# may behave differently, it would deserve a real article.
OriginalGriff wrote: Do you think I should post it as a new Tip / Trick
Absolutely, a tip or article. And please include an SQL file with the data, so others can set up their own DB.
OriginalGriff wrote: Five hundred and twenty three
There seems to be one more issue that needs getting settled: should or shouldn't you use a hyphen in those inverted decimal-and-unit combinations? And if both are acceptable, how to let the user choose?
|
|
|
|
|
Luc Pattyn wrote: should or shouldn't you use a hyphen in those inverted decimal-and-unit combinations?
Thank you for pointing out this problem; you are indeed quite correct and there should be a hyphen between the tens digit and the units digit for all values between 21 and 99, excepting (of course) those integrally divisible by ten. This also applies to such numbers when considered as part of a larger number: "one thousand and sixty-seven" or "three hundred and fourty-eight thousand". In addition, there may be a comma between the magnitude indicator and the lesser value ("one thousand, three hundred and sixty-seven") although this is not compulsory (unless there is a decimal point in the number, in which case it should appear at each three digit position to the right of the decimal).
I had completely forgotten this point, and have modified the Tip / Trick accordingly. In my defence, it has been many years since I last wrote a cheque and thus any numbers as words! Even then, to exceed one thousand on a personal cheque was not an everyday occurrence...
I have corrected this, and provided credit as is only appropriate.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Thanks for the clarification, and of course the credit.
I didn't know at all about the thousands separators turning into comma's (and I hope you really mean "," and not "comma").
How about the ultimate edition, dealing with floating-point numbers? (could be double, float, decimal)
|
|
|
|
|
Luc Pattyn wrote: How about the ultimate edition, dealing with floating-point numbers?
I think that is the "Pro Ultimate Gold Team Edition for Workgroups Turbo CRXVI-DiD" due for simultaneous release with the "Hades Low Temperature Food Storage Conditions" application. The release date of the later is, unfortunately, beyond my control - but is estimated to be when Microsoft release a bug-free version of Visual Studio.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|