- Feature Articles
-
CodeSOD
- Most Recent Articles
- What a More And
- Hall of Mirrors
- Magical Bytes
- Contact Us
- Plugin Acrobatics
- Recursive Search
- Objectified
- Secondary Waits
- 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
But then you would have to make every number an object. You would have to abolish the idea of a primitive. That would create substantial performance issues.
Also, the Number object would then have to be extensible. But that could create issues. There are reasons why Sun made String, Integer, Double, etc final. For example, if you could extend them, you could break immutability.
If there was a really good reason to abolish primitives, maybe we would just accept these drawbacks as the price we have to pay for all these good benefits. But the only reason I've heard so far is "to uphold the goal of maintaining OOP purity". Why is this even a goal, nevermind the overriding goal that must supersede all other considerations?
I agree that OOP is a great idea. But just because a tool proves useful in some contexts doesn't mean that we should now use this tool all the time and all other tools must be thrown away. The hammer is a great tool. I use hammers all the time. But I don't declare that because hammers have proven so useful at putting in nails, that therefore all jobs must now be done with a hammer. All screwdrivers must be thrown away because they are not hammers. What, you say that for this job a screwdriver is more useful than a hammer? I don't understand: You just agreed a momemt ago that hammers are good. Are you now saying that hammers are not good? Look, all the professional carpenters agree that hammers are good. Read any book on carpentry and I'm sure it will explain how useful hammers are. Therefore, for you to say that you will use a screwdriver for this job and not a hammer proves that you don't know anything about carpentry.
Admin
I checked, sadly this is not from Open Office, at least not in version 3.2.1 ...
Admin
dec2Alpha(5): b=5/26 => 0 c=5%26 => 5 => 3rd if-clause, add "E" to the array a=b => 0, loop ends dec2Alpha(31): b=31/26 => 1 c=31%26 => 5 => 3rd if-clause, add "E" to the array a=b => 1, loop ends dec2Alpha(681): b=681/26 => 26 c=681%26 => 5 => 3rd if-clause, add "E" to the array a=b => 26, loop ends dec2Alpha(707): b=707/26 => 27 c=707%26 => 5 => 3rd if-clause, add "E" to the array a=b => 27, loop again b=27/26 => 1 c=27%26 => 1 => 3rd if-clause, add "A" to the array a=b => 1, loop ends
Admin
Sorry, my indentations didn't carry over correctly.
Admin
Admin
Ooooooooh, "FINAL" class! Like I'd want to inherit that mung anyway.
Admin
They should be killed first, just to be sure.
Admin
CodeNazi? That You?
Oh, the horrors of lines and lines of identical snippets written in your quest to rid the world from unpure code, limited only by the compilers long death march when optimizing and merging stack frames.
Admin
You seriously don't get it dude. It's not a stark choice between repeating snippets all over the place versus a utility "class" (sneer quoted because objects should have STATE).
The middle ground is turning that generic utility function into a method in a well-designed object model, preferably (1) of a class that has the arguments already supplied by its members and (2) is near in location to the classes that consume the method.
I have NEVER needed a utility "class".
Let me rephrase my point in the form of a couple questions:
Why are you performing the same types of processing in totally different classes within a project?
Should every component of a car have an alternator?
Admin
Now I know my array-B-C's, next time won't you code with me?
Admin
Admin
Anyway, since auto-boxing introduced in 1.5, it's already less of a concern for the programmer. Sun^H^H^HOracle could just go the extra mile and normalise the primitive/class discrepancy.
Admin
You mean like
// test for letter A if ($letter eq "A") { return 1; }
// test for letter B if ($letter eq "B") { return 2; }
;)
Admin
Admin
Actually alot start with neither 1 nor 0 but "G".
Admin
Hmm, so you want to deliberately write inefficient code and rely on the compiler to figure out how to refactor your code to make it efficient?
Autoboxing in no way solves any efficiency problems. It creates problems, by allowing a programmer to be sloppy about when he uses a primitive and when he uses an object. I recently came across this line of code:
i.e. the programmer parsed a String into a Double object, and then extracted the double primitive from it, and then autoboxing turned it back into an object. If he had just written
he would have gotten the same result without creating an object, throwing it away, and then creating a new one. Without autoboxing, he would have gotten a compile error and quickly figured out the problem. Personally I think it was a mistake to add it to the language. Maybe this case is simple enough that a compiler could optimize it, but there are limits to how smart the compiler can be.
I have nothing against optimizing compilers, but I don't see any reason in deliberately making it hard on the compiler.
Admin
Array of Alphabet Letters -> ARR ALPHA LET
Important to work out exactly what it abbreviates, or you don't understand how bad the joke is.
Admin
I like the quasi-base concept. It would allow for numbers like 00101100110120011 in quasi-binary, for instance. Freedom at last.
Admin
public static String toColumnName(int index) { Validate.isTrue(index >= 0, "The column index must be >= 0: " + index);
Admin
If we set the end condition to while( a!= 0 ); though we would not need the extra add at the end or the second Z in the array. The first Z should be there though as it is the correct value to add when c is 0, i.e. when the number is divisible by 26.
If we handled the special case of 0 before we loop too we would not need the special case we must check every time we loop that b and c are both 0.
We also do not need b at all. Just a /= NUM_LETTERS will do, and we can use the input number for this too, we don't need to copy it.
Admin
Or you could use something efficient, like this:
Admin
So do you hire the ones who point out to you that, according to your code, the column YZ is followed not by ZA but by AAA?
The subtely of the integer -> excel column encoding (which the original code also misses, along with a bunch else) is that the bottom "digit" is base 26 (A,B,C ... Z) while the upper ones are base 27 (<nothing>,A,B,C ... Z). A is only equivalent to 0 in the bottom digit, but equals 1 in the upper ones, and 0 is taken by <nothing>. You halfway got the problem, in that you subtract 1 before you encode the upper digits. But that means that your upper digits will end at Y, not Z.
Admin
Admin
Good lord! the constants 65 straight into code! You assume ASCII or Unicode: What if 'A' isn't at 65? Better yet, what if the enumeration isn't ordered?
Plus, efficiency? Perhaps runtime efficiency, good luck maintaining that, programmer time is much more expensive than computer time!
Admin
No reason other than seeking to master the paradigm, that is. But who wants to be extremely good at what they do?
Admin
What an idealistic theory you have. The problem I see with it is that only expert programmers know the proper balance between form and pragmatism. Very often, a good object model is the best way to go in a business sense, rather than a spaghetti bowl of functions tightly bound to each other, because it makes adding additional layers of abstraction feasible.
Admin
I think you're missing my context. That was aimed at functional programming zealots and OOD/design pattern purists. I'm actually a big fan of class models especially for DRY purposes. I also don't like procedural programming excpet for the most trivial of applications. That being said, I will choose the pragmatic route over esoteric attempts at forcing a pardigm.
Admin
However, more of a problem than it being poorly coded is that the name gives absolutely ZERO indication that it does base26 conversion!
Admin
It is you who has failed to fully understand what an acronym is.
An ancronyn is a initialism that can be spoken as a word
Examples: NASA, NATO, OPEC
An abbreviation is an initialism where each letter is pronounced separately
Examples: USA, UK, QED
Admin
Actually, I know why that Z is there at the beginning. It's so whatever's using this doesn't have to do fancy modulus arithmetic to access Z when it's pointing at A. Or something like that.