Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Simplicity

Reply
Thread Tools

Simplicity

 
 
JKop
Guest
Posts: n/a
 
      09-04-2004
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
 
Reply With Quote
 
 
 
 
Steven T. Hatton
Guest
Posts: n/a
 
      09-04-2004
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->[i].

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

 
Reply With Quote
 
 
 
 
Ioannis Vranos
Guest
Posts: n/a
 
      09-04-2004
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
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      09-04-2004
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
 
Reply With Quote
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      09-04-2004
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
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      09-04-2004
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/i...rs/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
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      09-04-2004
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
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      09-04-2004
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
 
Reply With Quote
 
David Hilsee
Guest
Posts: n/a
 
      09-04-2004
"JKop" <(E-Mail Removed)> wrote in message
news:Tfo_c.26574$(E-Mail Removed)...
<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


 
Reply With Quote
 
JKop
Guest
Posts: n/a
 
      09-04-2004

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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Eccellio - Search and simplicity with one additional single-click frittino C Programming 0 05-16-2009 09:41 PM
Simplicity has a future jacob navia C Programming 109 06-06-2006 05:38 PM
Efficiency vs. simplicity Mike Austin Ruby 0 03-16-2006 07:48 PM
NYJavaSIG - EJB 3.0 and J2EE 5 - Bringing Simplicity to the Complexity Frank D. Greco Java 0 02-15-2005 05:31 AM
RE: Python's simplicity philosophy Tim Peters Python 1 11-15-2003 10:01 AM



Advertisments