C Board  

Go Back   C Board > Community Boards > Projects and Job Recruitment

Reply
 
LinkBack Thread Tools Display Modes
Old 12-05-2008, 05:56 AM   #1
Ugly C Lover
 
audinue's Avatar
 
Join Date: Jun 2008
Location: Indonesia
Posts: 462
Smile Syntax Design ...

Hi again!

I hope I'm not posting in a wrong place ^_^"...

Btw, I need your suggestion to my basic like programming language.

It has two features called Class Aliases and Alias for subtitution.

Class Aliases are just like toString() in Java but they can be used for any Class, not just String.

For instance:

Code:
Class Apple

  Alias Apple As String
    Return "I'm an Apple!" <-- LOL
  End Alias

  Alias Apple As Number
    Return 10
           ^-- Just for example
  End Alias

  /* Syntax:
  Alias ClassName As AnotherClassName
    .
    .
    Return objectOfAnotherClassName
  End Alias
  */
End Class

Dim apple As New Apple
Console.printLn apple           <-- 0x???? the object pointer
Console.printLn apple As String <-- I'm an Apple!
Console.printLn apple As Number <-- 10
And the second is Alias for subtitution, behaves just like #define in C, but a little bit more simple.

Syntax:
Code:
Alias new_name As name
Example:
Code:
Alias debug As Console.printLn
.
.
debug "ERROR? " & errorNumber
And then...

Code:
Class Apple

  Alias print As Console.printLn  

  Alias Apple As String
    print "Test!"
    Return "I'm an Apple!"
  End Alias

  Alias Apple As Number
    Return 10
  End Alias

End Class
Will you confused to a code like above?

Mmm... maybe there is another way to implement this one?

Thanks in advance.
audinue is offline   Reply With Quote
Old 12-05-2008, 05:58 AM   #2
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,365
To liken this to a C++ feature, would you say that your aliases are like type conversion functions?
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 12-05-2008, 06:03 AM   #3
Ugly C Lover
 
audinue's Avatar
 
Join Date: Jun 2008
Location: Indonesia
Posts: 462
Quote:
Originally Posted by laserlight View Post
To liken this to a C++ feature, would you say that your aliases are like type conversion functions?
But in OOP style, and yet simple.
audinue is offline   Reply With Quote
Old 12-05-2008, 06:33 AM   #4
Registered User
 
C_ntua's Avatar
 
Join Date: Jun 2008
Posts: 1,134
No, It is not confusing. But again I don't know anything about basic so not really good to judge.
The as keyword exists in C# but it doesn't do exactly this

Well, why not just make a toInt() or toSomeClass()?

Elaborate a bit of the usefulness of such a feature.
1) The toInt(), toObj() etc etc functions can be stored in an interface, so the basic toType() exists always and can be implemented as you want.
2) If they don't exist you 'll get a compile time error.

So why make them a language feature?
The way C# uses as seems more useful...
C_ntua is offline   Reply With Quote
Old 12-05-2008, 06:56 AM   #5
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,365
Quote:
Originally Posted by audinue
But in OOP style, and yet simple.
Well, C++ conversion functions are "OOP style" too

Taking a look at:
Code:
Console.printLn apple As String
I am guessing that the conversion must always be explicit. There are advantages to this (conversions will always be expected) and disadvantages (verbose syntax required).

What I do not understand is "Alias for subtitution". How does it differ from "Class Aliases"? They both seem to provide a conversion from the class type to some other type.

Quote:
Originally Posted by C_ntua
Well, why not just make a toInt() or toSomeClass()?
It is just a different syntactic sugar, from what I see.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 12-06-2008, 02:10 AM   #6
Ugly C Lover
 
audinue's Avatar
 
Join Date: Jun 2008
Location: Indonesia
Posts: 462
Quote:
Originally Posted by C_ntua
Well, why not just make a toInt() or toSomeClass()?

Elaborate a bit of the usefulness of such a feature.
1) The toInt(), toObj() etc etc functions can be stored in an interface, so the basic toType() exists always and can be implemented as you want.
2) If they don't exist you 'll get a compile time error.

So why make them a language feature?
The way C# uses as seems more useful...
Class aliases done just by a cast. Without calling toXXX method..

Quote:
Originally Posted by laserlight
I am guessing that the conversion must always be explicit. There are advantages to this (conversions will always be expected) and disadvantages (verbose syntax required).
There will be implicit conversion too ^_^

Quote:
Originally Posted by laserlight
What I do not understand is "Alias for subtitution". How does it differ from "Class Aliases"? They both seem to provide a conversion from the class type to some other type.
Class aliases are for converting base class type into another class type, and of course, they works only on their object.

"Alias for subtitution" subtitutes the 'name' of variable/function/class/package/module definition.
It doesn't convert anything at all. And works just like safe-macro (it will warn when ambigious things detected)

Code:
Dim frmMainHandle As HWND
... do something with frmMainHandle ...

{when frmMainHandle is not used anymore...
  subtitute it instead of creating a new variable}
Alias btnOKHandle As frmMainHandle
... do something with btnOKHandle ...
In C/C++ it's done by
Code:
#define btnOKHandle frmMainHandle
But yet, it's a compiler directive and will not checking for any collisions...
audinue is offline   Reply With Quote
Old 12-06-2008, 02:24 AM   #7
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,365
Quote:
Originally Posted by audinue
Class aliases are for converting base class type into another class type, and of course, they works only on their object.
Instead of "class aliases" you might want to call them "class conversions" or something like that.

Quote:
Originally Posted by audinue
"Alias for subtitution" subtitutes the 'name' of variable/function/class/package/module definition.
It doesn't convert anything at all. And works just like safe-macro (it will warn when ambigious things detected)
These, on the other hand, sound like actual aliases.

Quote:
Originally Posted by audinue
But yet, it's a compiler directive and will not checking for any collisions...
Actually, #define is a preprocessor directive and hence does not obey the rules of scope. Consider if your aliases will obey the rules of scope.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 12-06-2008, 02:30 AM   #8
Ugly C Lover
 
audinue's Avatar
 
Join Date: Jun 2008
Location: Indonesia
Posts: 462
Thank you laserlight!!
Quote:
Originally Posted by laserlight
Instead of "class aliases" you might want to call them "class conversions" or something like that.
I owe you this one!

Quote:
Consider if your aliases will obey the rules of scope.
Yes, it's.
audinue is offline   Reply With Quote
Old 12-06-2008, 03:48 AM   #9
Ugly C Lover
 
audinue's Avatar
 
Join Date: Jun 2008
Location: Indonesia
Posts: 462
And yet another confusion:

Code:
Type SortCallback<T> As Function(a, b As T) As Integer

Alias SortStringCallback As SortCallback<Character>
Arrrghh... designing is tough for sure

Last edited by audinue; 12-06-2008 at 07:44 AM.
audinue is offline   Reply With Quote
Old 12-08-2008, 09:04 AM   #10
The larch
 
Join Date: May 2006
Posts: 3,082
Code:
Dim frmMainHandle As HWND
... do something with frmMainHandle ...

{when frmMainHandle is not used anymore...
  subtitute it instead of creating a new variable}
Alias btnOKHandle As frmMainHandle
... do something with btnOKHandle ...
This looks like a bit too much micro-management. What happens if I do use frmMainHandle later?

Instead why not make a really good garbage collecter and free the programmer of such worries
__________________
I might be wrong.

Quote:
Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Quoted more than 1000 times (I hope).
anon is offline   Reply With Quote
Old 12-08-2008, 09:15 AM   #11
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Quote:
Originally Posted by anon View Post
Code:
Dim frmMainHandle As HWND
... do something with frmMainHandle ...

{when frmMainHandle is not used anymore...
  subtitute it instead of creating a new variable}
Alias btnOKHandle As frmMainHandle
... do something with btnOKHandle ...
This looks like a bit too much micro-management. What happens if I do use frmMainHandle later?

Instead why not make a really good garbage collecter and free the programmer of such worries
I'm at a complete loss as to what you actually are trying to achieve? A new language that uses Visual Basic syntax, but also has some features of C++?

Be that as it may: If you alias a variable, then that variable is still alive (it just happens to have a different name). So you need to either trust the programmer to to the right thing (like C and C++ does) or rely on some sort of automatic mechanism to handle the "freeing" of the object.

--
Mats

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
more then 100errors in header hallo007 Windows Programming 20 05-13-2007 08:26 AM
We Got _DEBUG Errors Tonto Windows Programming 5 12-22-2006 05:45 PM
Using VC Toolkit 2003 Noobwaker Windows Programming 8 03-13-2006 07:33 AM
Connecting to a mysql server and querying problem Diod C++ Programming 8 02-13-2006 10:33 AM
Dikumud maxorator C++ Programming 1 10-01-2005 06:39 AM


All times are GMT -6. The time now is 08:38 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22