• Jay (unregistered) in reply to Remy Porter
    Remy Porter:
    Jay:
    So let's say we agree that we're going to abolish the Math class as anti-OOP. Now in a program you discover that you need to calculate a square root. How will you implement a square root calculation?

    Obviously, it should be a method on the Number base-type. I shouldn't need to implement anything- a common function like that should be built into the type, not in an ancillary class.

    Now, if I had something domain specific, it would behoove me to implement my own child of the number type that had that method, although the "ideal" solution, for certain values of "ideal", would be to use the built-in language functionality to inject methods into higher levels of the inheritance tree.

    I can't speak to Java, but I know .NET, Ruby, JavaScript, and likely many other languages, have the ability to say, "Hey, put this method in the Number type, even though I don't have access to that type's definition."

    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.

  • Youngbull (unregistered) in reply to Mad Adder

    I checked, sadly this is not from Open Office, at least not in version 3.2.1 ...

  • nerfer (unregistered) in reply to Cbuttius
    Cbuttius:
    ok now for my PROPER review of the code. :
            do {
                b = a / VALUE;
               final int c = a % VALUE;
                if (c == 0 && b == 0) {
                    arrResult.add(0, "0");
    
    This will happen only if number was originally 0.
                } else if (c == 0 && b != 0) {
                    b = b - 1;
    
    :
                a = b;
            }
            while (a > VALUE);
    
        if (a != 0) {
            arrResult.add(0, ARRALPHALET[a]);
        }
    
    Okay, so I think the parts I left show that the highest multiple of 26 won't be converted? Consider these 4 input values:

    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

  • nerfer (unregistered)

    Sorry, my indentations didn't carry over correctly.

    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
    
  • Ouch! (unregistered) in reply to nerfer
    nerfer:
    Cbuttius:
    ok now for my PROPER review of the code. :
            do {
                // snip
            }
            while (a > VALUE);
    
        <b><span style="color:red;">if (a != 0) {
            arrResult.add(0, ARRALPHALET[a]);
        }</span></b>
    
    Okay, so I think the parts I left show that the highest multiple of 26 won't be converted? Consider these 4 input values:

    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

     a != 0 => add "A" to the array
    
    dec2Alpha(681): b=681/26 => 26 c=681%26 => 5 => 3rd if-clause, add "E" to the array a=b => 26, loop ends
     a != 0 => add "Z" to the array
    
    etc.
  • (cs)

    Ooooooooh, "FINAL" class! Like I'd want to inherit that mung anyway.

  • (cs) in reply to vydf
    vydf:
    JdFalcon04:
    The beginning "Z" value in the array is likely so that A maps to 1 instead of 0. I was honestly taught to do things like this in a business "programming" class that a few of us Comp Sci majors took for a laugh. Apparently 0-based values are MUCH more confusing than 1-based ones.

    People teaching this should be fired. Out of a cannon into the sun.

    They should be killed first, just to be sure.

  • Karl (unregistered) in reply to veniam
    veniam:
    A Util class is not object-oriented. Try to define its responsibility. If you write "it's supposed to hold everything that doesn't fit elsewhere" and compare that to other classes' responsibilities, you'll see that you have a beast that should be killed.

    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.

  • (cs) in reply to Karl
    Karl:
    veniam:
    A Util class is not object-oriented. Try to define its responsibility. If you write "it's supposed to hold everything that doesn't fit elsewhere" and compare that to other classes' responsibilities, you'll see that you have a beast that should be killed.

    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.

    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?

  • (cs)

    Now I know my array-B-C's, next time won't you code with me?

  • Dirk (unregistered) in reply to Mike D.
    Mike D.:
    If it doesn't manipulate the object, it doesn't need to be in the object. So a 'Util' class makes no sense unless you're creating 'Util's.
    Umm... so if I call Convert.ToInt32(s) I'm a preacher wanting to make some "Convert's"?
  • (cs) in reply to Jay
    Jay:
    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.
    Don't we have a (just-in-time) compiler for that? The Java compiler does funky things with the String class (a string literal automagically becomes an instance of the String class), so it could do the same things with primitives and their types/classes.

    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.

  • (cs) in reply to Cbuttius

    You mean like

    // test for letter A if ($letter eq "A") { return 1; }

    // test for letter B if ($letter eq "B") { return 2; }

    ;)

  • nerfer (unregistered) in reply to Ouch!
    Ouch!:
    nerfer:
    Cbuttius:
    ok now for my PROPER review of the code. :
            do {
                // snip
            }
            while (a > VALUE);
    
        <b><span style="color:red;">if (a != 0) {
            arrResult.add(0, ARRALPHALET[a]);
        }</span></b>
    
    Okay, so I think the parts I left show that the highest multiple of 26 won't be converted? Consider these 4 input values:

    dec2Alpha(31): b=31/26 => 1 c=31%26 => 5 => 3rd if-clause, add "E" to the array a=b => 1, loop ends

     a != 0 => add "A" to the array
    
    Doh! I don't know why I didn't see that. So the code's not extra buggy (other than not handling negatives), just a rather obtuse way of doing things. Thanks.
  • Dan G. (unregistered) in reply to Adam

    Actually alot start with neither 1 nor 0 but "G".

  • Jay (unregistered) in reply to Severity One
    Severity One:
    Jay:
    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.
    Don't we have a (just-in-time) compiler for that? The Java compiler does funky things with the String class (a string literal automagically becomes an instance of the String class), so it could do the same things with primitives and their types/classes.

    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.

    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:

    Double amount=new Double(sAmount).doubleValue();
    

    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

    Double amount=new Double(sAmount);
    

    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.

  • Steve (unregistered) in reply to pallen

    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.

  • (cs) in reply to Pierre Tramo
    Pierre Tramo:
    this is a relatively minor WTF compared with the poor implementation of quasi-base26 encoding.

    I like the quasi-base concept. It would allow for numbers like 00101100110120011 in quasi-binary, for instance. Freedom at last.

  • for is not while it is for (unregistered) in reply to eporter

    public static String toColumnName(int index) { Validate.isTrue(index >= 0, "The column index must be >= 0: " + index);

    	StringBuilder buf = new StringBuilder(5);
    	while(index >= 0)
        {
    		buf.append((char) ('A' + (index % 26)));
                index = index / 26 - 1;
    	}
    
    	return buf.reverse().toString();
    }
    
  • (cs)

    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.

  • Kevin (unregistered)

    Or you could use something efficient, like this:

        public static String intToXLCol(int index) {
          return (--index <= 25) ? ""+(char) (65+index):intToXLCol(index/26)+(char)(65+(index%26)) ;
          }
    
  • hire me? (unregistered) in reply to eporter

    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.

  • (cs) in reply to veniam
    veniam:
    A Util class is not object-oriented
    So what? OOP is a useful tool, but that's no reason to make a religion of it.
  • Matt (unregistered) in reply to Kevin
    Kevin:
    Or you could use something efficient, like this:
        public static String intToXLCol(int index) {
          return (--index <= 25) ? ""+(char) (65+index):intToXLCol(index/26)+(char)(65+(index%26)) ;
          }
    

    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!

  • (cs) in reply to Iago
    Iago:
    veniam:
    A Util class is not object-oriented
    So what? OOP is a useful tool, but that's no reason to make a religion of it.

    No reason other than seeking to master the paradigm, that is. But who wants to be extremely good at what they do?

  • (cs) in reply to frits
    frits:
    We've got a bunch of ivory tower crap going on here today. To me, programming is a means to an end. Doing it in a simple, pragmatic manner trumps theoretical ideals. Always.

    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.

  • (cs) in reply to hoodaticus
    hoodaticus:
    frits:
    We've got a bunch of ivory tower crap going on here today. To me, programming is a means to an end. Doing it in a simple, pragmatic manner trumps theoretical ideals. Always.

    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.

    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.

  • Craig (unregistered) in reply to MOD26
    MOD26:
    It's just a conversion to base 26 poorly coded.
    I'll take your word for that; cba to figure it out for myself.

    However, more of a problem than it being poorly coded is that the name gives absolutely ZERO indication that it does base26 conversion!

  • Anon (unregistered) in reply to anon

    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

  • Freyaday (unregistered)

    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.

Leave a comment on “The Arralphalet”

Log In or post as a guest

Replying to comment #:

« Return to Article