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 2 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.
  • R Ravi Bhavnani

    c2423 wrote:

    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

    I do the same thing [insert](in WinForms code behind)[/insert] as I find it useful and it helps reduce coding errors.  I have no qualms about using it.  Also, it's strictly not Hungarian notation, since lbl and txt are not primitive data types. /ravi

    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

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

    Strictly speaking strings aren't primitive data types either, but it'd make my skin crawl to name a variable strXyz.

    R L 2 Replies Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      So when you say you still use Hungarian in three cases, you are referring to the pre-monstrosity kind?

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

      J Offline
      J Offline
      Joe Woodbury
      wrote on last edited by
      #23

      I listed them; p, h and m_ (or _). The monstrosity kind were where you'd get a string of letters which must have meant something to someone, but which were now indecipherable. I once worked for a guy who insisted that 'i' be a prefix for integer and 'b' for byte/unsigned char, yet someone else on the team used 'n' and someone else 'd' and both used 'b' for bool, even if had ceased to be a BOOL (in the worse case, bool not only became an enum, but failure or false became -1.) PS. I suppose the most notorious example is WPARAM wParam which isn't a WORD at all. I realized that I do use lParam and wParam in this case, but mainly because when I want to know what's in the WPARAM, I know what to look for--the l and w prefixes have lost all meaning. It annoys me, though.

      1 Reply Last reply
      0
      • M M Badger

        I can't find it quickly but there was a good article posted here via the news feed (Insider News) that told a story, presumably true, as to what Hungarian was supposed to be for and what it got turned into and that they were vastly different. Anywho the Wikipedia article[^] might help, at least differentiating between System Hungarian and Apps Hungarian. Personally I tend to use the txtAge, lblAge, cmbGender, lblGender, cmdOK, cmdCancel etc. I am intrigued by the idea of switching to AgeTxt, AgeLbl, GenderCmb, GenderLbl, CancelCmd, OKCmd etc., might be better in at least some if not many places. Mike

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

        I didn't see the article - perhaps it was Joel on Software? http://www.joelonsoftware.com/articles/Wrong.html[^] I don't think AgeTxt etc is any better - you would win the point of saying "I don't use Hungarian notation", while doing something equally smelly. There is a suggestion above which is that you would have something like AgeInput or AgeEdit, which I quite like on the basis that it doesn't prescribe a particular implementation.

        1 Reply Last reply
        0
        • B BobJanova

          Making it a suffix means that related controls (i.e. all the things for FirstName) come together. Doing it 'properly' you have a single control, called firstName, which has the editor and the label and exposes the right properties. But UI usually doesn't work out like that, so you will have several controls relating to the same concept. You have to use the type to differentiate them, and a suffix seems better than a prefix to me.

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

          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 1 Reply Last reply
          0
          • C c2423

            Strictly speaking strings aren't primitive data types either, but it'd make my skin crawl to name a variable strXyz.

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #26

            Ha!  I wasn't advocating using (and do not use) strXyz. :-D /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            1 Reply Last reply
            0
            • C c2423

              Strictly speaking strings aren't primitive data types either, but it'd make my skin crawl to name a variable strXyz.

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

              c2423 wrote:

              but it'd make my skin crawl to name a variable strXyz.

              Imdeed. You better should call it lpszXyz. :)

              Sent from my BatComputer via HAL 9000 and M5

              1 Reply Last reply
              0
              • J Joe Woodbury

                Giving a variable name passwordString or something comparable is not Hungarian notation. The original intent with Hungarian notation was that a very short prefix would indicate HOW the variable was used, not the actual type of the variable. Thus dX meant delta-X, not that X is an integer. This was quickly perverted into a monstrosity. Name variables with meaningful names is to be encouraged, though in my style most abbreviations are discouraged. In UI programming, I often use Label/Checkbox or some suffix to distinguish controls from data. In C++, I still use Hungarian in three distinct cases: I put a 'p' in front of pointers since the semantics are dramatically different. I put 'h' in front of naked handles for a similar reason--if I see a variable prefixed with an 'h', there better be a CloseHandle or equivalent nearby (code-wise). I also put "m_" in front of class member variables. Oddly I don't do this in C# (except lately since my current peers insist on using the "_" prefix for member variables.)

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

                Joe Woodbury wrote:

                Giving a variable name passwordString or something comparable is not Hungarian notation. The original intent with Hungarian notation was that a very short prefix would indicate HOW the variable was used, not the actual type of the variable. Thus dX meant delta-X, not that X is an integer

                No. http://en.wikipedia.org/wiki/Hungarian_notation[^] "Simonyi's paper referred to prefixes used to indicate the "type" of information being stored" http://msdn.microsoft.com/en-us/library/aa260976%28v=vs.60%29.aspx[^] "Long, long ago in the early days of DOS, Microsoft's Chief Architect Dr. Charles Simonyi introduced an identifier naming convention that adds a prefix to the identifier name to indicate the functional type of the identifier."

                J 1 Reply Last reply
                0
                • J jschell

                  Joe Woodbury wrote:

                  Giving a variable name passwordString or something comparable is not Hungarian notation. The original intent with Hungarian notation was that a very short prefix would indicate HOW the variable was used, not the actual type of the variable. Thus dX meant delta-X, not that X is an integer

                  No. http://en.wikipedia.org/wiki/Hungarian_notation[^] "Simonyi's paper referred to prefixes used to indicate the "type" of information being stored" http://msdn.microsoft.com/en-us/library/aa260976%28v=vs.60%29.aspx[^] "Long, long ago in the early days of DOS, Microsoft's Chief Architect Dr. Charles Simonyi introduced an identifier naming convention that adds a prefix to the identifier name to indicate the functional type of the identifier."

                  J Offline
                  J Offline
                  Joe Woodbury
                  wrote on last edited by
                  #29

                  jschell wrote:

                  http://msdn.microsoft.com/en-us/library/aa260976%28v=vs.60%29.aspx[^]
                   
                  "Long, long ago in the early days of DOS, Microsoft's Chief Architect Dr. Charles Simonyi introduced an identifier naming convention that adds a prefix to the identifier name to indicate the functional type of the identifier."

                  "the functional type" Simonyi's paper makes this reasonably clear, though even he allowed some physical types to be represented. I believe the problem is that Simonyi was using "type" when he meant "usage" due, I believe, to English not being his first language. (I found it funny that he writes : "In closing, it is evident that the conventions participated in making the code more correct, easier to write, and easier to read. Naming conventions cannot guarantee good code, however; only the skill of the programmer can." When, for me at least, his example is nearly indecipherable and not clear at all.)

                  J 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
                    RedDk
                    wrote on last edited by
                    #30

                    It's a stretch ... It's probably a stretch, I mean.

                    1 Reply Last reply
                    0
                    • M M Badger

                      I can't find it quickly but there was a good article posted here via the news feed (Insider News) that told a story, presumably true, as to what Hungarian was supposed to be for and what it got turned into and that they were vastly different. Anywho the Wikipedia article[^] might help, at least differentiating between System Hungarian and Apps Hungarian. Personally I tend to use the txtAge, lblAge, cmbGender, lblGender, cmdOK, cmdCancel etc. I am intrigued by the idea of switching to AgeTxt, AgeLbl, GenderCmb, GenderLbl, CancelCmd, OKCmd etc., might be better in at least some if not many places. Mike

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

                      txtSomething is better than SomethingTxt IMHO, because when I type and want to pull up a control name with IntelliSense I always know the kind of control I will be looking up, but might not remember the actual variable name. So I type txt... and pick the control name from the popped list.

                      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.

                        C Offline
                        C Offline
                        Clifford Nelson
                        wrote on last edited by
                        #32

                        Think a big reason that it has disappeared is that display space is not as valuable. There was also the issue of calling something strName, well Name is probably going to be a string anyway, so sort of redundant. In the case of UI there is more TextBoxName vs txtName.

                        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
                          #33

                          Interesting question... When it is up to me, I dabbled fairly recently to using ux as a prefix for all GUI controls - and not naming any controls that don't require a name. So I would have uxCustomerName and uxCustomerNameLabel assuming both were referenced in code somewhere. Makes it obvious which variables belong to the GUI, keeps label and control variables adjacent alphabetically, allows me to change from a text box to a combo without any bother of renaming. But old habits die hard and I still find myself using txtCustomerName!

                          MVVM# - See how I did MVVM my way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an '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.

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

                            c2423 wrote:

                            lblSomething is clearly meant to be a label which is next to txtSomething

                            Exactly. What else are ya gonna do? And there's this: Making Wrong Code Look Wrong[^]

                            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
                              JimmyRopes
                              wrote on last edited by
                              #35

                              c2423 wrote:

                              it still seems prevalent in UI programming - for example I might have lblSomething next to txtSomething.

                              Yes I still use it for controls but not for variables any more.

                              The report of my death was an exaggeration - Mark Twain
                              Simply Elegant Designs JimmyRopes Designs
                              Think inside the box! ProActive Secure Systems
                              I'm on-line therefore I am. JimmyRopes

                              1 Reply Last reply
                              0
                              • J Joe Woodbury

                                jschell wrote:

                                http://msdn.microsoft.com/en-us/library/aa260976%28v=vs.60%29.aspx[^]
                                 
                                "Long, long ago in the early days of DOS, Microsoft's Chief Architect Dr. Charles Simonyi introduced an identifier naming convention that adds a prefix to the identifier name to indicate the functional type of the identifier."

                                "the functional type" Simonyi's paper makes this reasonably clear, though even he allowed some physical types to be represented. I believe the problem is that Simonyi was using "type" when he meant "usage" due, I believe, to English not being his first language. (I found it funny that he writes : "In closing, it is evident that the conventions participated in making the code more correct, easier to write, and easier to read. Naming conventions cannot guarantee good code, however; only the skill of the programmer can." When, for me at least, his example is nearly indecipherable and not clear at all.)

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

                                Joe Woodbury wrote:

                                Simonyi's paper makes this reasonably clear,

                                Yes it does. From that paper (Table 4.) "b Byte, not necessarily holding a coded character, more akin to w." Are you suggesting that "b" is used to represent something besides the data type of the variable from the above phrase?

                                J 1 Reply Last reply
                                0
                                • J jschell

                                  Joe Woodbury wrote:

                                  Simonyi's paper makes this reasonably clear,

                                  Yes it does. From that paper (Table 4.) "b Byte, not necessarily holding a coded character, more akin to w." Are you suggesting that "b" is used to represent something besides the data type of the variable from the above phrase?

                                  J Offline
                                  J Offline
                                  Joe Woodbury
                                  wrote on last edited by
                                  #37

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

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