-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functions without parameters #222
Comments
Usually if not always it's enough to use fake (unused) parameters, which can get messy in larger projects; they allow a lot of poetic freedom, but it would probably still be possible to use them anyways. I think it would still be good to easily recognize the functions, unless that's a main point of your proposal and useful for your extention. Using "taking nothing" is out of question, "takes nothing/nowhere" isn't problematic and sounds good, but can still be confusing. I thought about "takes/taking a pill/a sip" and other options which shouldn't be mentioned. Probably the best one was "takes/taking it easy", but I don't know how easy it is to avoid the "it" being wrongly interpreted. |
@hapaxlego I agree with you that we can always use dummy paramterers. My proposal is that we should avoid them, if we can - to avoid the mess, as you wrote. The goal of my proposal is to clear the code and make it more readable. There will be a lot of parameterless accessors in an OOP code, if we need to use dummies all the time that makes it really messy. It was not my primary goal to mix variables and functions, though it is a valid case I think. In an OOP language accessors are nothing else but wrappers of a field access (e.g. in Java sometimes synthetical accessor methods are generated to allow field access) - in this sense, most parameterless function calls will be simple variable references (just bypassing the encapsulation boundary). So, I think that the Also, think of this example. Suppose we have the
Then my last example would look like this:
Which is really ugly IMHO. We should not overdose the Regarding |
The "taking" overuse was also mine major doubt, and using variable-like names for getters makes sense. Readability is not a primar goal and someone can make it clear it's a function just with name choises, at least in minimalistic code. |
In Rockstar, we have these marvellous functions that take parameters, just like this:
However, it is not possible to define a function that accepts zero parameters. In this proposal I recommend a syntax for this. Currently there's no much need for them, but hopefully in the future we can use them more extensively.
The proposal is simple:
takes nothing
(or other alias fornull
value likenowhere
ornobody
)taking
part off. Technically the function name behaves like if it was a variable - if there is a function defined with that name, we can call the function, otherwise we need to access the variable. (The function names should have priority over the variables)An example:
Currently I'm working on an OOP extension proposal, and this feature is necessary for the accessors - at least it would ease the way to write them. So, in the future functions will be able to access more than the global variables - and there will be much more parameterless (getter) functions than at this moment.
The text was updated successfully, but these errors were encountered: