Closed deathbeam closed 8 years ago
What if at some point in the future you want to add immutable variables, you define a new operator?
also what if you want to define but not assign? the classic example would be:
def something;
if(condition)
something = "test"
def something
isnt valid syntax anyway. You need to atleast use def something : String
. But yes, I also though about that. If you will want to define something and not assign, you will use default value for your type, so false for booleans, 0 for numbers and null for rest.
:= FTW !
I like it! 'def' is used for functions, and 'var' for variables, and then this suggestion is better. when inside a function, you can assign directly. That's very nice. for your information, there is another language that does that: http://cobra-language.com/ if you want to check pitfalls of your idea doesn't seem to have a problem.
What about returning or assigning multiple values?
a,b := 3,4
or
a,b := return2()
or
a,b,rest = [1,2,3,4,5] # a = 1, b = 2, c = [3,4,5]
when you add parsing to this feature, think if you want to support multiple assignment.
:+1:
Will removing the def mean that you can declare the class member inside your ctor (a la ruby and python)? Because I don't like how you currently have to repeat yourself like in C-like languages currently.
Would it be bad to treat the first assignment as a declaration as well and default to Dynamic for the type (or simply leave it out and let haxe sort out if it's allowable or not)
First assignment as declaration can be very hard with current compiler state. And what do you mean declaring the class member inside "actor"?
ctor = consctuctor. Like I like how in ruby and python, you can just do this:
class Blah:
# I don't need to declare count here
def __init__(self):
self.count = 0
It helps prevent repeating yourself to only have to declare it one place or another. Also reduces the likelihood of having an uninitialized member variable.
that's like Lua. There is a problem with this approach: what if you have a spelling mistake? the compiler will allow this. a static language is much safer in this regard. my opinion is that it doesn't fit raxe, but that's only one opinion among many.
I am going to use the Ruby-Python way of declaring variables, so closing this.
So I am opening this issue, because this is open-source project and I am trying to make it more "community-driven". So, I am deciding about new syntax for defining a variable.
Currently, we have this syntax=
And I want to remove the
def
and add new:=
keyword:So?