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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Why I hate C#

Why I hate C#

Scheduled Pinned Locked Moved C#
csharpc++designhelpquestion
35 Posts 11 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 Christian Graus

    typedefs are plain ugly. They are a holdover from C, I thought. multiple inheritance was not included probably because the design focus of C# is to make it hard to hurt yourself using it. I disagree with them, but that is their focus.

    Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

    P Offline
    P Offline
    Paul Conrad
    wrote on last edited by
    #23

    Christian Graus wrote:

    typedefs are plain ugly. They are a holdover from C, I thought.

    Yes, they are ugly. I have always thought that they were carried over from C to maintain portability between older legacy C code and newer C++ code.

    "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

    P 1 Reply Last reply
    0
    • S Skippums

      Prior to spending the last eight months using C#, life was good in the land of C++. I could use pointers without explicitly sharing that fact with the compiler. Implementing a Bus class that inherits from both GroundVehicle and PublicTransport was a non-issue. And of course, I could declare a method with thirty-two overloads in one definition using default parameters. The latest headache that I have encountered in C# is the removal of the ever useful typedef. Why is it that a new language, birthed from a great language like C++, would restrict its users by removing some of the most usefull features of the language? Did the designers of C# feel that code reuse is better left in the past because programming was becoming too convenient? Why is it that now, during the code design phase of an application, when I don't know whether I will be using an int, string, long, etc. for a unique identifier, can I not either (1) typedef a class "UniqueIdentifier" to int for now, so it can easily be changed EVERYWHERE later, or (2) create a class "UniqueIdentifier" that inherits from int, which would essentially typedef it as in (1)? Instead I have to guess which one I will end up using, then go through my code line by line in two months and find every single occurance of that type, then change it to whatever it should be. The only other alternative is to REIMPLEMENT the int class, which is a complete waste of my time. This lack of convenience perplexes and frustrates me to no end. I am also disappointed that an interface member who returns void (nothing) cannot be implemented by a method that returns some other type. Oh well, I guess that I will have to start implementing my own compiler so I don't have to put up with the lack of thought and foresight by the "greatest minds" in our field. Jeff

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

      Skippums wrote:

      the removal of the ever useful typedef

      "When Anders closes a door he usually opens a window someplace." No one showed you the C# way? Won't this work for you?

      // Uncomment one of these
      // using MyType = System.Int32 ;
      // using MyType = System.Double ;
      // using MyType = System.Decimal ;
      // using MyType = System.String ;

      namespace Test
      {
      class Test
      {
      private static MyType
      F
      (
      MyType x
      )
      {
      return ( x + x ) ;
      }

          \[System.STAThreadAttribute\]
          static void
          Main
          (
              string\[\] args
          )
          {
              try
              {
                  System.Console.WriteLine ( F ( 2 ) ) ;
              }
              catch ( System.Exception err )
              {
                  System.Console.WriteLine ( err.Message ) ;
              }
      
              return ;
          }
      }
      

      }

      Of course C/C++ header files make using typedefs easier, whereas each C# file would need to have the using directive. On the other hand, you can pass C# code through the C-preprocessor if you want.

      S 1 Reply Last reply
      0
      • P Paul Conrad

        Christian Graus wrote:

        typedefs are plain ugly. They are a holdover from C, I thought.

        Yes, they are ugly. I have always thought that they were carried over from C to maintain portability between older legacy C code and newer C++ code.

        "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

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

        Well typedefs are prettier than having to say struct X all over the place.

        1 Reply Last reply
        0
        • S Skippums

          I agree that they CAN be ugly, but all I want is to do something like, "typedef UniqueId as int;", so anywhere I put the word UniqueId, the compiler will know I want it to be an int. I don't understand how strongly coupling my UniqueId property and the integer type within the class is at all helpful. Code maintanance on this is going to be atrocious. Jeff

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #26

          You could in fact create a generic class and define it that way. IMO maintenance on a project where the nature of your unique Id could change in mid stream is no less problematic. Hell, you can store an object if you want, and then handle it as whatever type you like from there. But if you use generics, then your type won't be boxed if it's a value type.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          1 Reply Last reply
          0
          • S Skippums

            If you know why they didn't include multiple inheritence and typedef'ing, I would be very interested in hearing (or reading) it. Jeff

            J Offline
            J Offline
            Judah Gabriel Himango
            wrote on last edited by
            #27

            Why didn't they include multiple inheritence: Big question. Best I can do is point you to an in-depth post by one of the CLR guys who explains in detail why they didn't: http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85562.aspx[^] Why didn't they include typedef's: well, technically they did, they just limited the scope of typedefs to the file level, which is a good thing IMO. For example, you can write:

            using IntList = System.Collections.Generic.List;

            ...

            public void Foo()
            {
            IntList list = new IntList();
            list.Add(5);
            ...
            }

            If you don't like the fact that it's limited to the file level, then I'd just write a value type (e.g. a struct) that holds whatever data you need.

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Story of the Spoiled Child The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            1 Reply Last reply
            0
            • S Skippums

              Prior to spending the last eight months using C#, life was good in the land of C++. I could use pointers without explicitly sharing that fact with the compiler. Implementing a Bus class that inherits from both GroundVehicle and PublicTransport was a non-issue. And of course, I could declare a method with thirty-two overloads in one definition using default parameters. The latest headache that I have encountered in C# is the removal of the ever useful typedef. Why is it that a new language, birthed from a great language like C++, would restrict its users by removing some of the most usefull features of the language? Did the designers of C# feel that code reuse is better left in the past because programming was becoming too convenient? Why is it that now, during the code design phase of an application, when I don't know whether I will be using an int, string, long, etc. for a unique identifier, can I not either (1) typedef a class "UniqueIdentifier" to int for now, so it can easily be changed EVERYWHERE later, or (2) create a class "UniqueIdentifier" that inherits from int, which would essentially typedef it as in (1)? Instead I have to guess which one I will end up using, then go through my code line by line in two months and find every single occurance of that type, then change it to whatever it should be. The only other alternative is to REIMPLEMENT the int class, which is a complete waste of my time. This lack of convenience perplexes and frustrates me to no end. I am also disappointed that an interface member who returns void (nothing) cannot be implemented by a method that returns some other type. Oh well, I guess that I will have to start implementing my own compiler so I don't have to put up with the lack of thought and foresight by the "greatest minds" in our field. Jeff

              B Offline
              B Offline
              Bino B
              wrote on last edited by
              #28

              Never hate any languages,pls.

              Cheers Bino www.codepal.co.in

              1 Reply Last reply
              0
              • S Skippums

                I agree that they CAN be ugly, but all I want is to do something like, "typedef UniqueId as int;", so anywhere I put the word UniqueId, the compiler will know I want it to be an int. I don't understand how strongly coupling my UniqueId property and the integer type within the class is at all helpful. Code maintanance on this is going to be atrocious. Jeff

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #29

                Hi Jeff, if you want to be able to write

                for(uniqueID id=0; id<10; id++) Console.WriteLine(id.ToString());

                then just do it. All it takes is a simple:

                using uniqueID=System.Int32;

                AFAIK this has been available since day one. The one thing now really missing from C/C++ is you can't collect statements like the latter in a single header file and get them included everywhere. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


                S 1 Reply Last reply
                0
                • S Skippums

                  Prior to spending the last eight months using C#, life was good in the land of C++. I could use pointers without explicitly sharing that fact with the compiler. Implementing a Bus class that inherits from both GroundVehicle and PublicTransport was a non-issue. And of course, I could declare a method with thirty-two overloads in one definition using default parameters. The latest headache that I have encountered in C# is the removal of the ever useful typedef. Why is it that a new language, birthed from a great language like C++, would restrict its users by removing some of the most usefull features of the language? Did the designers of C# feel that code reuse is better left in the past because programming was becoming too convenient? Why is it that now, during the code design phase of an application, when I don't know whether I will be using an int, string, long, etc. for a unique identifier, can I not either (1) typedef a class "UniqueIdentifier" to int for now, so it can easily be changed EVERYWHERE later, or (2) create a class "UniqueIdentifier" that inherits from int, which would essentially typedef it as in (1)? Instead I have to guess which one I will end up using, then go through my code line by line in two months and find every single occurance of that type, then change it to whatever it should be. The only other alternative is to REIMPLEMENT the int class, which is a complete waste of my time. This lack of convenience perplexes and frustrates me to no end. I am also disappointed that an interface member who returns void (nothing) cannot be implemented by a method that returns some other type. Oh well, I guess that I will have to start implementing my own compiler so I don't have to put up with the lack of thought and foresight by the "greatest minds" in our field. Jeff

                  S Offline
                  S Offline
                  Skippums
                  wrote on last edited by
                  #30

                  Thanks to everyone who responded to my post! I got a lot of good opinions and dialogs going, and even some reasons why particular language design choices were made (although I still disagree with them). Perhaps the title of the post should have been, "Some of the features I miss from C++", as I still plan on using C# for my projects that I do in my free time, even when someone doesn't force me to. There are many great features of C# to take advantage of, and despite the few drawbacks (in my opinion, pretty significant drawbacks), it really is a great language. Thanks again everyone! Jeff

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Skippums wrote:

                    the removal of the ever useful typedef

                    "When Anders closes a door he usually opens a window someplace." No one showed you the C# way? Won't this work for you?

                    // Uncomment one of these
                    // using MyType = System.Int32 ;
                    // using MyType = System.Double ;
                    // using MyType = System.Decimal ;
                    // using MyType = System.String ;

                    namespace Test
                    {
                    class Test
                    {
                    private static MyType
                    F
                    (
                    MyType x
                    )
                    {
                    return ( x + x ) ;
                    }

                        \[System.STAThreadAttribute\]
                        static void
                        Main
                        (
                            string\[\] args
                        )
                        {
                            try
                            {
                                System.Console.WriteLine ( F ( 2 ) ) ;
                            }
                            catch ( System.Exception err )
                            {
                                System.Console.WriteLine ( err.Message ) ;
                            }
                    
                            return ;
                        }
                    }
                    

                    }

                    Of course C/C++ header files make using typedefs easier, whereas each C# file would need to have the using directive. On the other hand, you can pass C# code through the C-preprocessor if you want.

                    S Offline
                    S Offline
                    Skippums
                    wrote on last edited by
                    #31

                    "you can pass C# code through the C-preprocessor if you want" That is an interesting idea... I will have to try that one at home sometime. As far as the using statement, that works alright, but I will still have to modify the value in a number of places after the fact. What I really wanted was either namespace-scoped typedefs or project-scoped typedefs (solution-scoped would probably be nice in certain situations, but I could get by with just the other two mentioned above). Anyway, thanks for your input! Jeff

                    P 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Hi Jeff, if you want to be able to write

                      for(uniqueID id=0; id<10; id++) Console.WriteLine(id.ToString());

                      then just do it. All it takes is a simple:

                      using uniqueID=System.Int32;

                      AFAIK this has been available since day one. The one thing now really missing from C/C++ is you can't collect statements like the latter in a single header file and get them included everywhere. :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


                      S Offline
                      S Offline
                      Skippums
                      wrote on last edited by
                      #32

                      Yeah, it's just that I will still have to have that statement in EVERY file where I reference the type. For maintanence purposes, I will still have to change the using statement in every file. I will probably just end up making my own value type, storing the "real" member as private, then implement the IEquatable and IComparable interfaces, so I can still sort and test for equivalence. Also, this will allow for strong type checking, as apposed to typedef (and I think, the using statement as outlined above) where the types are actually equivalent. Anyway, thanks for the input! Jeff

                      1 Reply Last reply
                      0
                      • S Skippums

                        "you can pass C# code through the C-preprocessor if you want" That is an interesting idea... I will have to try that one at home sometime. As far as the using statement, that works alright, but I will still have to modify the value in a number of places after the fact. What I really wanted was either namespace-scoped typedefs or project-scoped typedefs (solution-scoped would probably be nice in certain situations, but I could get by with just the other two mentioned above). Anyway, thanks for your input! Jeff

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

                        Skippums wrote:

                        I will still have to modify the value in a number of places after the fact

                        Wouldn't that be the case anyway?

                        Skippums wrote:

                        thanks for your input!

                        Glad to be of service.

                        S 1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          Skippums wrote:

                          I will still have to modify the value in a number of places after the fact

                          Wouldn't that be the case anyway?

                          Skippums wrote:

                          thanks for your input!

                          Glad to be of service.

                          S Offline
                          S Offline
                          Skippums
                          wrote on last edited by
                          #34

                          Ok, you got me. I should have said, "I will still have to modify the TYPE in a number of places after the fact". Jeff

                          1 Reply Last reply
                          0
                          • C Christian Graus

                            typedefs are plain ugly. They are a holdover from C, I thought. multiple inheritance was not included probably because the design focus of C# is to make it hard to hurt yourself using it. I disagree with them, but that is their focus.

                            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                            A Offline
                            A Offline
                            Alaric_
                            wrote on last edited by
                            #35

                            bingo....your particular desired usage of typedefs typically follows a procedural mentality. ...C++ allows them because C++ is the disgusting bastard child caught in between the (now very)distant past of procedural design and what has been come to be accepted(OOP) as the way things are done from here(actually...probably closer to 10 years ago) until something better can be thought of ...C# is not the problem for placing said restrictions on you...C++ was the problem for allowing you to do them in the first place

                            "I need build Skynet. Plz send code"

                            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