Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Function name choice

Function name choice

Scheduled Pinned Locked Moved The Weird and The Wonderful
10 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Otto Grunf
    wrote on last edited by
    #1

    def widthOfLength(s: String) = s.length.toString.length

    D P S 3 Replies Last reply
    0
    • O Otto Grunf

      def widthOfLength(s: String) = s.length.toString.length

      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      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

      F 1 Reply Last reply
      0
      • D DaveAuld

        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

        F Offline
        F Offline
        Forogar
        wrote on last edited by
        #3

        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.

        O 1 Reply Last reply
        0
        • F Forogar

          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.

          O Offline
          O Offline
          Otto Grunf
          wrote on last edited by
          #4

          You're absolutely right about the code purpose.:thumbsup:

          1 Reply Last reply
          0
          • O Otto Grunf

            def widthOfLength(s: String) = s.length.toString.length

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            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 ) ) ;

            Richard DeemingR 1 Reply Last reply
            0
            • O Otto Grunf

              def widthOfLength(s: String) = s.length.toString.length

              S Offline
              S Offline
              Smart K8
              wrote on last edited by
              #6

              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() :D

              J 1 Reply Last reply
              0
              • P PIEBALDconsult

                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 ) ) ;

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                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

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                1 Reply Last reply
                0
                • S Smart K8

                  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() :D

                  J Offline
                  J Offline
                  John M Drescher
                  wrote on last edited by
                  #8

                  Smart K8 wrote:

                  I don't understand language of your tribe

                  My guess is python

                  John

                  S 1 Reply Last reply
                  0
                  • J John M Drescher

                    Smart K8 wrote:

                    I don't understand language of your tribe

                    My guess is python

                    John

                    S Offline
                    S Offline
                    Smart K8
                    wrote on last edited by
                    #9

                    OK, thanks.

                    O 1 Reply Last reply
                    0
                    • S Smart K8

                      OK, thanks.

                      O Offline
                      O Offline
                      Otto Grunf
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups