Forum Replies Created
-
AuthorPosts
-
Thanks. Unfortnately I don’t have to time to make up a network stack for it. I might have to look at Unity again.
Cheers
Thanks for the reply @cocon. I’m very familiar with OO and C++ (I do it for a job), my concern is the potential danger when tying ref/value semantics to the declaration of a type. As I outlined above there’s some potentially very dangerous issues that can arise and I feel the code is less easy to reason about (You need to get back to the declaration). The latter can be solved in some part with a great IDE but TED isn’t there yet.
In your example above, the reasoning is only clearer because you’ve essentially used a variant of Hungarian notation by adding Struct to the type name. I think this is bad form in and of itself, however if the functions were generics, you wouldn’t see that even.
[/crayon]Monkey123456[crayon-5cba951bbff2e308999852 inline="true" ]Class Bob<T>Method Grow(t:T, amount:UInt)t.width += amountt.height += amountEndEndDoes completely different things if the ‘t’ passed in was a struct or class. The compiler at present can’t help either as it’s OK to use either struct or class.
I’ve probably belaboured the point
In my experience, the fact that the code for a struct instance and class instance looks identical, but behaves differently is potentially dangerous. C++ has it too of course (Although it provides some protection with non reassignment of references) but finding the solution is fast (Look at the function signature) as opposed to having to go to the declaration.
If I had
[/crayon]Monkey12345678[crayon-5cba951bc3a9b070305776 inline="true" ]Method LogansRun(a:MyThing)If a.age > 29 Thena.alive = FalseEndIf a.alive = False ThenPlaySombreMusic()EndEndThis is contrived of course but what happens on function end? Is a changed or not? My understanding is that a is NOT changed in the caller if it’s a struct, but if it’s a class it is. This is compounded more by the fact that if you later change from struct to class (Maybe you want to extend from something), the program behaves completely differently and you’d likely have to refactor a lot of code. Now there might be solutions in Monkey that solve these issues, I’m still really new to it, but when I see by value/ref based on struct/class it raises some red flags
Without knowing the internals I’m not sure how having it user specified would cause too many problems, it’s just moving the issue from the declaration to the called function which I think is where a user would want to specify certain behaviour. Sure you’d have to have some qualifiers in some case, but maybe making the default case be “by reference” you could reduce the need for it immensely. For instance if everything was by ref by default, potentially one keyword could be used for the other cases
[/crayon]Monkey123456789101112[crayon-5cba951bc3aa1498982274 inline="true" ]Method LogansRun(a:MyThing ByValue)If a.age > 9 Thena.alive = falseEndIf a.alive = False ThenPlaySombreMusic()EndLocal b := a ' Obviously by references as that's the defaultLocal c := a.Clone() orLocal c:MyThing ByValue = a orLocal c := Copy aEndIf you hated ByValue maybe if function signature has () that means “construct a new one” as in
[/crayon]Monkey12[crayon-5cba951bc3aa6859777501 inline="true" ]Method LogansRun(a:MyThing()) ' Not sure if this is clearer than the one aboveEndAnyway, not trying to be a dick just trying to provide some feedback based on concerns about proneness to errors with the way it currently is.
Cheers
Gotcha.
Question. Was there a reason structs are by-value and classes are by-reference as opposed to allowing the user to specify? I find the former is more error prone because the ref/value semantics is not localised; you need to go to the declaration or documentation to find out what it would be and remember it. Having it user specified would make it clear at the point of definition.
I also noticed that there is a Ptr keyword which might solve my problem however I’m not sure how to get the address of an object to set it.
Hi Mark, not sure what you mean. My minimal code was what I needed; that is, nested template structs.
@cocon I just need macros to wrap code so I can do something like this
REQUIRES(DoSomething() = false) and have the code portion both checked and put into an exception to help with error tracking.
Basically if you look at any C++ UNIT testing framework like Catch etc, then I want that sort of functionality.
Just to add, if Jim<> was declared as a class, it would build fine.
Seems like a lot of restrictions to avoid type slicing; something common in another languages (Especially C/++).
The way structs are is trading one “issue” for another. That is, you have to continually look at the declaration of your types to check whether they are by value or ref which I don’t think should ever have to be the case; code should be self documenting. It’s also now forcing people who want to use virtual functions to have by ref (And effectively heap allocated objects) which is taking away their control over performance.
I actually wonder if it would have been better for Monkey (and c++ to be honest), to just not allow assignment that causes slicing. I’m having trouble right now, thinking of a single use case where I have ever needed to do this. i.e. It’s always been mistake.
Thanks, extends is what what I wanted to do; I just needed to add some member functions to Vec2i
I don’t see the logic of not allowing extends on a Struct – it seems pretty arbitrary. If there’s nothing virtual, no need for a virtual function table so no overhead.
One thing I’ve found as I’ve gotten into Monkey2 a bit more is that documentation is really lacking. Or maybe it’s the search function in the docs that doesn’t work well. Either way I often can’t find what I’m after
But I have it as a struct so I can have value semantics given the bizarre choice to have structs by value and classes by ref?!?!?!
I can only find 1.1.01 in the files. Is there a beta section somewhere where I can get the latest?
Cool, can’t wait to see what you’re doing
First, great work on Ted for Monkey 2. One small thing I’d like is to have the key mappings fixed on OSX. I have to use CTRL-C to copy and SPLAT-V to paste.
Is this editor a thing we can buy/get?
Holy Smoke. So I come back to look at Monkey 2 and find Pyro 2 is free!? I have to say that’s a very generous thing to do.
I see in this thread there’s a particle editor and some sort of Pyro editor. However I can’t see those for sale or such on your itch.io site. Are they available yet?
Thanks
Aaron
-
AuthorPosts