Function name choice
-
def widthOfLength(s: String) = s.length.toString.length
-
def widthOfLength(s: String) = s.length.toString.length
-
Do you think they [or you:suss:] chose width, as
lengthOfLength(s: String) = s.length.toString.length
would cause a meltdown.Dave Find Me On:Web|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject
I have to admit that "widthOfLength" seems OK to me. Obviously it is used to calculate the format/layout of some table perhaps where all the lengths are scanned to find the longest/widest. It is just a matter of semantics.
- I would love to change the world, but they won’t give me the source code.
-
I have to admit that "widthOfLength" seems OK to me. Obviously it is used to calculate the format/layout of some table perhaps where all the lengths are scanned to find the longest/widest. It is just a matter of semantics.
- I would love to change the world, but they won’t give me the source code.
You're absolutely right about the code purpose.:thumbsup:
-
def widthOfLength(s: String) = s.length.toString.length
Trying to determine how many decimal digits are required for the Length? A trick a colleague showed me once is to get the log 10 of the Length. Something like:
int y = (int) System.Math.Ceiling ( System.Math.Log10 ( new string ( '*' , 255 ).Length ) ) ;
-
def widthOfLength(s: String) = s.length.toString.length
-
Trying to determine how many decimal digits are required for the Length? A trick a colleague showed me once is to get the log 10 of the Length. Something like:
int y = (int) System.Math.Ceiling ( System.Math.Log10 ( new string ( '*' , 255 ).Length ) ) ;
PIEBALDconsult wrote:
new string ( '*' , 255 ).Length
Someone's getting paid by the character! :rolleyes:
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I don't understand language of your tribe, but I would go with extension method in C#. Something like this:
public static Int32 GetStringLength(this Int32 value)
s.Length.GetStringLength()
:DSmart K8 wrote:
I don't understand language of your tribe
My guess is python
John
-
Smart K8 wrote:
I don't understand language of your tribe
My guess is python
John
-
It's Scala actually and both Forogar and PIEBALDconsult are right about the function purpose. It is taken from a small example that reads a text file and prints it out displaying each line's length before it and the function makes sure that all lines are aligned/tabulated correctly.