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. What are the bad features of C#?

What are the bad features of C#?

Scheduled Pinned Locked Moved The Lounge
csharpquestion
32 Posts 16 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.
  • T Thomas Daniels

    Pete O'Hanlon wrote:

    C# or .NET in general?

    C# (the discussion above my discussion is about the annoying aspects of .NET development, so if you've an annoying aspect of .NET, then you can reply to the discussion above my discussion).

    The quick red ProgramFOX jumps right over the Lazy<Dog>.

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

    Sorry to hijack your thread, but I couldn't resist. :) Good question though. Really makes you think about how much you've been indoctrinated. It's kind of like asking a person, "what's wrong with your government?" :thumbsup:

    Thou mewling ill-breeding pignut!

    1 Reply Last reply
    0
    • T Thomas Daniels

      What are, in your opinion, the bad features of C#?

      The quick red ProgramFOX jumps right over the Lazy<Dog>.

      K Offline
      K Offline
      kosmoh
      wrote on last edited by
      #6

      Small, but annoying: public constructors in abstract classes. The creation of abstract class is forbidden, why do they allow public keyword for the constructor of abstract class? It confuses the developer who reads. I`d require protected/private keyword only.

      R 1 Reply Last reply
      0
      • P Pete OHanlon

        C# or .NET in general? If it was .NET, one thing I'd pick up on is the fact that generics are compile time constraints - I'd love to be able to have them as runtime constraints (a-la C++ templates). Given that there's support for dynamic in the language, I'd have thought they'd be able to extend to this as well.

        I was brought up to respect my elders. I don't respect many people nowadays.
        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        B Offline
        B Offline
        BobJanova
        wrote on last edited by
        #7

        I'm not sure you mean 'runtime' here, if you're comparing with C++. What C++ does is check, at compile time, that the methods (or system functions e.g. +) you're trying to call are defined on the class in question. That's very similar to the where constraints in C#, except it applies to operations not to interfaces. I agree that an extension to check that (for simple operations at least; I don't like the 'method signature is interface' aspect of doing it on function calls) would be good, but it could be done at compile time when you use the generic method.

        P 1 Reply Last reply
        0
        • T Thomas Daniels

          What are, in your opinion, the bad features of C#?

          The quick red ProgramFOX jumps right over the Lazy<Dog>.

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #8

          It's a scalar language, like the rest of the C family, so it's really ugly writing code that is trying to operate on array data. For example, let's say you have two lists of numbers, and you want to add them up. Why not:

          int[] a = { 1, 4, 6, 8, 21}, b = {2, 1, -3, 5, 9};
          int[] c = a + b;

          That really shouldn't require a loop construct and explicit serial array walking in 2013! Similarly, there should be some construct for

          List<object> myList = (something);
          List<string> textReps = myList.¨ToString();

          (I've used the APL 'each' symbol there but the actual syntax isn't important. In pure ASCII you could do e.g. myList[].ToString() instead) The ForEach IEnumerable extension almost does this, but you should be able to call it on arrays too, and it should be a language feature. Both of these would also provide really easy hooks for the CLR to perform parallelisation when it sees that it's appropriate.

          A Richard DeemingR 3 Replies Last reply
          0
          • B BobJanova

            I'm not sure you mean 'runtime' here, if you're comparing with C++. What C++ does is check, at compile time, that the methods (or system functions e.g. +) you're trying to call are defined on the class in question. That's very similar to the where constraints in C#, except it applies to operations not to interfaces. I agree that an extension to check that (for simple operations at least; I don't like the 'method signature is interface' aspect of doing it on function calls) would be good, but it could be done at compile time when you use the generic method.

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #9

            I've deliberately been loose with my terminology here to show that there is a difference in the behaviour between templates and generics. What I would like to see is the ability to have generics specialisation put in place.

            I was brought up to respect my elders. I don't respect many people nowadays.
            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            1 Reply Last reply
            0
            • K kosmoh

              Small, but annoying: public constructors in abstract classes. The creation of abstract class is forbidden, why do they allow public keyword for the constructor of abstract class? It confuses the developer who reads. I`d require protected/private keyword only.

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

              Reharper picks that up

              1 Reply Last reply
              0
              • B BobJanova

                It's a scalar language, like the rest of the C family, so it's really ugly writing code that is trying to operate on array data. For example, let's say you have two lists of numbers, and you want to add them up. Why not:

                int[] a = { 1, 4, 6, 8, 21}, b = {2, 1, -3, 5, 9};
                int[] c = a + b;

                That really shouldn't require a loop construct and explicit serial array walking in 2013! Similarly, there should be some construct for

                List<object> myList = (something);
                List<string> textReps = myList.¨ToString();

                (I've used the APL 'each' symbol there but the actual syntax isn't important. In pure ASCII you could do e.g. myList[].ToString() instead) The ForEach IEnumerable extension almost does this, but you should be able to call it on arrays too, and it should be a language feature. Both of these would also provide really easy hooks for the CLR to perform parallelisation when it sees that it's appropriate.

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

                For the first, C# now supports initializer lists. EDIT: I misunderstood your first item. However, LINQ should allow this to be pretty minimal. For the second, you can use LINQ to perform mapping with minimal code.

                Thou mewling ill-breeding pignut!

                1 Reply Last reply
                0
                • B BobJanova

                  It's a scalar language, like the rest of the C family, so it's really ugly writing code that is trying to operate on array data. For example, let's say you have two lists of numbers, and you want to add them up. Why not:

                  int[] a = { 1, 4, 6, 8, 21}, b = {2, 1, -3, 5, 9};
                  int[] c = a + b;

                  That really shouldn't require a loop construct and explicit serial array walking in 2013! Similarly, there should be some construct for

                  List<object> myList = (something);
                  List<string> textReps = myList.¨ToString();

                  (I've used the APL 'each' symbol there but the actual syntax isn't important. In pure ASCII you could do e.g. myList[].ToString() instead) The ForEach IEnumerable extension almost does this, but you should be able to call it on arrays too, and it should be a language feature. Both of these would also provide really easy hooks for the CLR to perform parallelisation when it sees that it's appropriate.

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

                  How about these:

                  int[] a = { 1, 2, 3 }, b = { 4, 5, 6 };
                  int[] c = a.Select((x, index) => x + b[index]).ToArray();

                  List<object> myList = new List<object>() { 1, "dragon", new Object() };
                  List<string> textReps = myList.Select((x) => x.ToString()).ToList();

                  Thou mewling ill-breeding pignut!

                  B Richard DeemingR 2 Replies Last reply
                  0
                  • T Thomas Daniels

                    What are, in your opinion, the bad features of C#?

                    The quick red ProgramFOX jumps right over the Lazy<Dog>.

                    M Offline
                    M Offline
                    Matthew Faithfull
                    wrote on last edited by
                    #13

                    1. Unnecessary loss of control. I'm a control freak like most good programmers. Garabage Collection is fine but I must be able to make it happen when I require it and prevent it happening when I require 100% of the available performance. 2. Loss of the compilation unit concept. Removing the separation between header and implementation files is often seen as a good thing but it has non obvious negative effects. I'm no longer able to specify a pure interface for the purposes of export or interop (within the language) which has an implementation but the declaration of which can be used without access to or depenedency on the implementation. The separation of .h and .cpp files was not a mistake, oversight, shortcut or side effect of some other inadequacy. It was a deliberate and sensible idea that certain people at Microsoft never really understood. 3. Loss of dependency control. Removing the #include concept, also related to the loss of compilation units, means I'll never really know precisely what the compiler does and doesn't reference when compiling a class in exact files access terms. Like many such things this is OK if it's right but a nightmare if I have 7 versions of Runtime library headers installed and I can't tell which one it is getting its definitions from. 4. The additional learning requirement of endless extra badly specified and poorly documented 'secondary' languages. Most of the mitigation Microsoft have put in for items 2 and 3 has lead to the addition of yet more different formats of files to a project. App configs, manifests, non compiled resources &c. Every one of these new files is in what is effectively a new language although it is seldom recognised as such. Each and every one requires additional tools and or more knowledge to use it properly. Anything which increases the number of languages, formats, conventions or rules I need to know in order to do my job makes it harder not easier. Every time I have to edit or otherwise interact with one of these kludges I have to to stop thinking in C++ and switch to something else, usually some hacked subset of XML. The switching cost in time, concentration and quality of perception is high and completely unaccounted for by those who promote more and more such sub-domain specific languages. 5. Forcing me to use a JIT compiler when Native compilation should and could be available is another unacceptable loss of control. 6. Not strictly a C# issue, however providing a class library (the CLR) but forcing me to learn and use a new language

                    1 Reply Last reply
                    0
                    • T Thomas Daniels

                      What are, in your opinion, the bad features of C#?

                      The quick red ProgramFOX jumps right over the Lazy<Dog>.

                      D Offline
                      D Offline
                      Dave Kerr
                      wrote on last edited by
                      #14

                      Lack of support for C++ style 'const' (but this is a .NET limitation) and the inability to create generics for maths, i.e. class Matrix { } you can't make a matrix template for ints/floats/complex numbers because you cannot say in a template definition something like: class Matrix where T : *,+,-,/ So mathematical templates are darn near impossible to make. But other than that C# is pretty darn good. also 'dynamic' types are a nice time saver syntactically, but not very sensible in a static language.

                      My Blog: www.dwmkerr.com My Charity: Children's Homes Nepal

                      Richard DeemingR 1 Reply Last reply
                      0
                      • T Thomas Daniels

                        What are, in your opinion, the bad features of C#?

                        The quick red ProgramFOX jumps right over the Lazy<Dog>.

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

                        All listed here[^] I'm afraid.

                        If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

                        "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

                        1 Reply Last reply
                        0
                        • A AspDotNetDev

                          How about these:

                          int[] a = { 1, 2, 3 }, b = { 4, 5, 6 };
                          int[] c = a.Select((x, index) => x + b[index]).ToArray();

                          List<object> myList = new List<object>() { 1, "dragon", new Object() };
                          List<string> textReps = myList.Select((x) => x.ToString()).ToList();

                          Thou mewling ill-breeding pignut!

                          B Offline
                          B Offline
                          BobJanova
                          wrote on last edited by
                          #16

                          They are nice (I love Linq extension methods), but still not as nice as if the language did it natively.

                          A 1 Reply Last reply
                          0
                          • T Thomas Daniels

                            What are, in your opinion, the bad features of C#?

                            The quick red ProgramFOX jumps right over the Lazy<Dog>.

                            D Offline
                            D Offline
                            dusty_dex
                            wrote on last edited by
                            #17

                            Not being able to convert an old project in order to recompile against later frameworks, if you didn't get the version of VS that did the conversion. VS2003 will convert 2001 projects. VS2005 won't. It's a similar situation converting Visual C/C++ 6 projects. in VS2005 it can't be done unless you happen to have VS2003 lying around to do an intermediate conversion. I suppose the fear factor will keep the money rolling in for Microsoft when developers get wind of these issues. A syntax shortcoming recently discussed on CP.

                            break <label>;

                            "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                            Richard DeemingR B 2 Replies Last reply
                            0
                            • B BobJanova

                              They are nice (I love Linq extension methods), but still not as nice as if the language did it natively.

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

                              BobJanova wrote:

                              not as nice as if the language did it natively

                              That's the second time somebody has said that recently. I don't understand why it matters if the language does it natively. The language supports LINQ, and LINQ does it, so what's the problem with that? If you really wanted, you could even extend LINQ (e.g., myList.AllToString()), overload the plus operator (e.g., new MyArray(a) + new MyArray(b)), or create an extension method and overloaded operator (e.g., a.Extras() + b.Extras()).

                              Thou mewling ill-breeding pignut!

                              1 Reply Last reply
                              0
                              • T Thomas Daniels

                                What are, in your opinion, the bad features of C#?

                                The quick red ProgramFOX jumps right over the Lazy<Dog>.

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

                                It's got a bad pedigree. It's from Mickeysoft.

                                Sent from my BatComputer via HAL 9000 and M5

                                1 Reply Last reply
                                0
                                • B BobJanova

                                  It's a scalar language, like the rest of the C family, so it's really ugly writing code that is trying to operate on array data. For example, let's say you have two lists of numbers, and you want to add them up. Why not:

                                  int[] a = { 1, 4, 6, 8, 21}, b = {2, 1, -3, 5, 9};
                                  int[] c = a + b;

                                  That really shouldn't require a loop construct and explicit serial array walking in 2013! Similarly, there should be some construct for

                                  List<object> myList = (something);
                                  List<string> textReps = myList.¨ToString();

                                  (I've used the APL 'each' symbol there but the actual syntax isn't important. In pure ASCII you could do e.g. myList[].ToString() instead) The ForEach IEnumerable extension almost does this, but you should be able to call it on arrays too, and it should be a language feature. Both of these would also provide really easy hooks for the CLR to perform parallelisation when it sees that it's appropriate.

                                  Richard DeemingR Offline
                                  Richard DeemingR Offline
                                  Richard Deeming
                                  wrote on last edited by
                                  #20

                                  In your first example, it's not immediately obvious what you're expecting to happen. Should the output be:

                                  { 1, 4, 6, 8, 21, 2, 1, -3, 5, 9 }

                                  Or:

                                  { 3, 5, 3, 13, 30 }

                                  If it's the second option, what should happen if the operands have different lengths? Different types? Different ranks? Your solution has a much higher cognitive overhead than simply:

                                  int[] c = a.Zip(b, (x, y) => x + y).ToArray();

                                  For your second example, you could use:

                                  List<string> textReps = myList.ConvertAll(Convert.ToString);

                                  It even works with arrays:

                                  string[] testReps = Array.ConvertAll(myArray, Convert.ToString);


                                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                                  B 1 Reply Last reply
                                  0
                                  • A AspDotNetDev

                                    How about these:

                                    int[] a = { 1, 2, 3 }, b = { 4, 5, 6 };
                                    int[] c = a.Select((x, index) => x + b[index]).ToArray();

                                    List<object> myList = new List<object>() { 1, "dragon", new Object() };
                                    List<string> textReps = myList.Select((x) => x.ToString()).ToList();

                                    Thou mewling ill-breeding pignut!

                                    Richard DeemingR Offline
                                    Richard DeemingR Offline
                                    Richard Deeming
                                    wrote on last edited by
                                    #21

                                    AspDotNetDev wrote:

                                    List<string> textReps = myList.Select((x) => x.ToString()).ToList();

                                    Easy to break: ;P

                                    List<object> myList = new List<object> { 1, "dragon", null };


                                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                                    A 1 Reply Last reply
                                    0
                                    • D Dave Kerr

                                      Lack of support for C++ style 'const' (but this is a .NET limitation) and the inability to create generics for maths, i.e. class Matrix { } you can't make a matrix template for ints/floats/complex numbers because you cannot say in a template definition something like: class Matrix where T : *,+,-,/ So mathematical templates are darn near impossible to make. But other than that C# is pretty darn good. also 'dynamic' types are a nice time saver syntactically, but not very sensible in a static language.

                                      My Blog: www.dwmkerr.com My Charity: Children's Homes Nepal

                                      Richard DeemingR Offline
                                      Richard DeemingR Offline
                                      Richard Deeming
                                      wrote on last edited by
                                      #22

                                      It's quite easy to use LINQ expressions to create generic operators. There's a decent example in the MiscUtil project: http://www.yoda.arachsys.com/csharp/miscutil/[^] You essentially do something like this:

                                      public static class GenericOperator<T>
                                      {
                                      private static Func<T, T, TResult> Create<TResult>(Func<Expression, Expression, BinaryExpression> body)
                                      {
                                      try
                                      {
                                      Type typeT = typeof(T);
                                      var left = Expression.Parameter(typeT, "left");
                                      var right = Expression.Parameter(typeT, "right");

                                              if (typeT.IsEnum)
                                              {
                                                  Type enumType = Enum.GetUnderlyingType(typeT);
                                                  var x = Expression.Convert(left, enumType);
                                                  var y = Expression.Convert(right, enumType);
                                      
                                                  Expression op = body(x, y);
                                                  if (op.Type == enumType) op = Expression.Convert(op, typeT);
                                      
                                                  return Expression.Lambda<Func<T, T, TResult>>(op, left, right).Compile();
                                              }
                                      
                                              return Expression.Lambda<Func<T, T, TResult>>(body(left, right), left, right).Compile();
                                          }
                                          catch (InvalidOperationException ex)
                                          {
                                              string message = ex.Message;
                                              return delegate { throw new InvalidOperationException(message); };
                                          }
                                          catch (ArgumentException ex)
                                          {
                                              string message = ex.Message;
                                              return delegate { throw new InvalidOperationException(message); };
                                          }
                                      }
                                      
                                      private static readonly Lazy<Func<T, T, T>> \_add = Create<T>(Expression.Add);
                                      
                                      public static Func<T, T, T> Add
                                      {
                                          get { return \_add.Value; }
                                      }
                                      

                                      }

                                      public static class GenericMath
                                      {
                                      public static T Add<T>(T left, T right)
                                      {
                                      return GenericOperator<T>.Add(left, right);
                                      }
                                      }

                                      And then in your generic class, you just use:

                                      T x = someValue;
                                      T y = someOtherValue;
                                      T result = GenericMath.Add(x, y);

                                      The only problem is that you can't constrain the type parameters to have the required operators. If they don't, you'll get an InvalidOperationException when you call the relevant method.


                                      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                                      1 Reply Last reply
                                      0
                                      • D dusty_dex

                                        Not being able to convert an old project in order to recompile against later frameworks, if you didn't get the version of VS that did the conversion. VS2003 will convert 2001 projects. VS2005 won't. It's a similar situation converting Visual C/C++ 6 projects. in VS2005 it can't be done unless you happen to have VS2003 lying around to do an intermediate conversion. I suppose the fear factor will keep the money rolling in for Microsoft when developers get wind of these issues. A syntax shortcoming recently discussed on CP.

                                        break <label>;

                                        "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                                        Richard DeemingR Offline
                                        Richard DeemingR Offline
                                        Richard Deeming
                                        wrote on last edited by
                                        #23

                                        I haven't seen that problem. It's possibly related to the project file format changes when they switched to MSBuild. From what I've seen, VS2012 can open projects created in 2005, 2008 or 2010 without any problems (unless the project type has been discontinued, which happens far too often!).


                                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                                        D 1 Reply Last reply
                                        0
                                        • Richard DeemingR Richard Deeming

                                          I haven't seen that problem. It's possibly related to the project file format changes when they switched to MSBuild. From what I've seen, VS2012 can open projects created in 2005, 2008 or 2010 without any problems (unless the project type has been discontinued, which happens far too often!).


                                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                          D Offline
                                          D Offline
                                          dusty_dex
                                          wrote on last edited by
                                          #24

                                          Yes, the project file format changed between VS2003 and 2005, and like you say MSBUILD is the new way of doing things. I tried the express version of VS2008 but it drove me nuts. I'll be sticking with VS2005 until I find something equally stable/reliable. I don't need LINQ features right now, just x64 bits.

                                          "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                                          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