• (cs) in reply to Fast B

    You have to use BBCode, but then, like breaks don't seem to work either. (Also, that posting on this forum has no Preview button, though I'm pretty sure its built-in.)

  • (cs) in reply to qiguai

    His colleagues at Bell Labs were sometimes equally unimpressed

    to quote Bjarne :

    "A notable exception to this agreement was Doug McIlroy, who stated that the
    availability of exception handling would make systems less reliable because
    library writers and other programmers will throw exceptions rather than try
    to understand and handle problems. Only time will tell to what extent Doug's
    prediction will be true."


    On Thu, 20 May 2004, Rob Pike wrote:
    > when ken and i described the new features we were proposing for plan 9 C,
    > including inherited structure elements, to bjarne stroustrup, he said, "if you
    > want C++ you know where to find it." and stormed from the room.

    > i don't think he understood exactly why we were proposing these features.

    > -rob

    and to quote bj again (he really should come and read wtf) :

    >    "The C trick of having the declaration of a name mimic its use
    >    leads to declarations that are hard to read and write


  • (cs)

    This is a WTF even on its own terms. For maximum code reuse, fields should be Object, not String.

    <font color="#000099">public</font> <font color="#000099">class</font> Pair
    {
    <font color="#000099">public</font> <font color="#000099">int</font> PairID;
    <font color="#000099">public</font> Object<font color="#000099"></font> field1;
    <font color="#000099">public</font> Object field2;
    }

    <font color="#000099">
    </font>
    Anyway, to follow "best practices", where are the getters/setters?
  • (cs) in reply to zephc
    zephc:
    You have to use BBCode, but then, like breaks don't seem to work either. (Also, that posting on this forum has no Preview button, though I'm pretty sure its built-in.)

    Maybe you weren't here, but the preview button caused ten times as many wtf comments. I kinda miss all the html spews now. ;_;

    I'd love to meet the sap who has to come in and maintain a program with a complex algorithm punctuated by swarms of

    out.field3 = dict.field1 * dict.field5;

    See, I do it the PHP way, where with __get() and __set(), you can create a class that can define any variable, or even turn simple variable access into crazy functions. =D

    $class->keanu('whoa');
    $class->duck = '12';  // drop database
    $twelve = $class->mong;  // whatever duck was set to ends up here
  • (cs) in reply to foxyshadis
    foxyshadis:
    zephc:
    You have to use BBCode, but then, like breaks don't seem to work either. (Also, that posting on this forum has no Preview button, though I'm pretty sure its built-in.)

    Maybe you weren't here, but the preview button caused ten times as many wtf comments. I kinda miss all the html spews now. ;_;

    I'd love to meet the sap who has to come in and maintain a program with a complex algorithm punctuated by swarms of

    out.field3 = dict.field1 * dict.field5;

    See, I do it the PHP way, where with __get() and __set(), you can create a class that can define any variable, or even turn simple variable access into crazy functions. =D

    $class->keanu('whoa');
    $class->duck = '12';  // drop database
    $twelve = $class->mong;  // whatever duck was set to ends up here

    Well, properties are harly anything new (but for Java guys that is). Ruby has them natively and in a most graceful way, Python has them as well (although the construct is much less graceful than Ruby's), even C# has them...

    Methinks Java6 should do it the Ruby way, any getter and/or setter generates a property, read, write or both (if both getter and setter exist) and be done with it, maintains backward compatibility and stops having to write shitty code.

  • Ian (unregistered) in reply to Mung Kee
  • Ian (unregistered) in reply to Mung Kee

    Mung Kee:
    Alexis de Torquemada:
    Mung Kee:


    I did a quick search for "Stroustrup".  Imagine having this line on your resume:

    "I designed and implemented the C++ programming language"

    http://www.research.att.com/~bs/homepage.html


    My resume already contains the line "I invented the Internet", and I don't want to make people suspicious.



    Wow, Richard Nixon and Al Gore on the same thread.

    Oops.. ignore the above post :)

    http://www.perkel.com/politics/gore/internet.htm

  • 6755765 (unregistered) in reply to Ian
    Anonymous:

    Mung Kee:
    Alexis de Torquemada:
    Mung Kee:


    I did a quick search for "Stroustrup".  Imagine having this line on your resume:

    "I designed and implemented the C++ programming language"

    http://www.research.att.com/~bs/homepage.html


    My resume already contains the line "I invented the Internet", and I don't want to make people suspicious.



    Wow, Richard Nixon and Al Gore on the same thread.

    Oops.. ignore the above post :)

    http://www.perkel.com/politics/gore/internet.htm

     

    Do you know why I hate to read about politics?
    Because they start the page with:
    "Here's the story behind the story and you determine who is lying and who is telling the truth. "

    And end with:
    <FONT color=#c000a0>"So, it would appear that Bush is the one lying and can't be trusted. "</FONT>

    <FONT color=#c000a0></FONT> 

    <FONT color=#c000a0>Yea, right.</FONT>

  • (cs) in reply to masklinn
    masklinn:
    Well, properties are harly anything new (but for Java guys that is). Ruby has them natively and in a most graceful way, Python has them as well (although the construct is much less graceful than Ruby's), even C# has them...

    Methinks Java6 should do it the Ruby way, any getter and/or setter generates a property, read, write or both (if both getter and setter exist) and be done with it, maintains backward compatibility and stops having to write shitty code.


    What I meant by my example is that __get() and __set() aren't tied to any property. One function controls all properties, rather than naming properties and calling get/set methods on them. The wtf is that there's no interface to document, and anyone who looks over the code of a sufficiently braindamaged class will have a siezure trying to figure out what to call. =D Plus the magic of no compile-time (or what passes for compile-time in php) checking.

    Sadly, it's the only way to do that. Instead of providing properties with get/set, we get a bizarre universal catchall get/set property that I'm pretty sure no other language has. The only way around it is public members or individual methods.
  • (cs) in reply to foxyshadis
    foxyshadis:

    Sadly, it's the only way to do that. Instead of providing properties with get/set, we get a bizarre universal catchall get/set property that I'm pretty sure no other language has.

    Python?
    LUA?

  • (cs) in reply to foxyshadis
    foxyshadis:
    ...Sadly, it's the only way to do that. Instead of providing properties with get/set, we get a bizarre universal catchall get/set property that I'm pretty sure no other language has. The only way around it is public members or individual methods.

    The third way around it is to not use, or at least minimize, getters and setters.   See http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox_p.html for details.  This article really needs a followup with some good examples, unfortunately.

  • (cs) in reply to foxyshadis
    foxyshadis:
    Sadly, it's the only way to do that. Instead of providing properties with get/set, we get a bizarre universal catchall get/set property that I'm pretty sure no other language has. The only way around it is public members or individual methods.

    Python actually has some "catchall" methods, namely __getattr__, __setattr__, __delattr__ and __getattribute__.

    These "magic methods" are called when no existing member exists, and are given the attribute name that was called as their parameter. They are not used often, but allow for fine tuning of specific objects, and work on top (or behind) of the regular attributes/properties of the Python objects.

    An object will, of course, resume to AttributeError exception if these methods are not explicitely implemented, and you as the implementer are supposed to throw it manually if the attribute name doesn't fit your filters.

  • Paul (unregistered)

    Wonderful... Why not just:

    <FONT face="Courier New" color=#000000>string serializedObject;</FONT>

    Covers all bases and is very reusable [:P]

  • (cs) in reply to masklinn
    masklinn:
    foxyshadis:
    Sadly, it's the only way to do that. Instead of providing properties with get/set, we get a bizarre universal catchall get/set property that I'm pretty sure no other language has. The only way around it is public members or individual methods.

    Python actually has some "catchall" methods, namely __getattr__, __setattr__, __delattr__ and __getattribute__.

    These "magic methods" are called when no existing member exists, and are given the attribute name that was called as their parameter. They are not used often, but allow for fine tuning of specific objects, and work on top (or behind) of the regular attributes/properties of the Python objects.

    An object will, of course, resume to AttributeError exception if these methods are not explicitely implemented, and you as the implementer are supposed to throw it manually if the attribute name doesn't fit your filters.


    Yeah, that's what I meant, I just missed them when I went over python's OO a while back. It's good to know that bizarre mindfucks are somewhat portable. =D
  • phx (unregistered) in reply to foxyshadis

    You can always use your favourite aspect oriented weaver to really screw things up for the hapless sod who has to debug your work. A particular fave I left an employer was a horrible (partly necessary) solution which created classes and methods using Reflection.Emit and wove them into target classes. :(

  • (cs) in reply to triso
    triso:

    The third way around it is to not use, or at least minimize, getters and setters.   See http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox_p.html for details.


    Very interesting and usefull link, thanks.
  • Arrnonymous the Pirate (unregistered) in reply to Satanicpuppy
    Satanicpuppy:
    Just an aside, I was delighted when intel moved from "486" to the "Pentium" line, instead of continuning with the boring x86 number theme. I was convinced they were going to go from Pentium to "Sexium" and damn, that would be a fine name for a computer. Pentium II?!?!? Oh, unjust, cruel world.


    Sorry to burst your bubble, but since "penta" is greek, just to be consistent, the successor would have had to be called "Hexium" ;)
  • (cs) in reply to Arrnonymous the Pirate

    'Hexium'? Oooh, that's pagan, innit? Can't have that, it might upset the fundies!

  • Gerrit (unregistered)

    We have a more generic aproach, we use Object instead of Strings:

    class Tuple {
        Object a, b;

        Tuple(Object a, Object b) {

            this.a = a;

            this.b = b;

        }


        public Object getFst() {

            return a;

        }


        public Object getSnd() {

            return b;

        }

    }

  • (cs) in reply to no1

    I hope he didn't get to Sextuple, don't want this guy reproducing

  • flux (unregistered)

    The advantage of using these structures instead of for example arrays is that the compiler can check the proper number of elements at compile time. For this reason using (public) inheritance for the longer tuples isn't a good idea.

    Obviously these classes were written for a piece of code that manipulated only strings, otherwise they could be Objects instead of Strings - which would lead to horrible code clutter, casting to and back. Java Generics would (almost) fix that..

    Many functional languages have tuples built-in to the language, so no need for hacks like these..

  • Anon (unregistered) in reply to Mung Kee

    I'm not sure if that is sarcasm or not.  If not then you missed the point.  The intent was to replace all of the classes with a single String array object

  • christoofar (unregistered) in reply to RayS

    No no no, this is NOT how you should do it.

    Please observe this example:

    public class Unary
    {
        int unaryID;
        string field1;
    }

    public class Binary
    {
        int binaryID;
        Unary unaryField;
        string field2;
    }

    public class Ternary
    {
        int ternaryID;
        Binary binaryField;  //Brillant!  Less code!
        string field3;
    }

  • woah (unregistered)

    Ah the beauty of java.util.Map.

    public class Person
    {
        public String id;
        public Map attributes;
        public setAttr(Object key, Object value) {
           this.attributes.put(key, value);
        }
        public getAttr(Object key) {
           return this.attributes.get(key);
        }
    }

    usage:
    Person me = new Person();
    me.attributes.put("field1", field1Value);

    Or if you don't like all the dots, use the setter:
    Person me = new Person();
    me.setAttr("field1", field1Value);

  • (cs) in reply to Arrnonymous the Pirate

    Anonymous:
    Satanicpuppy:
    Just an aside, I was delighted when intel moved from "486" to the "Pentium" line, instead of continuning with the boring x86 number theme. I was convinced they were going to go from Pentium to "Sexium" and damn, that would be a fine name for a computer. Pentium II?!?!? Oh, unjust, cruel world.


    Sorry to burst your bubble, but since "penta" is greek, just to be consistent, the successor would have had to be called "Hexium" ;)

    Agreed, mixing your Latin and your Greek should be grounds for justifiable anthrocide. [:O]

  • qiguai (unregistered) in reply to masklinn
    masklinn:
    foxyshadis:
    zephc:
    You have to use BBCode, but then, like breaks don't seem to work either. (Also, that posting on this forum has no Preview button, though I'm pretty sure its built-in.)

    Maybe you weren't here, but the preview button caused ten times as many wtf comments. I kinda miss all the html spews now. ;_;

    I'd love to meet the sap who has to come in and maintain a program with a complex algorithm punctuated by swarms of

    out.field3 = dict.field1 * dict.field5;

    See, I do it the PHP way, where with __get() and __set(), you can create a class that can define any variable, or even turn simple variable access into crazy functions. =D

    $class->keanu('whoa');
    $class->duck = '12';  // drop database
    $twelve = $class->mong;  // whatever duck was set to ends up here

    Well, properties are harly anything new (but for Java guys that is). Ruby has them natively and in a most graceful way, Python has them as well (although the construct is much less graceful than Ruby's), even C# has them...

    Methinks Java6 should do it the Ruby way, any getter and/or setter generates a property, read, write or both (if both getter and setter exist) and be done with it, maintains backward compatibility and stops having to write shitty code.



    Properties go back (at least) to early Lisp (or LISP, as it was called then) implementations. I'm too lazy to look it up, but I'm guessing that this dates to around '61 (Lisp dates to around '59). Properties in Lisp are interesting in that they can be attached to any variable (well, any symbol, which is a slightly different thing). The implementation is generally not very efficient for large numbers of properties (usually a linked list of tuples), and I  wouldn't normally use them in "real" code for reasons unrelated to efficiency, but they can be quite handy for prototyping.
  • qiguai (unregistered) in reply to OneFactor
    OneFactor:

    Agreed, mixing your Latin and your Greek should be grounds for justifiable anthrocide. [:O]



    That was really uncalled for. To think that the pun has been unjustly impugned, all these years, as the lowest form of humour...

    ---
    I'd rather split etyms than atoms - James Joyce
  • Brandon Driesen (unregistered)

    <font size="2">public class Combination
    {
        private string id;
        private string [] values = {};
        
        public Combination(int length)
        {
            if (length > 0)
                this.values = new string [length];
        }

        public string this [int index]
        {
            get { return this.values[index];}
            set { this.values[index] = value; }

        }

        public string ID
        {
            get { return this.id; }
            set { this.id = value; }
        }

        public int Count
        {
            get { return this.values.Length; }
        }

        public string [] ToArray
        {
            get
            {
                string [] clones = {};
                if (this.values.Length != 0)
                {
                    clones = new string[this.values.Length];
                    this.values.CopyTo(clones,0);
                }
                return clones;
            
            }
        }
    }

    example:
    Combination c = new Combination(3);
    c.ID = "Triplet";
    c[0] = "Hello World!";
    c[1] = "Test It";
    c[2] = "Yesterday!!";
    </font>

  • (cs) in reply to OneFactor

    OneFactor: "Agreed, mixing your Latin and your Greek should be grounds for justifiable anthrocide"

    On television.

  • (cs) in reply to Bellinghman

    Bellinghman:
    OneFactor: "Agreed, mixing your Latin and your Greek should be grounds for justifiable anthrocide" On television.

    <FONT face="Courier New" size=2>tbs presents, "my big fat latin/greek wedding"</FONT>

  • (cs) in reply to Fast B

    Anonymous:
    Um...I think he was referring to this.

    <FONT face="Courier New" size=2>i suppose one could make a union of pairs, triples, etc.  what a pain in the ass.  alright, check it.  these structures are defined for primes up to say, 100.  that's about 25 of them, no?  they should be able to represent most numbers in common ranges, producing wider gaps as you get into larger and larger numbers.  if one of these "skipped over" numbers is needed, create the missing factors and add them to the list.  after a while, the probability of needing a "skipped over" number diminishes, and you get the minimal set of prime-tuples that are needed for your application.  viola!  the fewer basic structures used make the program run faster, since aggregates of structures are optimized by the compiler.  everybody wins!  yay!</FONT>

  • Sam (unregistered) in reply to Dave

    [:D]  That's hilarious!  I can't believe no one got that joke before now.

  • Sam (unregistered) in reply to Sam

    Anonymous:
    [:D]  That's hilarious!  I can't believe no one got that joke before now.

    I was referring to this one:

    Anonymous:

    You mean with the tuples? Looks like he stopped before he got to sex. So does this qualify as codus interruptus?

      I'm used to VBulletin, which autoquotes when you hit Reply... sorry. [:$]

  • Loke (unregistered) in reply to Tupler

    That C++ code is truely scary. Just as I thought templates couldn't possibly be any worse, you drag me right back to earth again. :-)

    It's truely a marvel.

  • (cs)

    Ironically most languages now suppport strongly typed Tuples... So the concept was sound, but the implementation was not.

Leave a comment on “Structured Code Reuse”

Log In or post as a guest

Replying to comment #:

« Return to Article