Skip to content
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

Open
gaborsch opened this issue Sep 3, 2019 · 3 comments
Open

Functions without parameters #222

gaborsch opened this issue Sep 3, 2019 · 3 comments
Milestone

Comments

@gaborsch
Copy link

gaborsch commented Sep 3, 2019

In Rockstar, we have these marvellous functions that take parameters, just like this:

scale takes X, Y and Z
give back X times Y plus Z

say scale taking 1, 2, and 3 (output: "5")

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:

  • in the method declaration we declare takes nothing (or other alias for null value like nowhere or nobody)
  • in the method call we simply leave the 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:

Let the sequence be 0

next takes nothing                (parameterless method declaration)
Build the sequence up
give back the sequence 

say next                          (output: "1")
the hunter says " elephants"
say next plus the hunter          (output: "2 elephants")
say next of 2                     (output: "6")
say next minus next               (output: "-1")

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.

@hapaxlego
Copy link

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.

@gaborsch
Copy link
Author

gaborsch commented Sep 5, 2019

@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 taking keyword to denote a function call is not necessary.

Also, think of this example. Suppose we have the next function defined like this:

next takes dummy
Build the sequence up
give back the sequence 

Then my last example would look like this:

say next taking dummy minus next taking dummy

Which is really ugly IMHO. We should not overdose the taking keyword. Also, if we introduce the object reference, it will be more confusing.

Regarding a pill / a sip: they're perfect for dummy placeholders. But you cannot overdose taking a pill or takes it easy either. I think that such kind of repetition would kill the lyrics.

@hapaxlego
Copy link

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.
Probably your example could be made a little less ugly if splittet into more expression, but to expand functonalities it's better to keep things simple.
I think "taking" is already a bit overused so some aliases for take/taking wuldn't hurt, but there's a lot of pending alias discussion, so I'll leave it alone for now.
Glad you liked the placeholders.

@dylanbeattie dylanbeattie added this to the 2.0 milestone Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants