Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

auto as C++0x


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 FDsagizi   Members   -  Reputation: 514

Like
0Likes
Like

Posted 31 January 2013 - 12:35 AM

Hi smile.png

what you think about "auto" as c++ C++0x - this is difficult add to script ?

 

 

Exemple:

class SomeClassName
{    
    void DoSome(){}
}    

SomeClassName @Get()
{
    return ...
}

void F()
{
    auto a = Get();
    a.DoSome();
} 
 

Edited by FDsagizi, 31 January 2013 - 12:37 AM.


Sponsor:

#2 Cornstalks   Crossbones+   -  Reputation: 6974

Like
0Likes
Like

Posted 31 January 2013 - 02:33 AM

Sorry, I'm not sure what you're asking. Personally, I only use auto for unweildly/very long typenames, like std::map<std::string, MyClass>::const_iterator, for example.

 

What's difficult about your code is that it's not clear what Get() returns (from just reading the function F()). If it were perhaps more appropriately named, it would help improve the clarity of your code.

 

Completely ignore this post! I didn't realize this was the AngleCode forum... sorry for being so blind! I thought FDsagizi might be asking what people thought of auto and if it was good to use it in the following code. I realize now that I wasn't even remotely close (and where's GameDev's embarrassed smiley!?).


Edited by Cornstalks, 31 January 2013 - 07:45 AM.

[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#3 Hodgman   Moderators   -  Reputation: 28780

Like
0Likes
Like

Posted 31 January 2013 - 02:35 AM

Sorry, I'm not sure what you're asking

We're in the AngelCode sub-forum -- he's asking about adding C++0x-esque auto to AngelScript.

#4 Andreas Jonsson   Moderators   -  Reputation: 3269

Like
0Likes
Like

Posted 31 January 2013 - 07:12 AM

I think 'auto' is a useful feature in C++, especially when writing template functions, or even macros. 

 

In AngelScript I can see 'auto' being useful for the mixin classes, and as such I have it on my to-do list to study the possibility of implementing it, however its currently very low on my priority.

 

It's not an easy feature to implement. It would reverse the order things are evaluated in the compiler right now, as it is necessary to first determine the type of the expression and only then declare the actual variable. 


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#5 Cornstalks   Crossbones+   -  Reputation: 6974

Like
0Likes
Like

Posted 31 January 2013 - 07:41 AM

Sorry, I'm not sure what you're asking

We're in the AngelCode sub-forum -- he's asking about adding C++0x-esque auto to AngelScript.

Oh... wow... I'm an idiot. Sorry folks!


[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#6 saejox   Members   -  Reputation: 714

Like
0Likes
Like

Posted 31 January 2013 - 01:16 PM

I used to think type inference would be a great addition to AngelScript.

As i used it more and more in C++, i have turned around.

I see two problems with it.

 

1. AngelScript does not have templates or generics. It doesn't have nested classes neither.

It's not possible to create conventional iterators.

Auto is practically useless without long type names to infer.

 

2. Auto is not magic. You still need to determine if it's an handle, reference or value.

This is a great source of confusion, unwanted constructor/destructor calls and bunch of other nasty bugs.



#7 Andreas Jonsson   Moderators   -  Reputation: 3269

Like
0Likes
Like

Posted 31 January 2013 - 01:42 PM

AngelScript's mixin classes are generics, and auto can definitely come in handy in such cases. Example:

 

mixin class MyGenericImpl
{
   void func()
   {
      auto c = a + b;
      DoSomething(c);
   }
}
 
class A : MyGenericImpl
{
  int a, b;
}
 
class B : MyGenericImpl
{
  float a, b;
}

 

The variable c in the func() method will have the int type in class A, and the float type in class B, as the code for the mixin class is only compiled in the context where it was included.

 

 

In my opinion, auto is not supposed to be used to infer long type names. That should be done with the use of typedefs to declare a shorter alias for the long types. Currently AngelScript only supports creating aliases for primitive types with typedefs, but eventually I'll allow any type to be used in typedefs.

 

The use of auto outside generic code is not something I recommend, for much the same reasons that saejox mentioned. It would make it much harder to know what type is actually acted upon, thus make it more difficult to read the code.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#8 saejox   Members   -  Reputation: 714

Like
0Likes
Like

Posted 31 January 2013 - 09:10 PM

That's an interesting use of mixins :)

I didn't go beyond code reuse and separating same class in multiple files.

 

I have just read your ideas page.

I thought i should make a list myself. :)

 

1. Function pointers and function objects

2. Template objects with multiple subtypes

3. Inheritance from registered classes. Without this your whole program design changes, it sucks.

4. Closures/Anonymous functions/Lambdas. Functional programming is the best.

5. Builtin array, set and maps. Everyone needs them, why are they addons. They can still be optional, but builtin is a must. If they are builtin i can finally write some AngelScript only programs. I can write a 1000 word essay how important built-in containers are for a language.

6. Static functions. Great for organization.

7. Generic handle. like ref addon but supports all types and can implicitly convert.

8. Varidic functions. Or functions with argument array. void MyFunction(args). Would be easy with #7

9. Type comparison. if( typeof(my_int) == int ). This may even be a switch/select statement. Useless without #8

10. Unsafe keyword. Mark functions and objects to be free of garbage collection. Also warn user of the dangers. Maybe go crazy with pointers.

11. new and delete. Unmanaged memory for all types. ( would be double awesome with unsafe keyword)

12. Stateful functions. With a keyword like 'yield' . Pause execution, resume when called by other later. Script languages are great for stuff like this.

13. Reflection. No not as powerful as js or lua. At least functions like createClass .addMethod("func()") .invoke("func")

 

These are just stuff i like, no need for a feedback. You are likely very busy.



#9 Andreas Jonsson   Moderators   -  Reputation: 3269

Like
0Likes
Like

Posted 01 February 2013 - 07:32 AM

1. coming. delegates and also the opCall operator (same as C++ operator())

2. coming. though probably only as registered classes

3. I would like to do this, but I really don't see a proper solution for it. 

4. probably one day

5. no. I provide them as add-ons because not everyone has the same needs. The add-ons are as good as built-in, but more flexible as you can easily change them the way you want. The engine core shall provide the necessary hooks for the add-ons to work seemlessly

6. one day

7. add-on

8. one day

9. add-on

10 & 11. maybe. I do have an interest in adding support for pure pointers again, though with an engine property to turn it off where sandboxing is required

12. as much as possible in add-on, but with necessary support from engine

13. add-on with support for incremental compilation in the engine


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#10 saejox   Members   -  Reputation: 714

Like
0Likes
Like

Posted 01 February 2013 - 09:15 AM

I think i can live without built-in containers. Still, i just feel addon's are not the same. VM could do much better job. Compiler time optimization, better memory layout, avoid unnecessary ref counting, weak iterators etc..

Anyway, that's what i think. I can't even write a simple parser. My suggestions are probably worthless :)

 

Delegates and multiple subtypes are going to be revolutionizing.

I will rewrite half my AngelScript code. Can wait :D






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS