Wish "New" Keyword

Discussion in 'Bugs & wishlist' started by ShaneG30, Mar 17, 2015.

  1. ShaneG30

    ShaneG30 Well-Known Member Licensed User

    Would love to see the upcoming rewrite of the IDE come with the "New" keyword. Would make creating objects much more faster.

    Old Way
    Code:
    Dim Pikmin As Map
    Pikmin.Initialize
    With "New" Keyword.
    Code:
    Dim Pikmin As New Map
    If any methods have parameters that need to be included with the Initialization:
    Code:
    'Old Way
    Dim Pikmin As Method
    Pikmin.Initialize(
    "parameter 1"null)

    'With "New" Keyboard
    Dim Pikmin As New Method("parameter 1"null)
     
  2. Troberg

    Troberg Well-Known Member Licensed User

    I like it. It would take us one step closer to a "real" constructor.

    If one just started to always use New instead of Dim & Initialize, one would also get compiler errors (instead of runtime errors) if one forgot to initialize with required parameters.

    Code:
    Dim MyObj as cMyObject
    MyObj.Initialize(
    "Monday""Pig""Aircraft"'Forget this line and the compiler will not say anything about it
     
    Dim MyObj as New cMyObject("Monday""Pig""Aircraft"'Correct form
    Dim MyObj as New cMyObject 'Forget the arguments and the compiler will scream at you
     
  3. EddyW

    EddyW Member Licensed User

    +1
    Would be very nice to have this
     
    ShaneG30 likes this.
  4. JakeBullet70

    JakeBullet70 Well-Known Member Licensed User

    +1
     
    ShaneG30 likes this.
  5. inakigarm

    inakigarm Well-Known Member Licensed User

    +1
     
    ShaneG30 likes this.
  6. Peter Simpson

    Peter Simpson Expert Licensed User

    A big +1 from me :)
     
    ShaneG30 likes this.
  7. JakeBullet70

    JakeBullet70 Well-Known Member Licensed User

  8. ShaneG30

    ShaneG30 Well-Known Member Licensed User

    This would also help:

    - Existing VB.NET developers will have a faster time adjusting.
    - Porting existing VB.NET code will be easier.

    There could also be this option of coding:
    Code:
    'Instead of
    Dim Pikmin As New Method("parameter 1"null)

    'This way would make B4X much closer to VB.NET, which is a good thing ;)
    Dim Pikmin As New Method
    Pikmin.Parameter1 = 
    "The Property"
    Pikmin.Setting1 = 
    Null.
     
  9. Peter Simpson

    Peter Simpson Expert Licensed User

    @WhiteholeSoft in theory why would you really want to change one line into 3 lines?
    You're suggestion is just way too much work as programming should be made shorter, not longer if possible ;)

    The suggestion in the original post is way better than your suggestion, why would you suggest doing that?

    The current way takes 2 lines of code, @WhiteholeSoft suggestion turns 2 lines of code into 1 line of code :), but you want to turn 1 line of code into 3 lines of code :rolleyes: which is one line longer than how it's currently done. The main problem is that your suggestion (3 lines) is longer and does the exact same thing as the 1 line suggestion.

    I'm definitely :confused:
     
    Last edited: Apr 15, 2015
    ShaneG30, DonManfred, rboeck and 3 others like this.
  10. ShaneG30

    ShaneG30 Well-Known Member Licensed User

    To be fair, the IDE could have two coding options: B4X Mode (the way it is now) and VB.NET Mode. (The closer the language gets to VB.NET, the more likely VB.NET devs will use the product ;))

    Also, as an example to open a OpenFileDialog in VB.NET:

    Code:
    'Rough example of a OpenFileDialog.

    Dim TheDialog As New OpenFileDialog 'creates a new instance of the OpenFileDialog class
    TheDialog.Title = "Select a File!" 'sets the title
    TheDialog.Show() 'shows the dialog
     
  11. Peter Simpson

    Peter Simpson Expert Licensed User

    @WhiteholeSoft we will have have to agree to disagree.
     
    ShaneG30 likes this.
  12. Erel

    Erel Administrator Staff Member Licensed User

    I don't aim to make B4X language more similar to VB.Net.
     
  13. Troberg

    Troberg Well-Known Member Licensed User

    I don't think there's much to be gained from making it more similar to VB.net. The one thing I'd like to see more of is a more developed object orientation (interfaces in particular, but inheritance (preferably multiple) would also be nice, no need for operator overloading), but that's quite possible to build on the current VB6-like framework.
     
    Last edited: Apr 29, 2015
  14. JakeBullet70

    JakeBullet70 Well-Known Member Licensed User

    As a paid VB.NET programmer in my day job I prefer B4X. It's just dead simple and easy to read. That's why I use it.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice