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. The perfect teacher

The perfect teacher

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpjavavisual-studiotutorialquestion
22 Posts 15 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 Chris Meech

    Kubajzz wrote:

    - in case you haven't noticed, this code violates some basic good-style C# coding guidelines

    I haven't noticed. Can you provide an explanation with an example? Thanks. :)

    Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

    K Offline
    K Offline
    Kubajzz
    wrote on last edited by
    #4

    Sure :) First of all, properties should be used in C# instead of get() and set() methods wherever appropriate. Public member names should start with a capital letter. Prefixes such as "arg..." are evil. The constructor parameters should be simply "name" and "sname". The name "SName" is a great example of an unclear and unneccessary abbreviation that should be avoided. I was too lazy to search for reference links, this is what I remember from the guidelines. Somebody correct me if I'm wrong...

    C 1 Reply Last reply
    0
    • K Kubajzz

      Sure :) First of all, properties should be used in C# instead of get() and set() methods wherever appropriate. Public member names should start with a capital letter. Prefixes such as "arg..." are evil. The constructor parameters should be simply "name" and "sname". The name "SName" is a great example of an unclear and unneccessary abbreviation that should be avoided. I was too lazy to search for reference links, this is what I remember from the guidelines. Somebody correct me if I'm wrong...

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #5

      Thanks. I understand your points. In this day and age, using "SName" instead of say "Surname", whilst seemingly picky is a good point. Sometimes it's all about the attention to details. :)

      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

      1 Reply Last reply
      0
      • K Kubajzz

        See this piece of code:

        class Person
        {
        private string name;
        private string sname;

        public Person(string argName, string argSName)
        {
            name = argName;
            sname = argSName;
        }
        
        public string getName()
        {
            return name;
        }
        
        public string getSName()
        {
            return sname;
        }
        
        public override string ToString()
        {
            return name + " " + sname;
        }
        

        }

        Now consider these few facts: - the code is in C#, not Java - in case you haven't noticed, this code violates some basic good-style C# coding guidelines - the person who wrote this code teaches C# programming at university - this piece of code was given to his students as a do-it-like-this example - he never, ever uses properties (Java-style getXXX() and setXXX() methods seem to be good enough for him...) - he sometimes names his classes and methods in Czech using diactitics (yes, it compiles fine since VS is Unicode-based, but... WTF?) - And more!

        _ Offline
        _ Offline
        _Erik_
        wrote on last edited by
        #6

        Congratulations. You have found the main source of the content in hall of shame: shameful teachers.

        1 Reply Last reply
        0
        • K Kubajzz

          See this piece of code:

          class Person
          {
          private string name;
          private string sname;

          public Person(string argName, string argSName)
          {
              name = argName;
              sname = argSName;
          }
          
          public string getName()
          {
              return name;
          }
          
          public string getSName()
          {
              return sname;
          }
          
          public override string ToString()
          {
              return name + " " + sname;
          }
          

          }

          Now consider these few facts: - the code is in C#, not Java - in case you haven't noticed, this code violates some basic good-style C# coding guidelines - the person who wrote this code teaches C# programming at university - this piece of code was given to his students as a do-it-like-this example - he never, ever uses properties (Java-style getXXX() and setXXX() methods seem to be good enough for him...) - he sometimes names his classes and methods in Czech using diactitics (yes, it compiles fine since VS is Unicode-based, but... WTF?) - And more!

          R Offline
          R Offline
          RobCroll
          wrote on last edited by
          #7

          I like the way they explicitly declare methods as public when the class is implicitly internal. BTW I am a teacher so if you want to pass, hand in your assignments :)

          "You get that on the big jobs."

          K 1 Reply Last reply
          0
          • K Kubajzz

            See this piece of code:

            class Person
            {
            private string name;
            private string sname;

            public Person(string argName, string argSName)
            {
                name = argName;
                sname = argSName;
            }
            
            public string getName()
            {
                return name;
            }
            
            public string getSName()
            {
                return sname;
            }
            
            public override string ToString()
            {
                return name + " " + sname;
            }
            

            }

            Now consider these few facts: - the code is in C#, not Java - in case you haven't noticed, this code violates some basic good-style C# coding guidelines - the person who wrote this code teaches C# programming at university - this piece of code was given to his students as a do-it-like-this example - he never, ever uses properties (Java-style getXXX() and setXXX() methods seem to be good enough for him...) - he sometimes names his classes and methods in Czech using diactitics (yes, it compiles fine since VS is Unicode-based, but... WTF?) - And more!

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #8

            And he should be shot for concatenating his strings... :laugh:

            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            R A 2 Replies Last reply
            0
            • R RobCroll

              I like the way they explicitly declare methods as public when the class is implicitly internal. BTW I am a teacher so if you want to pass, hand in your assignments :)

              "You get that on the big jobs."

              K Offline
              K Offline
              Kubajzz
              wrote on last edited by
              #9

              RobCroll wrote:

              I like the way they explicitly declare methods as public when the class is implicitly internal.

              I can't really see anything wrong with that :confused:

              RobCroll wrote:

              if you want to pass, hand in your assignments :)

              I have already got an A, but thanks for the offer :D

              R 1 Reply Last reply
              0
              • K Kubajzz

                RobCroll wrote:

                I like the way they explicitly declare methods as public when the class is implicitly internal.

                I can't really see anything wrong with that :confused:

                RobCroll wrote:

                if you want to pass, hand in your assignments :)

                I have already got an A, but thanks for the offer :D

                R Offline
                R Offline
                RobCroll
                wrote on last edited by
                #10

                Kubajzz wrote:

                RobCroll wrote:

                I like the way they explicitly declare methods as public when the class is
                implicitly internal.

                I can't really see anything wrong with that :confused:

                The methods are public which would suggest they are available to the world but the class is internal and only accessible within the assembly. Explicitly declaring the "Access Modifier" as public is misleading because it can only be private, internal or protected. Congratulations on the A by the way.

                "You get that on the big jobs."

                A 1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  And he should be shot for concatenating his strings... :laugh:

                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

                  R Offline
                  R Offline
                  RobCroll
                  wrote on last edited by
                  #11

                  After x iterations of .NET it would be nice to have a constant for space String.Space or String.Character.Space. I guess you could encapsulate the statement getFName() but other than that, what is the problem?

                  "You get that on the big jobs."

                  G 1 Reply Last reply
                  0
                  • R RobCroll

                    After x iterations of .NET it would be nice to have a constant for space String.Space or String.Character.Space. I guess you could encapsulate the statement getFName() but other than that, what is the problem?

                    "You get that on the big jobs."

                    G Offline
                    G Offline
                    GibbleCH
                    wrote on last edited by
                    #12

                    It should be

                        return string.Format("{0} {1}", name, sname);
                    
                    B 1 Reply Last reply
                    0
                    • K Kubajzz

                      See this piece of code:

                      class Person
                      {
                      private string name;
                      private string sname;

                      public Person(string argName, string argSName)
                      {
                          name = argName;
                          sname = argSName;
                      }
                      
                      public string getName()
                      {
                          return name;
                      }
                      
                      public string getSName()
                      {
                          return sname;
                      }
                      
                      public override string ToString()
                      {
                          return name + " " + sname;
                      }
                      

                      }

                      Now consider these few facts: - the code is in C#, not Java - in case you haven't noticed, this code violates some basic good-style C# coding guidelines - the person who wrote this code teaches C# programming at university - this piece of code was given to his students as a do-it-like-this example - he never, ever uses properties (Java-style getXXX() and setXXX() methods seem to be good enough for him...) - he sometimes names his classes and methods in Czech using diactitics (yes, it compiles fine since VS is Unicode-based, but... WTF?) - And more!

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

                      Kubajzz wrote:

                      - this piece of code was given to his students as a do-it-like-this example

                      Mhm... I have to admit, my coding style is a little bit Java-like... but my padawan and I agree on that... but to say "do-it-like-this" is a little bit... wow... :doh: BTW: like your argumentation on this[]...:thumbsup:

                      (yes|no|maybe)*

                      1 Reply Last reply
                      0
                      • K Kubajzz

                        See this piece of code:

                        class Person
                        {
                        private string name;
                        private string sname;

                        public Person(string argName, string argSName)
                        {
                            name = argName;
                            sname = argSName;
                        }
                        
                        public string getName()
                        {
                            return name;
                        }
                        
                        public string getSName()
                        {
                            return sname;
                        }
                        
                        public override string ToString()
                        {
                            return name + " " + sname;
                        }
                        

                        }

                        Now consider these few facts: - the code is in C#, not Java - in case you haven't noticed, this code violates some basic good-style C# coding guidelines - the person who wrote this code teaches C# programming at university - this piece of code was given to his students as a do-it-like-this example - he never, ever uses properties (Java-style getXXX() and setXXX() methods seem to be good enough for him...) - he sometimes names his classes and methods in Czech using diactitics (yes, it compiles fine since VS is Unicode-based, but... WTF?) - And more!

                        J Offline
                        J Offline
                        Jeroen De Dauw
                        wrote on last edited by
                        #14

                        How else would students learn to deal with crappy code? When they graduate, the crappy teacher will just be replaced by a crappy boss and crappy colleagues :)

                        Jeroen De Dauw (blog | Twitter | Identi.ca)

                        1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          And he should be shot for concatenating his strings... :laugh:

                          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

                          A Offline
                          A Offline
                          AspDotNetDev
                          wrote on last edited by
                          #15

                          Seems fine to me.

                          [Managing Your JavaScript Library in ASP.NET]

                          1 Reply Last reply
                          0
                          • R RobCroll

                            Kubajzz wrote:

                            RobCroll wrote:

                            I like the way they explicitly declare methods as public when the class is
                            implicitly internal.

                            I can't really see anything wrong with that :confused:

                            The methods are public which would suggest they are available to the world but the class is internal and only accessible within the assembly. Explicitly declaring the "Access Modifier" as public is misleading because it can only be private, internal or protected. Congratulations on the A by the way.

                            "You get that on the big jobs."

                            A Offline
                            A Offline
                            AspDotNetDev
                            wrote on last edited by
                            #16

                            Seems like a fine pratice to me. If the class is later changed to public, all the properties would then become visible outside the assembly. This may be the intention. There is also the case of when implementing an interface (the members would have to be public, even on an internal class). While neither of those appear to be the case here, I don't see a downside to making the members public.

                            [Managing Your JavaScript Library in ASP.NET]

                            M 1 Reply Last reply
                            0
                            • C Chris Meech

                              Kubajzz wrote:

                              - in case you haven't noticed, this code violates some basic good-style C# coding guidelines

                              I haven't noticed. Can you provide an explanation with an example? Thanks. :)

                              Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

                              D Offline
                              D Offline
                              Dalek Dave
                              wrote on last edited by
                              #17

                              Oh dear god no! :)

                              ------------------------------------ I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave CCC Link[^] Trolls[^]

                              1 Reply Last reply
                              0
                              • G GibbleCH

                                It should be

                                    return string.Format("{0} {1}", name, sname);
                                
                                B Offline
                                B Offline
                                BobJanova
                                wrote on last edited by
                                #18

                                Got a citation for that? It would seem to me that string.Format is a lot heavier than concatenation, since it has to parse the format string, work out what the arguments are and then substitute them in. Usually the advice is to use StringBuilder but for such a small example I don't see what's wrong with the concatenation, and Format seems worse.

                                1 Reply Last reply
                                0
                                • A AspDotNetDev

                                  Seems like a fine pratice to me. If the class is later changed to public, all the properties would then become visible outside the assembly. This may be the intention. There is also the case of when implementing an interface (the members would have to be public, even on an internal class). While neither of those appear to be the case here, I don't see a downside to making the members public.

                                  [Managing Your JavaScript Library in ASP.NET]

                                  M Offline
                                  M Offline
                                  Mel Pama
                                  wrote on last edited by
                                  #19

                                  If the assembly has more than just this internal class then the members should be public if you want the other classes in the same assembly to access them. Internal is assembly in scope, public is class in scope. Internal limits public access only to that assembly for that internally declared class, all other classes can still acess the internal class.

                                  A 1 Reply Last reply
                                  0
                                  • M Mel Pama

                                    If the assembly has more than just this internal class then the members should be public if you want the other classes in the same assembly to access them. Internal is assembly in scope, public is class in scope. Internal limits public access only to that assembly for that internally declared class, all other classes can still acess the internal class.

                                    A Offline
                                    A Offline
                                    AspDotNetDev
                                    wrote on last edited by
                                    #20

                                    I know. My point was that if you change the class down the road (e.g., by changing it from internal to public) for whatever reason, then it may be advantageous if you had marked all the class members public in the first place (assuming your change of making the class public implies that you also want the members to be public once that change has been made).

                                    [Managing Your JavaScript Library in ASP.NET]

                                    1 Reply Last reply
                                    0
                                    • K Kubajzz

                                      See this piece of code:

                                      class Person
                                      {
                                      private string name;
                                      private string sname;

                                      public Person(string argName, string argSName)
                                      {
                                          name = argName;
                                          sname = argSName;
                                      }
                                      
                                      public string getName()
                                      {
                                          return name;
                                      }
                                      
                                      public string getSName()
                                      {
                                          return sname;
                                      }
                                      
                                      public override string ToString()
                                      {
                                          return name + " " + sname;
                                      }
                                      

                                      }

                                      Now consider these few facts: - the code is in C#, not Java - in case you haven't noticed, this code violates some basic good-style C# coding guidelines - the person who wrote this code teaches C# programming at university - this piece of code was given to his students as a do-it-like-this example - he never, ever uses properties (Java-style getXXX() and setXXX() methods seem to be good enough for him...) - he sometimes names his classes and methods in Czech using diactitics (yes, it compiles fine since VS is Unicode-based, but... WTF?) - And more!

                                      A Offline
                                      A Offline
                                      Anuj Tripathi
                                      wrote on last edited by
                                      #21

                                      Thank god. you teacher knows that much stuff.

                                      1 Reply Last reply
                                      0
                                      • K Kubajzz

                                        See this piece of code:

                                        class Person
                                        {
                                        private string name;
                                        private string sname;

                                        public Person(string argName, string argSName)
                                        {
                                            name = argName;
                                            sname = argSName;
                                        }
                                        
                                        public string getName()
                                        {
                                            return name;
                                        }
                                        
                                        public string getSName()
                                        {
                                            return sname;
                                        }
                                        
                                        public override string ToString()
                                        {
                                            return name + " " + sname;
                                        }
                                        

                                        }

                                        Now consider these few facts: - the code is in C#, not Java - in case you haven't noticed, this code violates some basic good-style C# coding guidelines - the person who wrote this code teaches C# programming at university - this piece of code was given to his students as a do-it-like-this example - he never, ever uses properties (Java-style getXXX() and setXXX() methods seem to be good enough for him...) - he sometimes names his classes and methods in Czech using diactitics (yes, it compiles fine since VS is Unicode-based, but... WTF?) - And more!

                                        B Offline
                                        B Offline
                                        Brad Barnhill
                                        wrote on last edited by
                                        #22

                                        Properties man ... properties. Good lord.

                                        Brad Barnhill

                                        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