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. The Lounge
  3. The (strange) case against very long and explicit variable names, with Math

The (strange) case against very long and explicit variable names, with Math

Scheduled Pinned Locked Moved The Lounge
helpquestioncsharpmobilecom
18 Posts 15 Posters 1 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.
  • S Super Lloyd

    I am working with Xamarin forms and there is a problem with FormsAppCompat size after softkeyboard is shown on screen. There is a bit of a fix copied verbatim all over the web which can (also) be found there: [Accommodating The On Screen Keyboard in Xamarin Forms - Xamarin Help](https://xamarinhelp.com/accommodate-on-screen-keyboard-xamarin-forms/) My particular beef is with those lines copied in so many places

        int usableHeightNow = computeUsableHeight();
        if (usableHeightNow != usableHeightPrevious)
        {
            int usableHeightSansKeyboard = mChildOfContent.RootView.Height;
            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
    
            frameLayoutParams.Height = usableHeightSansKeyboard - heightDifference;
    

    This looks painfully complicated, doesn't it? That's probably why it has been copied verbatim in so many places. Now, as a thought exercise let's use those so called "evil and short and meaningless" variable names

        int a = computeUsableHeight();
        if (a != usableHeightPrevious)
        {
            int b = mChildOfContent.RootView.Height;
            int d = b - a;
    
            frameLayoutParams.Height = b - d;
    

    what is immediately visible now? well frameLayoutParams.Height = b - d = b - (b - a) = a hence the all thing can be simplified to:

        int a = computeUsableHeight();
        if (a != usableHeightPrevious)
        {
            frameLayoutParams.Height = a;
    

    All of that to say that those "long and meaningful" variable names are really an hindrance...

    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

    S Offline
    S Offline
    StM0n
    wrote on last edited by
    #9

    :) the old "but someone said you should use meaningful variable names" and c&p-coding without getting a grip. I would rather tend to rename a back to usableHeightNow... for readability :laugh:

    (yes|no|maybe)* "Fortunately, we don't need details - because we can't solve it for you." - OriginalGriff

    1 Reply Last reply
    0
    • S Super Lloyd

      I am working with Xamarin forms and there is a problem with FormsAppCompat size after softkeyboard is shown on screen. There is a bit of a fix copied verbatim all over the web which can (also) be found there: [Accommodating The On Screen Keyboard in Xamarin Forms - Xamarin Help](https://xamarinhelp.com/accommodate-on-screen-keyboard-xamarin-forms/) My particular beef is with those lines copied in so many places

          int usableHeightNow = computeUsableHeight();
          if (usableHeightNow != usableHeightPrevious)
          {
              int usableHeightSansKeyboard = mChildOfContent.RootView.Height;
              int heightDifference = usableHeightSansKeyboard - usableHeightNow;
      
              frameLayoutParams.Height = usableHeightSansKeyboard - heightDifference;
      

      This looks painfully complicated, doesn't it? That's probably why it has been copied verbatim in so many places. Now, as a thought exercise let's use those so called "evil and short and meaningless" variable names

          int a = computeUsableHeight();
          if (a != usableHeightPrevious)
          {
              int b = mChildOfContent.RootView.Height;
              int d = b - a;
      
              frameLayoutParams.Height = b - d;
      

      what is immediately visible now? well frameLayoutParams.Height = b - d = b - (b - a) = a hence the all thing can be simplified to:

          int a = computeUsableHeight();
          if (a != usableHeightPrevious)
          {
              frameLayoutParams.Height = a;
      

      All of that to say that those "long and meaningful" variable names are really an hindrance...

      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

      M Offline
      M Offline
      Mark_Wallace
      wrote on last edited by
      #10

      I agree. usableHeightNow and usableHeightPrevious don't even meet the requirements of meaningful naming. They should be currentComputedValueOfUsableHeight and usableHeightExtantBeforeTheCurrentValueWasComputed [edit] What a time to typo "extant"! Open a ticket; the bloody code won't compile! [/edit]

      I wanna be a eunuchs developer! Pass me a bread knife!

      1 Reply Last reply
      0
      • J Jorgen Andersson

        The problem isn't the length of the variable names. (Even though they might be some times) The problem is that the original author didn't think all the way, but even worse, that everyone else is just copy'n'pasting. Take a look at your refactored code with the original variable names:

            int usableHeightNow = computeUsableHeight();
            if (usableHeightNow != usableHeightPrevious)
            {
                frameLayoutParams.Height = usableHeightNow;
        

        It's not that bad anymore is it?

        Wrong is evil and must be defeated. - Jeff Ello

        N Offline
        N Offline
        Nicholas Marty
        wrote on last edited by
        #11

        or... if the Height is a field or a property without side effects in the setter:

        frameLayoutParams.Height = computeUsableHeight();

        J 1 Reply Last reply
        0
        • N Nicholas Marty

          or... if the Height is a field or a property without side effects in the setter:

          frameLayoutParams.Height = computeUsableHeight();

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #12

          I thought so as well, but if you follow the link in the OP you'll notice there's more code inside the conditional.

          Wrong is evil and must be defeated. - Jeff Ello

          1 Reply Last reply
          0
          • V V 0

            Super Lloyd wrote:

            All of that to say that those "long and meaningful" variable names are really an hindrance...

            That greatly depends on the situation. If you use it locally, like in the example. I fully agree. If you need to use it elsewhere, however,... ;)

            V.

            (MQOTD rules and previous solutions)

            M Offline
            M Offline
            Mark_Wallace
            wrote on last edited by
            #13

            That's the trouble. You end up with 7,000 private instances of a, b, and c. Better is to use meaningful names that don't all start with the same characters (in this case "usableHeight"), and let intellisense do its magic. nowUsableHeight and newUsableHeight aren't such a pain, but are clear enough.

            I wanna be a eunuchs developer! Pass me a bread knife!

            1 Reply Last reply
            0
            • J Jorgen Andersson

              The problem isn't the length of the variable names. (Even though they might be some times) The problem is that the original author didn't think all the way, but even worse, that everyone else is just copy'n'pasting. Take a look at your refactored code with the original variable names:

                  int usableHeightNow = computeUsableHeight();
                  if (usableHeightNow != usableHeightPrevious)
                  {
                      frameLayoutParams.Height = usableHeightNow;
              

              It's not that bad anymore is it?

              Wrong is evil and must be defeated. - Jeff Ello

              M Offline
              M Offline
              megaadam
              wrote on last edited by
              #14

              You are right Jörgen but even worse, that everyone else is just copy'n'pasting. :cool:

              ... such stuff as dreams are made on

              1 Reply Last reply
              0
              • S Super Lloyd

                I am working with Xamarin forms and there is a problem with FormsAppCompat size after softkeyboard is shown on screen. There is a bit of a fix copied verbatim all over the web which can (also) be found there: [Accommodating The On Screen Keyboard in Xamarin Forms - Xamarin Help](https://xamarinhelp.com/accommodate-on-screen-keyboard-xamarin-forms/) My particular beef is with those lines copied in so many places

                    int usableHeightNow = computeUsableHeight();
                    if (usableHeightNow != usableHeightPrevious)
                    {
                        int usableHeightSansKeyboard = mChildOfContent.RootView.Height;
                        int heightDifference = usableHeightSansKeyboard - usableHeightNow;
                
                        frameLayoutParams.Height = usableHeightSansKeyboard - heightDifference;
                

                This looks painfully complicated, doesn't it? That's probably why it has been copied verbatim in so many places. Now, as a thought exercise let's use those so called "evil and short and meaningless" variable names

                    int a = computeUsableHeight();
                    if (a != usableHeightPrevious)
                    {
                        int b = mChildOfContent.RootView.Height;
                        int d = b - a;
                
                        frameLayoutParams.Height = b - d;
                

                what is immediately visible now? well frameLayoutParams.Height = b - d = b - (b - a) = a hence the all thing can be simplified to:

                    int a = computeUsableHeight();
                    if (a != usableHeightPrevious)
                    {
                        frameLayoutParams.Height = a;
                

                All of that to say that those "long and meaningful" variable names are really an hindrance...

                A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                N Offline
                N Offline
                Nathan Minier
                wrote on last edited by
                #15

                I fundamentally disagree. In the age before the IDE and Intellisense this argument held some water, since descriptive variable names translated directly into writing time. These days I rarely need to type more than three characters and I've locked into the variable that I need. Long variable names provide description and context, and lead to self-documenting code: that Utopian dream where source code can be quickly understood without being riddled with // or /**/. The other point is that source code is for people. In the future, that set of people may include you or it may not, but the code will need to be pulled out, brushed off, and modified at some point. A terse variable name may make perfect sense to you, but the next guy is not you and it may or may not to him. I guarantee that a nice, descriptive name will, though.

                "There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli

                Richard Andrew x64R 1 Reply Last reply
                0
                • N Nathan Minier

                  I fundamentally disagree. In the age before the IDE and Intellisense this argument held some water, since descriptive variable names translated directly into writing time. These days I rarely need to type more than three characters and I've locked into the variable that I need. Long variable names provide description and context, and lead to self-documenting code: that Utopian dream where source code can be quickly understood without being riddled with // or /**/. The other point is that source code is for people. In the future, that set of people may include you or it may not, but the code will need to be pulled out, brushed off, and modified at some point. A terse variable name may make perfect sense to you, but the next guy is not you and it may or may not to him. I guarantee that a nice, descriptive name will, though.

                  "There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli

                  Richard Andrew x64R Offline
                  Richard Andrew x64R Offline
                  Richard Andrew x64
                  wrote on last edited by
                  #16

                  Wholeheartedly agree! :cool:

                  The difficult we do right away... ...the impossible takes slightly longer.

                  1 Reply Last reply
                  0
                  • S Super Lloyd

                    I am working with Xamarin forms and there is a problem with FormsAppCompat size after softkeyboard is shown on screen. There is a bit of a fix copied verbatim all over the web which can (also) be found there: [Accommodating The On Screen Keyboard in Xamarin Forms - Xamarin Help](https://xamarinhelp.com/accommodate-on-screen-keyboard-xamarin-forms/) My particular beef is with those lines copied in so many places

                        int usableHeightNow = computeUsableHeight();
                        if (usableHeightNow != usableHeightPrevious)
                        {
                            int usableHeightSansKeyboard = mChildOfContent.RootView.Height;
                            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
                    
                            frameLayoutParams.Height = usableHeightSansKeyboard - heightDifference;
                    

                    This looks painfully complicated, doesn't it? That's probably why it has been copied verbatim in so many places. Now, as a thought exercise let's use those so called "evil and short and meaningless" variable names

                        int a = computeUsableHeight();
                        if (a != usableHeightPrevious)
                        {
                            int b = mChildOfContent.RootView.Height;
                            int d = b - a;
                    
                            frameLayoutParams.Height = b - d;
                    

                    what is immediately visible now? well frameLayoutParams.Height = b - d = b - (b - a) = a hence the all thing can be simplified to:

                        int a = computeUsableHeight();
                        if (a != usableHeightPrevious)
                        {
                            frameLayoutParams.Height = a;
                    

                    All of that to say that those "long and meaningful" variable names are really an hindrance...

                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                    G Offline
                    G Offline
                    Gary Wheeler
                    wrote on last edited by
                    #17

                    Long and meaningful variable names are useful in a long-term, global context. In this case, those longer names are obscuring their actual use in a local context. If you have a complicated calculation that references those names, copy the incoming values to shorter names for purposes of performing the calculation, thereby making it more readable.

                    Software Zen: delete this;

                    1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      I agree.

                      R Offline
                      R Offline
                      raddevus
                      wrote on last edited by
                      #18

                      Here's the likely truth Everyone who likes the short (letter) var names 1) is 45 or older (you've read K&R :) ) 2) codes alone and not as part of a team (it don't matter cuz it's write-once code) 3) All of the above :laugh: (but I'm kind of not laughing too, because when you read someone else's code like that you have to read it a few times). I'd much rather read someone else's code <=1 time. :-D

                      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