Strict v. Non-Strict Naming Convention in Functions?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Strict v. Non-Strict Naming Convention in Functions?

Kevin Meredith
Given a function `f` with a single argument, `x`, I have a need for passing x both strictly and non-strictly.

Example:

def fStrict(x: Int)             = ???

def fNonStrict(x: => Int) = ???

I don't like explicitly putting strict and non-strict in the names. 

Does anyone have a convention for how to name both functions?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Strict v. Non-Strict Naming Convention in Functions?

Peter Salanki
Kevin,

As you know. The two parameter signatures, albeit visually similar have very different meaning. The first one accepts an integer, and the second one a function that returns an integer. This can have wide ranging implications in both performance and functionality. I am wondering if having two versions of the same function, one by name and one by value is the right way to go. Without knowing your use case it's of course hard to give an educated opinion, but it seems to me that it would bloat your API and confuse users more than providing the "preferred" route and let the caller turn it into a function / defer the entire method call as necessary.

Sincerely,
Peter Salanki

On Feb 17, 2017, at 08:57, Kevin Meredith <[hidden email]> wrote:

Given a function `f` with a single argument, `x`, I have a need for passing x both strictly and non-strictly.

Example:

def fStrict(x: Int)             = ???

def fNonStrict(x: => Int) = ???

I don't like explicitly putting strict and non-strict in the names. 

Does anyone have a convention for how to name both functions?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Strict v. Non-Strict Naming Convention in Functions?

Kevin Meredith
>The first one accepts an integer, and the second one a function that returns an integer.

For the second, it's technically not a function though, is it?

Although I see how a 0-arg call by-name argument behaves like Function0.

On Friday, February 17, 2017 at 9:26:00 AM UTC-5, Peter Salanki wrote:
Kevin,

As you know. The two parameter signatures, albeit visually similar have very different meaning. The first one accepts an integer, and the second one a function that returns an integer. This can have wide ranging implications in both performance and functionality. I am wondering if having two versions of the same function, one by name and one by value is the right way to go. Without knowing your use case it's of course hard to give an educated opinion, but it seems to me that it would bloat your API and confuse users more than providing the "preferred" route and let the caller turn it into a function / defer the entire method call as necessary.

Sincerely,
Peter Salanki

On Feb 17, 2017, at 08:57, Kevin Meredith <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="sEjPedIBCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">kevin.m....@...> wrote:

Given a function `f` with a single argument, `x`, I have a need for passing x both strictly and non-strictly.

Example:

def fStrict(x: Int)             = ???

def fNonStrict(x: => Int) = ???

I don't like explicitly putting strict and non-strict in the names. 

Does anyone have a convention for how to name both functions?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="sEjPedIBCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">scala-user+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Strict v. Non-Strict Naming Convention in Functions?

Jasper-M
Conceptually it's not a Function0, but technically under the hood it is implemented with a Function0. Depending on your interpretation of the words conceptually and technically, I guess...

Kind regards,
Jasper

Op vrijdag 17 februari 2017 20:02:10 UTC+1 schreef Kevin Meredith:
>The first one accepts an integer, and the second one a function that returns an integer.

For the second, it's technically not a function though, is it?

Although I see how a 0-arg call by-name argument behaves like Function0.

On Friday, February 17, 2017 at 9:26:00 AM UTC-5, Peter Salanki wrote:
Kevin,

As you know. The two parameter signatures, albeit visually similar have very different meaning. The first one accepts an integer, and the second one a function that returns an integer. This can have wide ranging implications in both performance and functionality. I am wondering if having two versions of the same function, one by name and one by value is the right way to go. Without knowing your use case it's of course hard to give an educated opinion, but it seems to me that it would bloat your API and confuse users more than providing the "preferred" route and let the caller turn it into a function / defer the entire method call as necessary.

Sincerely,
Peter Salanki

On Feb 17, 2017, at 08:57, Kevin Meredith <[hidden email]> wrote:

Given a function `f` with a single argument, `x`, I have a need for passing x both strictly and non-strictly.

Example:

def fStrict(x: Int)             = ???

def fNonStrict(x: => Int) = ???

I don't like explicitly putting strict and non-strict in the names. 

Does anyone have a convention for how to name both functions?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Strict v. Non-Strict Naming Convention in Functions?

Rex Kerr-2
In reply to this post by Kevin Meredith
In the very very rare cases (actually, I only remember one) where I needed to do this and didn't immediately rip it out as confusing, I called the strict one `f` and the non-strict one `fByName`.

If you know what a by name parameter is, it's very clear.  If you don't, it doesn't get at the distinction at all, so it's not so great.  ("fLazyArg" would be more instructive.)

The problem with Strict in my opinion is that it requires the same level of knowledge as ByName to make sense, but isn't as precise leaving one to wonder what isn't strict about it.

  --Rex

On Fri, Feb 17, 2017 at 5:57 AM, Kevin Meredith <[hidden email]> wrote:
Given a function `f` with a single argument, `x`, I have a need for passing x both strictly and non-strictly.

Example:

def fStrict(x: Int)             = ???

def fNonStrict(x: => Int) = ???

I don't like explicitly putting strict and non-strict in the names. 

Does anyone have a convention for how to name both functions?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.