• (cs) in reply to Joost_

    Original Post:
    An Order vector or a vector of Order vectors...  Or a standard Error vector.

    Why stop there?  You could return a vector of vectors of order vectors, or a vector of error vectors...

    This could change the world!

  • (cs) in reply to kedge
    Anonymous:

    This excerpt from the book description says it all:

    "best practices" for reusable component design illustrated in Visual Basic.
  • (cs) in reply to MVP
    Anonymous:
    Nope, first cast is needed.  The orderVector.get(4) call returns an Object, NOT a String.  Polymorphism doesn't apply in this case.  Java doesn't know it's a String until it is casted.  Even if that object is technically a String, not casting it will force Java to call Object's equals() method, not String's equals() method. 


    Wow!  I'm just waiting to see you're code posted here.  You apparently have no concept of polymorphism.

    The String class overrides the Object.equals(Object) method.  It doesn't matter whether the reference is of type Object or of type String the method of the underlying class is called.  In this case if the referenced object is of type String the String.equals(Object) method will be called.

    Notice that the equals method of the String class takes as a parameter and Object not a String.  This is overriding a method.  This is polymorphism.

    If the Vectory returned a reference to an object of type Foo and Foo had overriden the equals(Object) method then the method on Foo would be called.

    Please note the capitalization of the word Object vs. the word object as the first is a reference to the type and the latter is a reference to a generic thing.
  • (cs) in reply to kipthegreat

    kipthegreat:
    MVP:
    Nope, first cast is needed.  The orderVector.get(4) call returns an Object, NOT a String.  Polymorphism doesn't apply in this case.  Java doesn't know it's a String until it is casted.  Even if that object is technically a String, not casting it will force Java to call Object's equals() method, not String's equals() method. 

    Nope, it's not.

    Try this if you don't believe me:

    public class WtfClass {
      public static void main(String[] args)
      {
        Object obj = new String("wtf");
        String str = new String("wtf");
       
        if (obj == str)
          System.out.println("They are the same object!");
        else if (obj.equals(str))
          System.out.println("They dot-equal each other!");
        else
          System.out.println("No relation!");
      }
    }

    You'll get "They dot-equal each other!" printed out.

     

    erm, correct me if im wrong, but didnt what you just write agree with what the guy you quoted said?

    the code in question used '=' for the assignment, instead of '.equals()', and therefore not work?

  • (cs) in reply to joe
    Anonymous:
    WTF!! um ok.... since when ? Polymorphism always applies. try this.

    public class test {

    public static void main(String[] args) { java.util.Vector v = new java.util.Vector(); v.add( "wtf");

    if( v.get(0).equals( "wtf") ) { System.out.println("yeah for polymorphism!"); } } }



    I get "yeah for polymorphism".
    This is the whole idea behind polymorphism.  It will always call the method in the real class, not in the type that the variable references.  If this weren't the case, how would it call any class that implemented an interface?

  • (cs) in reply to kipthegreat
    kipthegreat:
    MVP:
    Nope, first cast is needed.  The orderVector.get(4) call returns an Object, NOT a String.  Polymorphism doesn't apply in this case.  Java doesn't know it's a String until it is casted.  Even if that object is technically a String, not casting it will force Java to call Object's equals() method, not String's equals() method. 

    Nope, it's not.

    Try this if you don't believe me:

    public class WtfClass {
      public static void main(String[] args)
      {
        Object obj = new String("wtf");
        String str = new String("wtf");
       
        if (obj == str)
          System.out.println("They are the same object!");
        else if (obj.equals(str))
          System.out.println("They dot-equal each other!");
        else
          System.out.println("No relation!");
      }
    }

    You'll get "They dot-equal each other!" printed out.


    That's true.... you don't need the first cast


  • java guy (unregistered) in reply to DiamondDave

    MVP, are you a "star developer"?

  • rbrendler (unregistered) in reply to Adonoman

    Adonoman:
    Looks like someone spent too much time using LISP, or Perl, or worse... APL

    Aaaargh!  APL?!  I still occasionally wake up in a cold sweat curled into fetal position, thinking about programming APL...

    My first job out of school was writing scripts for StatGraphics using APL.  The entire language was a WTF...

  • Nicolas (unregistered) in reply to gtllama
    Anonymous:
    Anonymous:
    So basically, we eschew all sense of strongly typed objects or even run-time binding, such as referencing an object by property name, and end up with Vector Pepper.


    Order Vector, Error Vector
    I'm a Vector, He's a Vector
    Wouldn't you like to be a Vector, too?



    Order Vector, Error Vector ... Vector Vector duck ...
    I'm a Vector, He's Vector, mushroom cheescake Vector ... :p


    isn't it blatantly obvious that a "key => value" pair mechanism (struct, associative array, dictionary...) lends itself much better than a vector for kind of data that gets passed around ...
  • (cs) in reply to MVP

    It's funny how the first phrase kind-of sounds like a Composite pattern implementation gone very bad

  • Torajirou (unregistered) in reply to Ralph
    Anonymous:

    That is awesome.

    <font size="2">

    object DoEverythingConceivable(string whatToDo, object whatToDoItWith)

    </font>


    dammit'

    this contract is due tomorrow morning, and I've only covered half of it yet...
  • Otto (unregistered)

    Sweet merciful god, somebody get this man a HashMap!

    Then it would still be a WTF, but at least it would be a self-documenting WTF. [:P]

  • Kiss me, I'm Polish (unregistered) in reply to Otto

    Peter Piper picked a peck of pickled vectors.
    Round the ragged rocks the rat... dooorgh!
    Whaaat? What do you say? I don't understand you, speak Java!
    Ooh you think you're so good! "Look at me! I don't need vectors!"
    SHUTUP!

  • (cs) in reply to kipthegreat
    kipthegreat:

    Well you're almost right, but the first cast is unneeded (polymorphism takes care of it).  So it simplifies down to this:
    poNumber = ((orderVector.get(4).equals("shipped"))?(String)orderVector.get(6):(String)orderVector.get(5));


    You're not using the ? : operator to its full potential there.

    (String)orderVector.get(orderVector.get(4).equals("shipped") ? 6 : 5);
  • ebaur (unregistered) in reply to Ralph
    Anonymous:

    That is awesome.

    <font size="2">

    object DoEverythingConceivable(string whatToDo, object whatToDoItWith)

    </font>


    Of course, there's the Objective-C method: invoke:withObject:

    ex:
    [objectOne invoke:@selector(someMethod:) withObject:object2];

    For better or worse, this allows you to call any method on an object with any (single) parameter through the runtime and completely avoid compile-time checking.  ("With great power comes great responsibility.")
  • (cs) in reply to Ralph
    Anonymous:

    That is awesome.

    <FONT size=2>

    object DoEverythingConceivable(string whatToDo, object whatToDoItWith)

    </FONT>
     
    Hey you just stole the secret technology my previous employer used everyday [:D][:D][:D]
  • (cs) in reply to Otto
    Anonymous:

    Sweet merciful god, somebody get this man a HashMap!

    Then it would still be a WTF, but at least it would be a self-documenting WTF. [:P]



    Or, better yet, an "Order" object
  • (cs) in reply to Joost_
    Joost_:
    Would they have had utility functions that make life easier when dealing with this function?
    The program is all set for any command-line utilities written in any language.  And it's all set for being devolved into utilities which accept command-line parms.

    Whether that's a good thing is another debate.  What's less debatable is that common practice recommends validating input data and placing it into internal data structures upon entry.
  • Orthanc (unregistered) in reply to Whackjack
    Whackjack:
    Anonymous:
    WTF!! um ok.... since when ? Polymorphism always applies. try this.

    public class test {

    public static void main(String[] args) { java.util.Vector v = new java.util.Vector(); v.add( "wtf");

    if( v.get(0).equals( "wtf") ) { System.out.println("yeah for polymorphism!"); } } }



    I get "yeah for polymorphism".
    This is the whole idea behind polymorphism.  It will always call the method in the real class, not in the type that the variable references.  If this weren't the case, how would it call any class that implemented an interface?


    I suspect the confusion comes from the fact that:

    class Test {
        void print(Object o) {
           System.out.println("Object");
        }
        void print(String s) {
           System.out.println("String");
        }
        public static void main(String[] args) {
           Object o = "bob";
           new Test().print(o);
        }
    }

    Prints out "Object" becuase overloading uses reference type where as overridding uses the runtime type.

  • (cs) in reply to DiamondDave
    DiamondDave:
    Anonymous:

    Sweet merciful god, somebody get this man a HashMap!

    Then it would still be a WTF, but at least it would be a self-documenting WTF. [:P]



    Or, better yet, an "Order" object


    Can't do that. Too unflexible. What if you want to use the same program to do a totally different job? You have to start over writing a new program, while the clever guy just changes 250000 parameters to adjust the program (of course, he would then ask you to slightly adopt the specification for the new program, so it matches what he can actually deliver...)
  • Nikolas (unregistered) in reply to Goplat
    Goplat:
    kipthegreat:

    Well you're almost right, but the first cast is unneeded (polymorphism takes care of it).  So it simplifies down to this:
    poNumber = ((orderVector.get(4).equals("shipped"))?(String)orderVector.get(6):(String)orderVector.get(5));


    You're not using the ? : operator to its full potential there.

    (String)orderVector.get(orderVector.get(4).equals("shipped") ? 6 : 5);


    or with a bit of 'pepper' for the maintainer:
    poNumber = (String)orderVector.get(5 + ((!orderVector.get(4).equals("shipped")) ? 0 : 1));

    putting it this way we even get a nice smiley at the end of the line.
    the one with the '5' as a mouth looked kind of grumpy with my font...
  • (cs) in reply to Otto
    Anonymous:

    Sweet merciful god, somebody get this man a HashMap!

    Then it would still be a WTF, but at least it would be a self-documenting WTF. [:P]



    Tried that, doesn't make it better.

    Vector:
    poNumber = ((orderVector.get(4).equals("shipped"))?orderVector.get(6):orderVector.get(5))

    HashMap:

    poNumber = ((orderMap.get(new Long(4)).equals("shipped"))?orderMap.get(new Long(6)):orderMap.get(new Long(4)))

    ;-)


  • (cs) in reply to kedge
    Anonymous:


    This book looks mega-scary.  The first line of the abstract is enough to convince me every copy should be collected and incinerated, and the authors terminated with extreme prejudice: "Suitable for any project manager or VB software professional willing to think outside the proverbial box." 
  • (cs) in reply to HitScan
    HitScan:
    Not until the vector of vectors has 18 vectors in it. You'll also get a vector of vectors of vectors of vectors if you have more than 18 vectors of vectors of vectors. Truly, 18 is a magical number.
    <font size="5">A</font>t least it is always 18 and not a different number for each level.
  • Richard C Haven (unregistered) in reply to Ralph
    Anonymous:

    That is awesome.

    <font size="2">

    object DoEverythingConceivable(string whatToDo, object whatToDoItWith)

    </font>


    Damn. Now everyone knows...
  • maht (unregistered) in reply to Sean
    Anonymous:
    "Suitable for any project manager or VB software professional willing to think outside the proverbial box." 


    Those buffoons with their years of experience, I'll show them !
  • (cs)

    The goggles actually worked this time. 

    I would love to see how you would promote this sort of software:

    "OOP is handicapped by strict class types that force you to actually plan your projects out and think about what you want to do - tired of those wasted minutes of planning?  Let VOP set you free!"

  • (cs) in reply to kedge

    I'm more than a little concerned by this review of the book by "kzadora":

    ...the author really hates strong typing and recommends reducing the interface of _all_ your classes to just 3 members: "Item", "Ref" and "Action". This is bizarre.

    Damn right it's bizarre! So I take it that the author only ever uses one class called Foo. Then if you want an order, you'd use:

    order = new Foo("order")
    order.action("add", "some acme product")
    etc

    Another reviewer comments:

    The author describes separating the application from the architecture, and while I've done this before in software on several levels, I never considered removing the application completely from the compiled software and driving application behavior from what the author calls "external structural and behavioral metadata".

    So I take it that the author has only ever written one application, that concievably does everything he could ever want. None of this using Excel to edit spreadsheets, Windows as an operating system and NetBeans as an IDE. No instead you can simply use:

    mymagicapp -load operatingsystem.xml -load ide.xml myjavaproject.xml -load spreadsheets.xml financereport.xml -edit financereport -set cell -address 1,1 -value $123.45 -build myjavaproject -run myjavaproject .....

    WTF?!

  • (cs) in reply to MVP
    Anonymous:
    Actually, in Java you need to cast everything coming out of a Vector (since Vectors store Objects).
    Uhm, yeah, where were you when they introduced generics in Java 1.5? Where were all of you? The real WTF on this site is that most of the people posting have no idea what the hell they're talking about.

    Yeah, I know, "not everybody uses Java 1.5," but nobody here has even suggested the possibility.

  • (cs) in reply to John Hensley

    Lisp actually is OO thanks to CLOS. Also, pure functional is easy to debug. Find the misbehaving function in a test case, and its the same as at runtime.

  • (cs) in reply to SerajewelKS
    SerajewelKS:
    Uhm, yeah, where were you when they introduced generics in Java 1.5?
    Or, rather, where was my brain when I read the method signature?

    foot.action("put", "in mouth")

  • Runtime Error (unregistered) in reply to paddy
    paddy:
    The goggles actually worked this time. 

    I would love to see how you would promote this sort of software:

    "OOP is handicapped by strict class types that force you to actually plan your projects out and think about what you want to do - tired of those wasted minutes of planning?  Let VOP set you free!"


    "Tired of watching your programmers daydream instead of typing? Are your programmers wasting valuable time THINKING when they should be WORKING.  VOP eliminates the drudgery of design from programming and makes producitivity soar.  Watch typing rates and LOC counts go through the roof."
  • (cs) in reply to Josh

    Actually, true VOPness requires that we must observe the cardinal rule of unification: "An implementation containing two vectors can often be replaced by one where a third vector is employed to contain them."   Of course, hard-core VOPers will surely apply this rule recursively.

    Hence we would have:

    <font>/**
    *
    * the "vector" argument initially contains one a single vector that contains one
    * or more parameter values. The result vector, from the operation is set as the
    * second element of "vector". If there was an error retrieving the Order, then a
    * standard Error vector is used as the result. (see docs)
    *
    * @param vector vector of vector of input
    */</font>
    <font>public</font> void getSetOrder(Vector vector)
    {
    ...
    }

  • Bob (unregistered) in reply to Runtime Error

    Aren't there relational databases for this sort of thing?

  • risk (unregistered) in reply to MVP
    Anonymous:
    Actually, in Java you need to cast everything coming out of a Vector (since Vectors store Objects).  So really, it is something like:

    poNumber = ((((String)orderVector.get(4)).equals("shipped"))?(String)orderVector.get(6):(String)orderVector.get(5));



    Wouldn't (String)orderVector.get(4) mean casting the vector to a String, instead of the object returned by get(4)? Perhaps I've gotten too comfortable with generics already, but I thought the cast was (String)(orderVector.get(4)) or simply (String) orderVector.get(4) (note the space).
  • (cs) in reply to Disgruntled Lisp guy
    Anonymous:
    Funny, the code that I was working on 5 minutes ago looks kind of like that, but in Lisp.

    Little bits like "(setf result (seventh (first obj)))" make maintenance fun by turning it into a scavenger hunt!


    Erm... you do know Lisp has property lists, right?

  • (cs) in reply to Torajirou
    Anonymous:
    Anonymous:

    That is awesome.

    <font size="2">

    object DoEverythingConceivable(string whatToDo, object whatToDoItWith)

    </font>


    dammit'

    this contract is due tomorrow morning, and I've only covered half of it yet...


    Did the contract say anything about runtime? Just invoke a new universe each time (hardware is cheap).

    DoEverything Conceivable('Make my program work', Universe);
  • (cs) in reply to risk
    Anonymous:
    Wouldn't (String)orderVector.get(4) mean casting the vector to a String, instead of the object returned by get(4)? Perhaps I've gotten too comfortable with generics already, but I thought the cast was (String)(orderVector.get(4)) or simply (String) orderVector.get(4) (note the space).
    No, (Foo)bar.baz() is the same as (Foo)(bar.baz()), though either will work. If you want bar cast to Foo you need to do ((Foo)bar).baz()

    As for the extra space, you should know by now that in Java (and almost any C-like programming language) whitespace is ignored by the compiler, except when separating keywords from other keywords and identifiers, and (obviously) inside string contants, e.g. "private static" or "int foo" -- other than that it's purely aesthetic.

    public class Foo{public static void main(String[]args){System.out.println("Hello, World!"));}}

  • (cs) in reply to SerajewelKS
    SerajewelKS:
    public class Foo{public static void main(String[]args){System.out.println("Hello, World!"));}}
    Extra parentheses are, however, treated rather specially by the compiler.

    public class Foo{public static void main(String[]args){System.out.println("Hello, World!");}}

  • Juergen (unregistered) in reply to kipthegreat

    > poNumber = ((orderVector.get(4).equals("shipped"))?(String)orderVector.get(6):(String)orderVector.get(5));


    Well that is almost right. But come on, people! It MUST be "shipped".equals(orderVector.get(4)) ! We do not like NullPointerExceptions, do we.

  • Priit (unregistered) in reply to loneprogrammer

    At least the Order data isn't stored in a String with '|' characters between the data.
    Nobody would ever be dumb enough to do that.

    ...

    I wish I was joking.


    Unoftunately I have seen that kind of thing in a database.  Yes. Lots of tables that had only one column and data was separated with a "|" character.

    I was told to do some modifications to the software.  I kindly refused ;)

  • (cs) in reply to SerajewelKS
    SerajewelKS:
    Anonymous:
    Actually, in Java you need to cast everything coming out of a Vector (since Vectors store Objects).
    Uhm, yeah, where were you when they introduced generics in Java 1.5? Where were all of you? The real WTF on this site is that most of the people posting have no idea what the hell they're talking about.

    Yeah, I know, "not everybody uses Java 1.5," but nobody here has even suggested the possibility.

    Do you see any indication that this program uses generics? I would expect Vector<String> somewhere, but maybe it's just me.
  • (cs) in reply to lamborghini
    Anonymous:

    That is awesome.

    <font size="2"> </font>

    <font size="2">object DoEverythingConceivable(string whatToDo, object whatToDoItWith)</font>



    I think we've just struck gold here folks! An anonymous coward has submitted a whole line from the mythical DoWhatIMean.java class file. Obviously there are still a few more steps to go, but I think we're well on our way to solving some core problems in computing with this one:

    public interface DoWhatIMean {
        public static void doEverythingConceivable(String task, Object tool);
    }

    The implementation is trivial. I leave it as an exercise to the reader...

  • (cs) in reply to ithika

    Spatial Application Design.

    I love it!

    Multi-dimensional programming!

    Programming the Universe, one String at at time!

  • (cs) in reply to loneprogrammer
    loneprogrammer:
    At least the Order data isn't stored in a String with '|' characters between the data.

    I've seen improved versions of that scheme. Data stored with ~ delimiters for rows and | delimiters for columns. This way you get a nested table functionality for free!
  • digitissimo (unregistered)

    Now replace getSetOrder with ExecuteDataTable() and Vector with DataTable and you'll get similar example of the same principle, but implemented by Microsoft in .NET framework.

    And you know what? Sometimes novice developers are trying to justify they shitty code by saying "But look at Microsoft, they are doing the same as me! Why shouldn't we adhere to the industry's best practices?"

  • (cs) in reply to digitissimo
    Anonymous:

    Now replace getSetOrder with ExecuteDataTable() and Vector with DataTable and you'll get similar example of the same principle, but implemented by Microsoft in .NET framework.

    And you know what? Sometimes novice developers are trying to justify they shitty code by saying "But look at Microsoft, they are doing the same as me! Why shouldn't we adhere to the industry's best practices?"



    There is a big difference here. Unlike those clever VOP programmers, MS doesn't know what data the users of this class will want to store in it.
  • TrueLogic (unregistered) in reply to its me
    its me:

    VB 6.0 and earlier used to have (something like) this, it was called "Variant" datatype. Highly prone to runtime errors, and often a PITA to debug. The .NET platform did away with it for good reason....


    Sorry I couldn’t disagree more, this is the same logic that makes people think that a program compiling without errors is the same thing as a program working.

    <!--[if !supportEmptyParas]--> <o:p></o:p>

    Variant data types are not prone to runtime errors, sloppy programmers using variant data types are. Strong typing is a needless psychological safety net, it slows development and doesn’t really help develop functional software, it just helps create syntactically correct code.  Why to you think we are seeing an increase in the number of loose typed or untyped languages.

    <!--[if !supportEmptyParas]--> <o:p></o:p>

    VB.NET is a monolithic development tool and is often far too cumbersome for the job. VB6 on the other hand was the screwdriver of the programming toolkit, not always the right tool for the job, but sometime you just need a screwdriver.

    <!--[if !supportEmptyParas]--> <o:p></o:p>

    <span style="font-size: 12pt; font-family: "Times New Roman";">There is a lot of snobbery about VB, because it put programming in the hands of the amateur some people thought everybody using it had to be an amateur.

  • (cs) in reply to Ralph
    Anonymous:
    loneprogrammer:
    Anonymous:

    That is awesome.

    <font size="2"> </font>

    <font size="2">object DoEverythingConceivable(string whatToDo, object whatToDoItWith)</font>



    <font size="-0"><font size="2">DoEverythingConceivable("go to hell", handbasket);</font></font>

    I don't think that would ever return.



    Welcome to the world of the novice Perl programmer...
  • Davor (unregistered) in reply to its me
    its me:

    VB 6.0 and earlier used to have (something like) this, it was called "Variant" datatype. Highly prone to runtime errors, and often a PITA to debug. The .NET platform did away with it for good reason....

    Delphi had that monstrosity as well.... I dont know if still does.

Leave a comment on “Vector Oriented Programming”

Log In or post as a guest

Replying to comment #:

« Return to Article