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. Hungarian UIs

Hungarian UIs

Scheduled Pinned Locked Moved The Lounge
questionwpfdesigntutorial
67 Posts 39 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.
  • C c2423

    I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

    Y Offline
    Y Offline
    YvesDaoust
    wrote on last edited by
    #38

    It seems obvious that these two controls belong together. So it makes sense to group them in a single class "LabeledText", having two fields: "Something.Label" and "Something.Text". With the added benefit that the class can automatically enforce coherence of the two controls.

    I 1 Reply Last reply
    0
    • C c2423

      I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

      J Offline
      J Offline
      Jonathan C Dickinson
      wrote on last edited by
      #39

      lblUsername, txtUsername That's why. The 'correct' solution is presented by WPF (and HTML): you don't *need* to name controls. However, when I am doing Winforms: usernameTextBox, usernameLabel. No idea why, it's just style preference (or possibly hungarian aversion).

      He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chinese Proverb] Jonathan C Dickinson (C# Software Engineer)

      G C 2 Replies Last reply
      0
      • Y YvesDaoust

        It seems obvious that these two controls belong together. So it makes sense to group them in a single class "LabeledText", having two fields: "Something.Label" and "Something.Text". With the added benefit that the class can automatically enforce coherence of the two controls.

        I Offline
        I Offline
        irneb
        wrote on last edited by
        #40

        YvesDaoust wrote:

        With the added benefit that the class can automatically enforce coherence of the two controls.

        Some older libraries actually did do it this way. One that jumps to mind is Delphi's Borland Foundation Classes. But then you also ended up with other issues, e.g. say you wanted the label above the control? Do you need to make a new container class for that? Or do you need to extend the base container so it had a prop to state left/top/right/bottom -label. Or do you make like BFC did by having a 2nd location point for the label so it could freely be moved about on the GUI-Designer yet still snap to the "default" positions. But worse: if you want to align controls, you want it to ignore the label and align "controls", so your class needs to account for that too. And then what about stuff like font / colour / enabled / read-only / etc. are you going to expose all possibilities through pass-through properties, or rather just pass the child controls as public (i.e. breaking general OOP principles)? So your container class is not going to be a trivial thing at all, at least not for something you want to use extensively in various situations. IMO, if your current library doesn't provide such combined control+label classes, you're wasting your time making them simply to avoid prefixing / suffixing their variables. If you've got other reasons for doing so, then those are why you'd want to make such combined control. I do like the idea of a suffix for sorting purposes yes, but also I like the idea of intellisence / auto-complete picking up txt as well. So I'm a bit in 2 minds as to which one to use in preference. Though I do try to steer clear of tieing the name to some aspect of the control (e.g. I don't use txt for Text / cmb for Combo Box / tgl for Toggle / etc. etc. etc.) that just makes life more difficult on any change. I generally use lbl for labels and fld for inputs (i.e. "Field" like in a db form) even drop-downs/toggles.

        1 Reply Last reply
        0
        • C c2423

          I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

          S Offline
          S Offline
          Stefan_Lang
          wrote on last edited by
          #41

          The name of a variable should indicate what it's used for, so I see no reason not to use Hungarian notation as a means to distinguish between different kinds of UI components. Since there is only a limited number of different components, it makes sense to abbreviate them rather than using the full name.

          1 Reply Last reply
          0
          • C c2423

            I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

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

            Hungarian notation is an abomination before God :suss:. Besides, everyone knows that the proper naming convention is _Something__label, _Something__value, etc. :-D

            Software Zen: delete this;

            1 Reply Last reply
            0
            • J Jonathan C Dickinson

              lblUsername, txtUsername That's why. The 'correct' solution is presented by WPF (and HTML): you don't *need* to name controls. However, when I am doing Winforms: usernameTextBox, usernameLabel. No idea why, it's just style preference (or possibly hungarian aversion).

              He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chinese Proverb] Jonathan C Dickinson (C# Software Engineer)

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

              Jonathan C Dickinson wrote:

              ernameTextBox, usernameLabel

              That makes two[^] of us doing it properly, although I find your fondness for camel case morally repugnant.

              Software Zen: delete this;

              1 Reply Last reply
              0
              • C c2423

                I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

                S Offline
                S Offline
                Stephen Dycus
                wrote on last edited by
                #44

                I guess I'm going to have to disagree with everyone here. What happened to verbosity being a good thing in software development? Prefixing variables referencing UI objects makes your code more self documenting. I know that txtFirstName is an editable text box and firstName is most likely just a string. If you remove ui prefixes, all bets are off. You no longer have any indication as to what a variable's type/implementation is without either scrolling up to its declaration or hovering over the variable in a compatible IDE. The argument that changing the type of the variable is difficult is largely not the case anymore. The modern IDE has *at least* find and replace, and most have a right click -> Refactor -> Rename option. Should we really sacrifice self documentation for the off chance that a text box reference will be changed to a label?

                C 1 Reply Last reply
                0
                • C c2423

                  I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

                  S Offline
                  S Offline
                  Stuart Rubin
                  wrote on last edited by
                  #45

                  In general, a reason NOT to use Hungarian Notation is that it keeps the programmer from abstracting the data from the type. In fact, it does the opposite. For UI controls, the variables are NOT abstract from the control; they are intrinsically linked. They are one in the same. There's nothing to make more abstract from a variable "okButton." A button is a button, but an Uint16 could be just about anything. So, I say using the Hungarian-like notation for specific control types makes sense.

                  1 Reply Last reply
                  0
                  • D Dave Calkins

                    I've never quite understood how strongly some dislike hungarian notation. its just a style :)

                    B Offline
                    B Offline
                    Bob1000
                    wrote on last edited by
                    #46

                    Nothing wrong with Hungarian notation, I am quite happy to see it used, provided it attracts the death penalty! Preferable by the good old Hungarian folk method of hanging drawing and quartering....)

                    1 Reply Last reply
                    0
                    • C c2423

                      I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

                      B Offline
                      B Offline
                      Bob1000
                      wrote on last edited by
                      #47

                      Is the iPhone Hungarian?

                      1 Reply Last reply
                      0
                      • B BobJanova

                        If I have a control that is backing some data object field, let's say UserInfo.FirstName, I'll call it firstName or firstNameEdit, and its label firstNameLabel.

                        C Offline
                        C Offline
                        Chrisgo
                        wrote on last edited by
                        #48

                        I tend to take that a little farther. I like the longer, more verbose names, they seem more clear to me. But, I consider those to be class level variables. So, I'll tack on a '_' prefix. I would then have _firstNameLabel.

                        1 Reply Last reply
                        0
                        • C c2423

                          I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

                          D Offline
                          D Offline
                          DarkChuky CR
                          wrote on last edited by
                          #49

                          Well, I use the full name: TextBoxSomething, LabelSomething.... just because I follow the tendency to use verbose... and it's easier to read. New developers (juniors, just graduated) will always understand that TextBoxSomething is a TextBox and they don't need to know anything about bulgarian... let say txtSomething: a textbox? justa text, like a label, a string? dunno... in other words make your code as readable as possible (for dummies, if you need to have a degree and 6 years experience to read my code... there is something wrong) then being verbose helps a lot. (ok ok, we know that this make your code lines go bigger but then you will also add some other standards...) also, this is just what I like, bulgarian is 1000% better than TextBox x,y,b,a = new TextBox();

                          1 Reply Last reply
                          0
                          • C c2423

                            I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

                            P Offline
                            P Offline
                            patbob
                            wrote on last edited by
                            #50

                            The hungarian notation prefix was a memory mnemonic. It disappeared because of things like intellisense, name completion, and go-to-definition shortcuts, which provide the same features without the need for the mnemonic, and work ten times better. Nowdays, I only use it when intellisense, name completion, go-to-declaration are not available in the editor. In UI usage, I use a naming scheme (not hungarian) to provide a clue of which controls are related to each other. The text box that displays a string, and the label on the dialog that indicates to the user what that text box contains, are related. However, unless I'm going to manipualte the label, I don't need a member variable for it and have been known to set GenerateMember to False.

                            We can program with only 1's, but if all you've got are zeros, you've got nothing.

                            1 Reply Last reply
                            0
                            • C c2423

                              That's a fair point - I'd not thought of it that way. There's a suggestion somewhere else in this discussion that I quite like which is along the lines of FirstNameInput, thus not implying text box as such.

                              G Offline
                              G Offline
                              gggustafson
                              wrote on last edited by
                              #51

                              But if you are serious about UI programming (in WinForms, WebForms, and Mobile Apps) you want to imply a TextBox (WinForms).

                              Gus Gustafson

                              M 1 Reply Last reply
                              0
                              • C c2423

                                I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

                                N Offline
                                N Offline
                                Nonpareil
                                wrote on last edited by
                                #52

                                I use a naming convention that best suites my programming environment (IDE). When using Visual Studio, with Intelli-sense, I generally will not use any kind of pre or post typing notation as the IDE provides this context with a mouse-over (and you should be able to see its type from its usage in the code). As far as component delineation, as with UI constructs, I favor the noun-verb or noun-noun method of naming; i.e., MyStream_Read, MyStream_Write, MyStream_Flush, etc., or UserName_lbl, UserName_tb, etc. (with or without the underscore, but I do favor caps when not using underscore delimiters). I prefer this method as most IDEs present these entities in sort order. In less automated coding environments (NotePad++) I would use more of the constructs you describe, however, I always maintain sort order naming so its easy to see all labels, functions, or events associated with a given entity or programming construct.

                                The art of conversation is not only saying the right thing at the right time, but to leave unsaid the wrong thing at a most tempting moment!

                                1 Reply Last reply
                                0
                                • C c2423

                                  I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #53

                                  I like to put a "ux" in front of a UI control's name (when I need one); eg. uxFirstName ... helps group all controls in IntelliSense. And I prefix private fields with a "_"; so that they stand out from local variables. That's it.

                                  1 Reply Last reply
                                  0
                                  • C c2423

                                    I think we can all agree that for the most part nobody uses Hungarian notation for variables any more... but it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething. On one hand I feel a bit uneasy that there must be some way to avoid this horrible practice, but on the other hand lblSomething is clearly meant to be a label which is next to txtSomething, and I need a way to differentiate between them without ending up with two controls with the same name. What say you? Disclaimer: I don't consider this to be a programming question, more a question of what styles people like to use.

                                    R Offline
                                    R Offline
                                    RafagaX
                                    wrote on last edited by
                                    #54

                                    IDEs and OO Programming may be the culprits behind Hungarian notation demise in naming variables, also while naming controls I find that suffixing the type of the control is easier (although more verbose) for me, so I haven't used Hungarian notation in a long while.

                                    CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

                                    1 Reply Last reply
                                    0
                                    • J Joe Woodbury

                                      jschell wrote:

                                      Are you suggesting that "b" is used to represent something besides the data type of the variable from the above phrase?

                                      Read the damn paper. The b is an exception to his use of notation to indicate the usage of a variable. You are deliberately ignoring the other tables which are blindingly clear. Look at table 2 and table 3. Even table 4 save for two damn rows. Then read his whole damn discussion on the color red. What does "co" stand for? Simonyi states: "As suggested above, the concept of "type" in this context is determined by the set of operations that can be applied to a quantity."

                                      J Offline
                                      J Offline
                                      jschell
                                      wrote on last edited by
                                      #55

                                      Joe Woodbury wrote:

                                      What does "co" stand for?

                                      "1.Quantities are named by their type possibly followed by a qualifier. A convenient (and legal) punctuation is recommended to separate the type and qualifier part of a name. (In C, we use a capital initial for the qualifier as in rowFirst: row is the type; First is the qualifier.) " "Conversely, the tag for the type of the color value should not be "color."...A typical arbitrary choice could be co" Is that that "co" to which you are referring?

                                      1 Reply Last reply
                                      0
                                      • S Stephen Dycus

                                        I guess I'm going to have to disagree with everyone here. What happened to verbosity being a good thing in software development? Prefixing variables referencing UI objects makes your code more self documenting. I know that txtFirstName is an editable text box and firstName is most likely just a string. If you remove ui prefixes, all bets are off. You no longer have any indication as to what a variable's type/implementation is without either scrolling up to its declaration or hovering over the variable in a compatible IDE. The argument that changing the type of the variable is difficult is largely not the case anymore. The modern IDE has *at least* find and replace, and most have a right click -> Refactor -> Rename option. Should we really sacrifice self documentation for the off chance that a text box reference will be changed to a label?

                                        C Offline
                                        C Offline
                                        c2423
                                        wrote on last edited by
                                        #56

                                        Can't say I agree - changing the type of a variable is still very much a difficult job. The IDE will find and replace just fine for internal and private scoped variables, but for anything that's protected or public a change of type could break 3rd party code. This isn't really a problem solved with a good search and replace. Contrast this with swapping a type that maintains backwards compatibility, you'll give 3rd parties far fewer headaches.

                                        S 1 Reply Last reply
                                        0
                                        • J Jonathan C Dickinson

                                          lblUsername, txtUsername That's why. The 'correct' solution is presented by WPF (and HTML): you don't *need* to name controls. However, when I am doing Winforms: usernameTextBox, usernameLabel. No idea why, it's just style preference (or possibly hungarian aversion).

                                          He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chinese Proverb] Jonathan C Dickinson (C# Software Engineer)

                                          C Offline
                                          C Offline
                                          c2423
                                          wrote on last edited by
                                          #57

                                          Sometimes in HTML you do need to name variables - that's what the ID attribute is for. Otherwise you end up with some very complex javascript/jQuery when you try to access a particular control.

                                          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