Simplicity

Discussion in 'C++' started by JKop, Sep 4, 2004.

  1. JKop

    JKop Guest

    The other day I had to write some code to manipulate a Micrsoft Excel
    spreadsheet. I had to write it in Visual Basic, which I haven't used for
    about 5 years. Anyway, it slowly started creeping back to me and I began to
    understand terms like:

    ByVal (by value)
    ByRef (by reference)

    I remember how excited I was switching to C++, working with a better, more
    controllable language.

    But now going back and using VB I've realized how much I love the
    simplicity. One thing I particularly like is re-seatable references:

    Dim k as Zone

    The above is an object definition. "k" is the name of the object and "Zone"
    is the type. It would be akin to:

    Zone k;

    in C++. Anyway, while in C++, that would create an object, all it does in VB
    is create a re-seatable reference. For example, if I try to do this:

    Dim k as Zone
    k.SomeMemberFunction

    Then there will be a runtime error, it would be like doing the following in
    C++:


    Zone* k;
    k->SomeMemberFunction();


    Here's how you actually work with it:

    Dim k as Zone
    Set k = New Zone
    k.SomeMemberFunction

    Anyway, I love the idea of re-seatable references. Sure, we can re-seat
    pointers, but then that adds all the bullshit of dodgy syntax.

    So anyway, I'd just like to hear general opinions on the simplicity in other
    languages. I particulary like how VB uses actual words instead of symbols,
    eg.:

    //start VB code

    Public Sub DoStuff(ByRef r as integer)

    r = 12

    End Function

    //end VB code


    would be the equivalent of:


    void DoStuff(int &r)
    {
    r = 12
    }

    ****

    Before I go and write one myself, has anyone written a class for a re-
    seatable reference? I think I'll use macros to achieve syntax something
    like:

    int% a; //a re-seatable reference

    int k;

    Set a = k;

    a = 4; //changes k's value

    int z;

    Set a = z;

    a = 9; //changes z's value


    -JKop
    JKop, Sep 4, 2004
    #1
    1. Advertising

  2. JKop wrote:

    > The other day I had to write some code to manipulate a Micrsoft Excel
    > spreadsheet. I had to write it in Visual Basic, which I haven't used for
    > about 5 years. Anyway, it slowly started creeping back to me and I began
    > to understand terms like:
    >
    > ByVal (by value)
    > ByRef (by reference)


    I programmed in Apple BASIC about 21 years ago. I should have stuck with
    it; but no, I wanted to discover the true unified field theory. I do
    recall a bit of the simplicity of that. I also recall my father showing me
    a program written in some kind of BASIC about 5 years ago. Simplicity
    isn't always. <shudder>

    >
    > Here's how you actually work with it:
    >
    > Dim k as Zone
    > Set k = New Zone
    > k.SomeMemberFunction


    I'll bet dollars to doughnuts they're really pointers in drag.

    > Anyway, I love the idea of re-seatable references. Sure, we can re-seat
    > pointers, but then that adds all the bullshit of dodgy syntax.


    I haven't experimented with it, but I've seen some uses of typedef that
    might hide the 'dodgy syntax'. The one thing I would really like to be
    able to do in C++ is my_ptr->.

    > So anyway, I'd just like to hear general opinions on the simplicity in
    > other languages.


    I have found, though vague memories of using Pascal. It really is a capable
    language. I can't comment on VB, because the only time I've read it was
    when I received viruses written in it. Pascal is certainly more structured
    than the BASIC I learned.


    --
    "[M]y dislike for the preprocessor is well known. Cpp is essential in C
    programming, and still important in conventional C++ implementations, but
    it is a hack, and so are most of the techniques that rely on it. ...I think
    the time has come to be serious about macro-free C++ programming." - B. S.
    Steven T. Hatton, Sep 4, 2004
    #2
    1. Advertising

  3. JKop wrote:
    > The other day I had to write some code to manipulate a Micrsoft Excel
    > spreadsheet. I had to write it in Visual Basic, which I haven't used for
    > about 5 years. Anyway, it slowly started creeping back to me and I began to
    > understand terms like:
    >
    > ByVal (by value)
    > ByRef (by reference)
    >
    > I remember how excited I was switching to C++, working with a better, more
    > controllable language.
    >
    > But now going back and using VB I've realized how much I love the
    > simplicity. One thing I particularly like is re-seatable references:
    >
    > Dim k as Zone
    >
    > The above is an object definition. "k" is the name of the object and "Zone"
    > is the type. It would be akin to:
    >
    > Zone k;
    >
    > in C++. Anyway, while in C++, that would create an object, all it does in VB
    > is create a re-seatable reference. For example, if I try to do this:
    >
    > Dim k as Zone
    > k.SomeMemberFunction
    >
    > Then there will be a runtime error, it would be like doing the following in
    > C++:
    >
    >
    > Zone* k;
    > k->SomeMemberFunction();
    >
    >
    > Here's how you actually work with it:
    >
    > Dim k as Zone
    > Set k = New Zone
    > k.SomeMemberFunction





    In the above it looks like you create an object in the free store.



    > Anyway, I love the idea of re-seatable references. Sure, we can re-seat
    > pointers, but then that adds all the bullshit of dodgy syntax.



    I do not understand what you mean by re-seatable references, but I
    suspect you are using .NET and you are talking about .NET (CLI) features.


    The address of reference objects in C++/CLI handles (and the current
    managed extensions pointers) is not the same but changes as the runtime
    repositions objects in the managed heap.


    In C++/CLI the address of operator is % which returns a "tracking
    reference".


    Check this page of mine:

    http://www23.brinkster.com/noicys/cppcli.htm


    And the current thread with the stupid title:

    "Why not develop new language"


    In any case I haven't understood what exactly you like, the run-time error?!





    >
    > So anyway, I'd just like to hear general opinions on the simplicity in other
    > languages. I particulary like how VB uses actual words instead of symbols,
    > eg.:
    >
    > //start VB code
    >
    > Public Sub DoStuff(ByRef r as integer)
    >
    > r = 12
    >
    > End Function
    >
    > //end VB code
    >
    >
    > would be the equivalent of:
    >
    >
    > void DoStuff(int &r)
    > {
    > r = 12
    > }




    How can you do this in VB at compile-time, which also produces 100% pure
    IL code?


    //Managed object
    ref class test
    {
    int value;

    public:
    test() { value=1; }

    // Trivial property - Compiler generated definition
    property int Value;
    };


    template <class T>
    void multiply2(T %obj)
    {
    obj.Value=2;
    }


    int main()
    {
    // Managed object with stack semantics
    //Deterministic destruction
    test someobj;

    multiply2(someobj);


    System::Console::WriteLine(someobj.Value);

    }




    C:\c>cl /clr:safe temp.cpp
    Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40809
    for Microsoft (R) .NET Framework version 2.00.40607.16
    Copyright (C) Microsoft Corporation. All rights reserved.

    temp.cpp
    Microsoft (R) Incremental Linker Version 8.00.40809
    Copyright (C) Microsoft Corporation. All rights reserved.

    /out:temp.exe
    temp.obj

    C:\c>temp
    2

    C:\c>




    > Before I go and write one myself, has anyone written a class for a re-
    > seatable reference? I think I'll use macros to achieve syntax something
    > like:
    >
    > int% a; //a re-seatable reference
    >
    > int k;
    >
    > Set a = k;
    >
    > a = 4; //changes k's value
    >
    > int z;
    >
    > Set a = z;
    >
    > a = 9; //changes z's value




    Since you have pointers(and C++/CLI handles), you can do exactly the
    same operations. So you insist on a different syntax?



    You can write a simple template then. Something like:



    template <class T>
    ref class RTrackRef
    {
    T ^h;

    public:
    RTrackRef() { h=nullptr; }
    RTrackRef(T ^newHandleValue)
    {
    h= newHandleValue;
    }

    operator T() { return *h; }
    operator T ^() { return h; }

    T ^ operator=(T ^newHandleValue)
    {
    h= newHandleValue;

    return h;
    }

    const T % operator=(const T %newValue)
    {
    *h = newValue;

    return *h;
    }
    };


    template <class T>
    ref class NTrackRef
    {
    T *p;

    public:
    NTrackRef() { p=0; }
    NTrackRef(T *newPointerValue)
    {
    p= newPointerValue;
    }

    operator T() { return *p; }
    operator T *() { return p; }

    T * operator=(T *newPointerValue)
    {
    p= newPointerValue;

    return p;
    }

    const T & operator=(const T &newValue)
    {
    *p = newValue;

    return *p;
    }
    };



    int main()
    {
    using namespace System;

    NTrackRef<int> a; //a re-seatable reference


    int k;

    a = &k;

    a = 4; //changes k's value

    int z;

    a = &z;

    a = 9; //changes z's value

    }


    NTrackRef is for native types and RTrackRef for CLI reference types.






    Regards,

    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Sep 4, 2004
    #3
  4. Steven T. Hatton wrote:

    > I programmed in Apple BASIC about 21 years ago. I should have stuck with
    > it; but no, I wanted to discover the true unified field theory. I do
    > recall a bit of the simplicity of that. I also recall my father showing me
    > a program written in some kind of BASIC about 5 years ago. Simplicity
    > isn't always. <shudder>



    And one important thing is the name of the language itself. BASIC stands
    for "Beginner's All Purpose Symbolic Instruction Code".






    Regards,

    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Sep 4, 2004
    #4
  5. Ioannis Vranos wrote:

    > And one important thing is the name of the language itself. BASIC stands
    > for "Beginner's All Purpose Symbolic Instruction Code".


    Several sources says that the original meaning of Basic was "basic", and
    that the acronym was introducted a posteriori, because the names of all
    popular languages were acronyms.

    --
    Salu2
    =?ISO-8859-15?Q?Juli=E1n?= Albo, Sep 4, 2004
    #5
  6. Julián Albo wrote:

    >>And one important thing is the name of the language itself. BASIC stands
    >>for "Beginner's All Purpose Symbolic Instruction Code".

    >
    >
    > Several sources says that the original meaning of Basic was "basic", and
    > that the acronym was introducted a posteriori, because the names of all
    > popular languages were acronyms.



    I was playing with Basic (GWBASIC when I was at school) and then with
    QBASIC a bit (DOS 3.30 - 6.22 era), and that was the acronym I knew then
    it stood for.

    http://inventors.about.com/library/inventors/blbasic.htm


    Bill Gates invested heavily on it (you can say that he made it popular),
    and that's why it is bothering us even today. :)

    And if you consider its abilities, it is indeed for beginners.






    Regards,

    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Sep 4, 2004
    #6
  7. Ioannis Vranos wrote:

    > Since you have pointers(and C++/CLI handles), you can do exactly the
    > same operations. So you insist on a different syntax?
    >
    >
    >
    > You can write a simple template then. Something like:



    I want to emphasize that as I said above, that these VB reseatable
    references are in fact exactly what C++ pointers and CLI handles are.

    C++ is more type safe than VB and with more abilities, and the real
    references and CLI tracking references can't point to something else.


    So the equivalent of tracking references in C++ under CLI are handles.






    Regards,

    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Sep 4, 2004
    #7
  8. Ioannis Vranos wrote:

    > Ioannis Vranos wrote:
    >
    >> Since you have pointers(and C++/CLI handles), you can do exactly the
    >> same operations. So you insist on a different syntax?
    >>
    >>
    >>
    >> You can write a simple template then. Something like:

    >
    >
    >
    > I want to emphasize that as I said above, that these VB reseatable
    > references are in fact exactly what C++ pointers and CLI handles are.
    >
    > C++ is more type safe than VB and with more abilities, and the real
    > references and CLI tracking references can't point to something else.



    So the equivalent of *reseatable references* in C++ under CLI are *handles*.






    Regards,

    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Sep 4, 2004
    #8
  9. JKop

    David Hilsee Guest

    "JKop" <> wrote in message
    news:Tfo_c.26574$...
    <snip>
    > Anyway, I love the idea of re-seatable references. Sure, we can re-seat
    > pointers, but then that adds all the bullshit of dodgy syntax.

    <snip>

    What does that mean? Having to type "*" is bad? "." is better than "->"?
    You haven't been talking to Larry Wall about Perl 6, have you? :)

    > So anyway, I'd just like to hear general opinions on the simplicity in

    other
    > languages. I particulary like how VB uses actual words instead of symbols,
    > eg.:
    >
    > //start VB code
    >
    > Public Sub DoStuff(ByRef r as integer)
    >
    > r = 12
    >
    > End Function
    >
    > //end VB code
    >
    >
    > would be the equivalent of:
    >
    >
    > void DoStuff(int &r)
    > {
    > r = 12
    > }


    Beauty is in the eye of the beholder. Personally, I like symbols for
    certain things. I find them very natural and their usage somewhat similar
    to the usage of periods, commas, and parentheses in written language. They
    also can help one visually differentiate between custom code and language
    syntax. I don't think any of this has anything to do with simplicity.

    > Before I go and write one myself, has anyone written a class for a re-
    > seatable reference? I think I'll use macros to achieve syntax something
    > like:
    >
    > int% a; //a re-seatable reference
    >
    > int k;
    >
    > Set a = k;
    >
    > a = 4; //changes k's value
    >
    > int z;
    >
    > Set a = z;
    >
    > a = 9; //changes z's value


    Please don't. Code that uses macros to create a new pseudo-language
    invariably ends up looking awkward and unreadable.

    --
    David Hilsee
    David Hilsee, Sep 4, 2004
    #9
  10. JKop

    JKop Guest

    Thanks for the reply and the sample code and all, but I'm talking about C++
    here, not that other new-fangled language you're on about.

    I'd go along the lines of the following. Note that it doesn't compile or
    even do what it's supposed to but I think you'll get the idea:

    template<class T>
    class ReseatableRef
    {
    private:

    mutable T* p_t;

    public:

    operator T&()
    {
    return *p_t;
    }

    ReseatableRef(T& blah) : p_t(&blah) {}
    };

    template<class T>
    class Set_Class
    {
    public:

    T*& operator+(ReseatableRef<T> &k)
    {
    return k.p_t;
    }
    };

    #define Set *(Set_Class() +

    //One problem is that there's no closing bracket in the above macro

    int main()
    {
    int a;
    int b;
    int c;

    ReseatableRef<int> k = a;

    k = 4; //I wish there'd be implicit conversion here!

    Set k = b;

    k = 6;

    Set k = c;

    k = 7;
    }

    The aim is for:

    Set k = b;

    to be turned into:

    k.p_t = &b;


    or something along those lines!



    -JKop
    JKop, Sep 4, 2004
    #10
  11. JKop wrote:

    > The aim is for:
    >
    > Set k = b;
    >
    > to be turned into:
    >
    > k.p_t = &b;
    >
    >
    > or something along those lines!



    :) As I said pointers/handles are the equivalent of your VB references.


    If you want a non-C++ syntax, you may create a VB to C++ converter, by
    making a program that edits the file and replaces VB stuff with C++ stuff.






    Regards,

    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Sep 4, 2004
    #11
  12. On Sat, 04 Sep 2004 23:25:24 +0200, Julián Albo <>
    wrote:

    >Ioannis Vranos wrote:
    >
    >> And one important thing is the name of the language itself. BASIC stands
    >> for "Beginner's All Purpose Symbolic Instruction Code".

    >
    >Several sources says that the original meaning of Basic was "basic", and
    >that the acronym was introducted a posteriori, because the names of all
    >popular languages were acronyms.


    I had also heard that it was a 'backronym', but then I found this:
    http://www.dartmouth.edu/~vox/0304/0503/basic.html

    Short of hearing the truth from Kemeny or Kurtz themselves, I'd say it
    puts that question to rest.

    Or not.
    Frederic Banaszak, Sep 5, 2004
    #12
  13. Ioannis Vranos, Sep 5, 2004
    #13
  14. JKop

    JKop Guest

    ReRef

    The following code compiles. It's an early draft of a re-seatable reference:

    template<class T> class RefReseater;

    template<class T>
    class ReRef
    {
    private:

    T* p_t;

    public:

    explicit ReRef() : p_t(0) {}

    explicit ReRef(T& k) : p_t(&k)
    {

    }

    /*
    T& operator. ()
    {
    return *p_t;
    }
    */

    operator T&()
    {
    return *p_t;
    }

    friend class RefReseater<T>;
    };

    template<class T>
    class RefReseater
    {
    private:

    ReRef<T>& reref_object;

    public:

    RefReseater(ReRef<T>& in) : reref_object(in)
    {

    }

    ReRef<T>& operator= (T& object_in)
    {
    reref_object.p_t = &object_in;
    return reref_object;
    }
    };

    template<class T>
    RefReseater<T> Reseat(ReRef<T>& in)
    {
    return RefReseater<T>(in);
    }



    int main()
    {
    ReRef<int> j;

    int a = 1;
    int b = 2;
    int c = 3;
    int d = 4;

    Reseat(j) = a;

    //j = 9;

    Reseat(j) = b;

    //j = 8;

    Reseat(j) = c;

    //j = 7;

    //Reseat(j) = d;

    //j = 6;

    //I can't perform the assignment as there's
    //no operator defined
    };


    -JKop
    JKop, Sep 5, 2004
    #14
  15. JKop

    Phlip Guest

    Re: ReRef

    JKop wrote:

    > int main()
    > {
    > ReRef<int> j;
    >
    > int a = 1;
    > int b = 2;
    > int c = 3;
    > int d = 4;
    >
    > Reseat(j) = a;
    >
    > //j = 9;
    >
    > Reseat(j) = b;
    >
    > //j = 8;
    >
    > Reseat(j) = c;


    Nice to know one can do that. However, it breaks the style guideline "don't
    re-use a variable for more than one purpose".

    Following that rule, one should not reseat pointers, either. (We can stretch
    re-pointing a pointer into the same array around this admonition.)

    Now what did this notation solve besides the terrible burden of typing a
    cute little -> arrow?

    Also, I think you can never do this:

    ReRef<SimCity> aCity = theCity;
    theCity.electMayor("Zogg");

    I really suspect you can't do that little . dot. So you are back to an ->
    arrow anyway.

    If you really want to learn to twist C++, why not find a reason to overload
    the , comma operator?

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
    Phlip, Sep 5, 2004
    #15
  16. Ioannis Vranos, Sep 5, 2004
    #16
  17. JKop

    JKop Guest

    Re: ReRef

    Phlip posted:

    > Nice to know one can do that. However, it breaks the

    style guideline
    > "don't re-use a variable for more than one purpose".


    I don't recall signing such a contract ;-)

    There's dozens of bullshit rules out there.


    -JKop
    JKop, Sep 5, 2004
    #17
  18. Ioannis Vranos wrote:

    >> Several sources says that the original meaning of Basic was "basic", and
    >> that the acronym was introducted a posteriori, because the names of all
    >> popular languages were acronyms.

    > I was playing with Basic (GWBASIC when I was at school) and then with
    > QBASIC a bit (DOS 3.30 - 6.22 era), and that was the acronym I knew then
    > it stood for.


    Yes, I also have always known the acronym, but some time ago I have readed
    the fact I mentioned. Unfortunately I don't remember where, and can't find
    it in google.

    > Bill Gates invested heavily on it (you can say that he made it popular),
    > and that's why it is bothering us even today. :)


    I think that people made Basic popular, Microsoft just see the tendence and
    take profit from it (and make good interpreters, of course).

    > And if you consider its abilities, it is indeed for beginners.


    Yes, I think even today can be used as an easy introduction to programming.

    I even made an interpreter in the spirit of the 80 for personal computers of
    today: http://arrakis.es/~ninsesabe/blassic/

    (Not a complete off-topic: is written in C++) ;)

    --
    Salu2
    =?ISO-8859-15?Q?Juli=E1n?= Albo, Sep 5, 2004
    #18
  19. Frederic Banaszak wrote:

    > I had also heard that it was a 'backronym', but then I found this:
    > http://www.dartmouth.edu/~vox/0304/0503/basic.html
    >
    > Short of hearing the truth from Kemeny or Kurtz themselves, I'd say it
    > puts that question to rest.


    "BASIC (which stands for Beginners' All-purpose Symbolic Instruction Code)
    went on to be the most widely used computer language in the world,
    according to Kurtz, bringing computer technology to general audiences."

    I don't think that this is a definitine answer: the "according to Kurtz"
    seems to apply to "to be the most widely used computer language in the
    world", not to "(wich stands for...". But my english is very bad, I can't
    be sure.

    --
    Salu2
    =?ISO-8859-15?Q?Juli=E1n?= Albo, Sep 5, 2004
    #19
  20. =?ISO-8859-15?Q?Juli=E1n?= Albo, Sep 5, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank D. Greco
    Replies:
    0
    Views:
    339
    Frank D. Greco
    Feb 15, 2005
  2. Tim Peters

    RE: Python's simplicity philosophy

    Tim Peters, Nov 15, 2003, in forum: Python
    Replies:
    1
    Views:
    310
    Andrew Dalke
    Nov 15, 2003
  3. jacob navia

    Simplicity has a future

    jacob navia, May 30, 2006, in forum: C Programming
    Replies:
    109
    Views:
    1,495
    Richard Tobin
    Jun 6, 2006
  4. frittino
    Replies:
    0
    Views:
    284
    frittino
    May 16, 2009
  5. Mike Austin

    Efficiency vs. simplicity

    Mike Austin, Mar 16, 2006, in forum: Ruby
    Replies:
    0
    Views:
    93
    Mike Austin
    Mar 16, 2006
Loading...

Share This Page