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

Strong Typing

Scheduled Pinned Locked Moved The Weird and The Wonderful
42 Posts 17 Posters 9 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.
  • M Marcus J Smith

    Tristan Rhodes wrote:

    And was told it was a total waste of my time.

    Why?


    CleaKO

    "I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy)
    "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)

    T Offline
    T Offline
    Tristan Rhodes
    wrote on last edited by
    #30

    Because the general concencus was that "It's the most pointless piece of code" they had ever seen. :S

    ------------------------------- Carrier Bags - 21st Century Tumbleweed.

    P M 2 Replies Last reply
    0
    • T Tristan Rhodes

      Because the general concencus was that "It's the most pointless piece of code" they had ever seen. :S

      ------------------------------- Carrier Bags - 21st Century Tumbleweed.

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

      I'd have to see the code.

      T 1 Reply Last reply
      0
      • P PIEBALDconsult

        John R. Shaw wrote:

        Then again I wish C would allow me to declare a variable where ever I wanted

        I prefer to have all the declarations in one place (the top) so in C# I still do that by choice. But requiring such isn't very friendly, flexibility is good.

        C Offline
        C Offline
        Chris Maunder
        wrote on last edited by
        #32

        ewwww! Declare the variables as close to their first use as possible. I have spoken.

        cheers, Chris Maunder

        CodeProject.com : C++ MVP

        X 1 Reply Last reply
        0
        • T Tristan Rhodes

          Because the general concencus was that "It's the most pointless piece of code" they had ever seen. :S

          ------------------------------- Carrier Bags - 21st Century Tumbleweed.

          M Offline
          M Offline
          Marcus J Smith
          wrote on last edited by
          #33

          Maybe it was just the code. Strong typing is a good way to control up front what type of information you are looking for rather than waiting for it to hit the database or a flat file and finding out later it isnt what it should be.


          CleaKO

          "I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy)
          "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)

          1 Reply Last reply
          0
          • P PIEBALDconsult

            I'd have to see the code.

            T Offline
            T Offline
            Tristan Rhodes
            wrote on last edited by
            #34

            public class SessionWrapper { private HttpSessionState session; // Constants public SessionWrapper() { session = HttpContext.Current.Session; } public string UserName { get{return (string)session[SE_USER_NAME];} set{session[SE_USER_NAME] = value;} } public int? LastPurchase { get{return (int?)session[SE_LAST_PURCHASE];} set{session[SE_LAST_PURCHASE] = value;} } // Etc } I'm actualy working on a code generator to build stuff like that for me, but at the time it was written manualy. My argument was its a strongly typed wrapper that exposes other developers to exactly what they need, what type it is, and hides the constants. T

            ------------------------------- Carrier Bags - 21st Century Tumbleweed.

            P 2 Replies Last reply
            0
            • T Tristan Rhodes

              public class SessionWrapper { private HttpSessionState session; // Constants public SessionWrapper() { session = HttpContext.Current.Session; } public string UserName { get{return (string)session[SE_USER_NAME];} set{session[SE_USER_NAME] = value;} } public int? LastPurchase { get{return (int?)session[SE_LAST_PURCHASE];} set{session[SE_LAST_PURCHASE] = value;} } // Etc } I'm actualy working on a code generator to build stuff like that for me, but at the time it was written manualy. My argument was its a strongly typed wrapper that exposes other developers to exactly what they need, what type it is, and hides the constants. T

              ------------------------------- Carrier Bags - 21st Century Tumbleweed.

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

              Makes sense to me. A similar thing I do is with ExecuteScalar(), which returns object which then (usually) requires a test for null and a cast, and setting a default value if null. I wrote a wrapper like public virtual T ExecuteScalar<T>(T IfNull){...} to handle the cast. Any time I'm writing a scalar query and don't have to test for null and/or do a cast I save time, the code is more readable too. Usually, spending the time to encapsulate such common tasks will pay off. "A stitch in time saves nine."

              T 1 Reply Last reply
              0
              • P PIEBALDconsult

                Makes sense to me. A similar thing I do is with ExecuteScalar(), which returns object which then (usually) requires a test for null and a cast, and setting a default value if null. I wrote a wrapper like public virtual T ExecuteScalar<T>(T IfNull){...} to handle the cast. Any time I'm writing a scalar query and don't have to test for null and/or do a cast I save time, the code is more readable too. Usually, spending the time to encapsulate such common tasks will pay off. "A stitch in time saves nine."

                T Offline
                T Offline
                Tristan Rhodes
                wrote on last edited by
                #36

                Well i spent a few months crusading for sensible coding practices, and now i've given up. The other day i was told to remove it, re-centralise all the constants and simply use Session[AppConstants.CONST_NAME] to access everything.

                ------------------------------- Carrier Bags - 21st Century Tumbleweed.

                P 1 Reply Last reply
                0
                • T Tristan Rhodes

                  Well i spent a few months crusading for sensible coding practices, and now i've given up. The other day i was told to remove it, re-centralise all the constants and simply use Session[AppConstants.CONST_NAME] to access everything.

                  ------------------------------- Carrier Bags - 21st Century Tumbleweed.

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

                  Glad I'm in a small IT department and have free reign on what I write.

                  T 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Glad I'm in a small IT department and have free reign on what I write.

                    T Offline
                    T Offline
                    Tristan Rhodes
                    wrote on last edited by
                    #38

                    I'm in a small IT department too, that was the CTO and Senior Developer pulling rank on my design decision. :S (I'm leaving in a week anyway :D ) T

                    ------------------------------- Carrier Bags - 21st Century Tumbleweed.

                    1 Reply Last reply
                    0
                    • J jhwurmbach

                      Those points that are the hotspots of my current working are CTRL-F2-bookmarked anyway. And if I only want to know the type of a variable, Intellisense would open that little tooltip for me. I all boils down to being simply personal style, I guess.


                      Failure is not an option - it's built right in.

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

                      I would agree. I consider it good form to reduce as much as possible the scope of a variable. I do not want the IDE suggesting local variables that should not be used at that point.

                      Paul

                      1 Reply Last reply
                      0
                      • T Tristan Rhodes

                        public class SessionWrapper { private HttpSessionState session; // Constants public SessionWrapper() { session = HttpContext.Current.Session; } public string UserName { get{return (string)session[SE_USER_NAME];} set{session[SE_USER_NAME] = value;} } public int? LastPurchase { get{return (int?)session[SE_LAST_PURCHASE];} set{session[SE_LAST_PURCHASE] = value;} } // Etc } I'm actualy working on a code generator to build stuff like that for me, but at the time it was written manualy. My argument was its a strongly typed wrapper that exposes other developers to exactly what they need, what type it is, and hides the constants. T

                        ------------------------------- Carrier Bags - 21st Century Tumbleweed.

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

                        I just spent the day (working from home) writing a wrapper for NumericUpDown that is generic and will take any of the built-in numerics, hide the actual decimal, and handle the casting so I don't have to. Ugly as Hillary, but it works.

                        1 Reply Last reply
                        0
                        • C Chris Maunder

                          ewwww! Declare the variables as close to their first use as possible. I have spoken.

                          cheers, Chris Maunder

                          CodeProject.com : C++ MVP

                          X Offline
                          X Offline
                          XTAL256
                          wrote on last edited by
                          #41

                          Well I started programming in Java and we were told to put all our declarations up the top (which i think is the Java coding standard), and i like it this way. Makes all your declarations easy to find. However, sometimes i need a variable at that scope which will only be used further down, so i put it there. It all comes down to the scope of you're variable and where it's used in that scope as to where it should go

                          Customer in computer shop: "Can you copy the Internet onto this disk for me?"

                          1 Reply Last reply
                          0
                          • D dighn

                            But then you have to go back to where you were. Sure you could take note of the position but it would still be annoying.

                            R Offline
                            R Offline
                            Russell Jones
                            wrote on last edited by
                            #42

                            in the old vb6 days ctrl-f2 used to take you to a definition and ctrl-shift-f2 used to take you back to where you were before. I'm sure this must be implemented in .net but i've never found out how to do it. I used to use it all the time. Russ

                            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