Thread: Syntax Design ...

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    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.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    To liken this to a C++ feature, would you say that your aliases are like type conversion functions?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    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.

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    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...

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    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...

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    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!

    Consider if your aliases will obey the rules of scope.
    Yes, it's.

  9. #9
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    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.

  10. #10
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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.

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

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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