Simplicity

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JKop

    Simplicity

    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.SomeMemberFun ction

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


    Zone* k;
    k->SomeMemberFunc tion();


    Here's how you actually work with it:

    Dim k as Zone
    Set k = New Zone
    k.SomeMemberFun ction

    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
  • Steven T. Hatton

    #2
    Re: Simplicity

    JKop wrote:
    [color=blue]
    > 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)[/color]

    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>
    [color=blue]
    >
    > Here's how you actually work with it:
    >
    > Dim k as Zone
    > Set k = New Zone
    > k.SomeMemberFun ction[/color]

    I'll bet dollars to doughnuts they're really pointers in drag.
    [color=blue]
    > 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.[/color]

    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->[i].
    [color=blue]
    > So anyway, I'd just like to hear general opinions on the simplicity in
    > other languages.[/color]

    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.

    Comment

    • Ioannis Vranos

      #3
      Re: Simplicity

      JKop wrote:[color=blue]
      > 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.SomeMemberFun ction
      >
      > Then there will be a runtime error, it would be like doing the following in
      > C++:
      >
      >
      > Zone* k;
      > k->SomeMemberFunc tion();
      >
      >
      > Here's how you actually work with it:
      >
      > Dim k as Zone
      > Set k = New Zone
      > k.SomeMemberFun ction[/color]




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


      [color=blue]
      > 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.[/color]


      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:




      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?!




      [color=blue]
      >
      > 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
      > }[/color]



      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(someo bj);


      System::Console ::WriteLine(som eobj.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>



      [color=blue]
      > 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[/color]



      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 *newPointerValu e)
      {
      p= newPointerValue ;
      }

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

      T * operator=(T *newPointerValu e)
      {
      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


      Comment

      • Ioannis Vranos

        #4
        Re: Simplicity

        Steven T. Hatton wrote:
        [color=blue]
        > 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>[/color]


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






        Regards,

        Ioannis Vranos


        Comment

        • Julián Albo

          #5
          Re: Simplicity

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

          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

          Comment

          • Ioannis Vranos

            #6
            Re: Simplicity

            Julián Albo wrote:
            [color=blue][color=green]
            >>And one important thing is the name of the language itself. BASIC stands
            >>for "Beginner's All Purpose Symbolic Instruction Code".[/color]
            >
            >
            > 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.[/color]


            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.




            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


            Comment

            • Ioannis Vranos

              #7
              Re: Simplicity

              Ioannis Vranos wrote:
              [color=blue]
              > 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:[/color]


              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


              Comment

              • Ioannis Vranos

                #8
                Re: Simplicity

                Ioannis Vranos wrote:
                [color=blue]
                > Ioannis Vranos wrote:
                >[color=green]
                >> 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:[/color]
                >
                >
                >
                > 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.[/color]


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






                Regards,

                Ioannis Vranos


                Comment

                • David Hilsee

                  #9
                  Re: Simplicity

                  "JKop" <NULL@NULL.NULL > wrote in message
                  news:Tfo_c.2657 4$Z14.8642@news .indigo.ie...
                  <snip>[color=blue]
                  > 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.[/color]
                  <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? :-)
                  [color=blue]
                  > So anyway, I'd just like to hear general opinions on the simplicity in[/color]
                  other[color=blue]
                  > 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
                  > }[/color]

                  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.
                  [color=blue]
                  > 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[/color]

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

                  --
                  David Hilsee


                  Comment

                  • JKop

                    #10
                    Re: Simplicity


                    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+(Resea tableRef<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<i nt> 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

                    Comment

                    • Ioannis Vranos

                      #11
                      Re: Simplicity

                      JKop wrote:
                      [color=blue]
                      > The aim is for:
                      >
                      > Set k = b;
                      >
                      > to be turned into:
                      >
                      > k.p_t = &b;
                      >
                      >
                      > or something along those lines![/color]


                      :-) 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


                      Comment

                      • Frederic Banaszak

                        #12
                        Re: Simplicity

                        On Sat, 04 Sep 2004 23:25:24 +0200, Julián Albo <JULIANALBO@ter ra.es>
                        wrote:
                        [color=blue]
                        >Ioannis Vranos wrote:
                        >[color=green]
                        >> And one important thing is the name of the language itself. BASIC stands
                        >> for "Beginner's All Purpose Symbolic Instruction Code".[/color]
                        >
                        >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.[/color]

                        I had also heard that it was a 'backronym', but then I found this:


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

                        Or not.


                        Comment

                        • Ioannis Vranos

                          #13
                          Re: Simplicity

                          Frederic Banaszak wrote:
                          [color=blue]
                          > 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.[/color]


                          Yes. And except of that, the name itself says it all. *Basic*.






                          Regards,

                          Ioannis Vranos


                          Comment

                          • JKop

                            #14
                            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(ReR ef<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

                            Comment

                            • Phlip

                              #15
                              Re: ReRef

                              JKop wrote:
                              [color=blue]
                              > 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;[/color]

                              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.electMa yor("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
                              Industrial XP: Extreme Programming, XP, Agile Software Development, Agile Methods.



                              Comment

                              Working...