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. i don't like object oriented programming

i don't like object oriented programming

Scheduled Pinned Locked Moved The Lounge
csharpc++wpfoop
94 Posts 18 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.
  • D Dannyyx

    You shouldn't look at object oriented programming as if you're working with objects. You should look at it objectively.

    H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #53

    i know how to code OO. i just don't like OO because it requires a lot of code to do a little bit.

    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

    D 1 Reply Last reply
    0
    • S Super Lloyd

      I dunno if there was a problem before.. but it's copy paste from some code I was just running on a test project while thinking about your problem.... So, shortly, this is fine. Assuming it was not always working (which I doubt) the test project use .NET Framework 4.7.2 and C# compiler latest version, i.e. 7.3 **[EDIT & REMARK]**this looks like perfectly valid C# since the beginning of generic to me. Odds are you got confused at some stage...

      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

      H Offline
      H Offline
      honey the codewitch
      wrote on last edited by
      #54

      i looked at your code wrong, didn't notice until i tried writing one myself. that's not template specialization, but simply method overloading - and i'm doing it already class CharFA : FA { .. }

      When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

      S 1 Reply Last reply
      0
      • H honey the codewitch

        oh i see what you did. that's not template specialization. that's method overloading

        When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

        S Offline
        S Offline
        Super Lloyd
        wrote on last edited by
        #55

        yeah but... it behave quite similarly...

        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

        H 2 Replies Last reply
        0
        • S Super Lloyd

          yeah but... it behave quite similarly...

          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #56

          not really. only in the specific scenario where all you need is method overloading. and even then it's not the same, because you have two separate classes in your code now instead of one.

          When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

          1 Reply Last reply
          0
          • S Super Lloyd

            yeah but... it behave quite similarly...

            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #57

            here let me give you an example of where it's not the same ... FooBase DerivedMethod() { return BaseMethod() } ... FooBase BaseMethod() { return new FooBase(); } ... in a specialization there are no base methods, so above would always return the fully derived class

            When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

            1 Reply Last reply
            0
            • H honey the codewitch

              i looked at your code wrong, didn't notice until i tried writing one myself. that's not template specialization, but simply method overloading - and i'm doing it already class CharFA : FA { .. }

              When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

              S Offline
              S Offline
              Super Lloyd
              wrote on last edited by
              #58

              Yeah, I was wondering, isn't that good enough?! But then I realised one could accidentally instantiate new FA() instead of the desired new CharFA() But then what of this other syntax? While it's slightly more wordy, I bet the end compiled result is just as you desired

              class A
              {
                  public void Do(T value)
                  {
                      if (value is int intV) Do(intV);
                      else DoDefault(value);
                  }
                  void DoDefault(T value)
                  {
                      Console.WriteLine("Value: " + value);
                  }
                  void Do(int value)
                  {
                      Console.WriteLine("Int: " + value);
                  }
              }
              class Program
              {
                  static void Main(string\[\] args)
                  {
                      A a = new A();
                      a.Do(1);
                  }
              }
              

              I mean personally I am happy to solve that using subclasses or interfaces, but since you really didn't want to....

              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

              H 2 Replies Last reply
              0
              • S Super Lloyd

                Yeah, I was wondering, isn't that good enough?! But then I realised one could accidentally instantiate new FA() instead of the desired new CharFA() But then what of this other syntax? While it's slightly more wordy, I bet the end compiled result is just as you desired

                class A
                {
                    public void Do(T value)
                    {
                        if (value is int intV) Do(intV);
                        else DoDefault(value);
                    }
                    void DoDefault(T value)
                    {
                        Console.WriteLine("Value: " + value);
                    }
                    void Do(int value)
                    {
                        Console.WriteLine("Int: " + value);
                    }
                }
                class Program
                {
                    static void Main(string\[\] args)
                    {
                        A a = new A();
                        a.Do(1);
                    }
                }
                

                I mean personally I am happy to solve that using subclasses or interfaces, but since you really didn't want to....

                A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                H Offline
                H Offline
                honey the codewitch
                wrote on last edited by
                #59

                Yeah I can't do that in this code because this code is inner loop critical and the "is" comparison is just a dog. I think "as" is faster, but still, it should be resolved at compile time. I know it seems a minor quibble but this code may be used as part of a lexer. The lexing itself needs to be balls quick to be feasible. also i'd be concerned about bugs this could introduce since i have to repeat a lot of code, but that's not a showstopper. it's just irritating

                When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                S 1 Reply Last reply
                0
                • S Super Lloyd

                  Yeah, I was wondering, isn't that good enough?! But then I realised one could accidentally instantiate new FA() instead of the desired new CharFA() But then what of this other syntax? While it's slightly more wordy, I bet the end compiled result is just as you desired

                  class A
                  {
                      public void Do(T value)
                      {
                          if (value is int intV) Do(intV);
                          else DoDefault(value);
                      }
                      void DoDefault(T value)
                      {
                          Console.WriteLine("Value: " + value);
                      }
                      void Do(int value)
                      {
                          Console.WriteLine("Int: " + value);
                      }
                  }
                  class Program
                  {
                      static void Main(string\[\] args)
                      {
                          A a = new A();
                          a.Do(1);
                      }
                  }
                  

                  I mean personally I am happy to solve that using subclasses or interfaces, but since you really didn't want to....

                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                  H Offline
                  H Offline
                  honey the codewitch
                  wrote on last edited by
                  #60

                  adding, my solution to the object creation was to have a method in the base class called CreateFA() that could be overloaded in order to force the base class to create the derived class. Unfortunately to get it to work I had to remove every static method that created objects from the base class =(

                  When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                  1 Reply Last reply
                  0
                  • H honey the codewitch

                    Yeah I can't do that in this code because this code is inner loop critical and the "is" comparison is just a dog. I think "as" is faster, but still, it should be resolved at compile time. I know it seems a minor quibble but this code may be used as part of a lexer. The lexing itself needs to be balls quick to be feasible. also i'd be concerned about bugs this could introduce since i have to repeat a lot of code, but that's not a showstopper. it's just irritating

                    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                    S Offline
                    S Offline
                    Super Lloyd
                    wrote on last edited by
                    #61

                    I think you probably underestimate the compiler here generic code are some sort of IL that is used to generate code on demand (when a concrete type is used) when, say A type is created the compiler will see that

                    void Do(int value) {
                    if (value is double d) { // dead end code prune by the compiler
                    }
                    if (value is int ii) Do (ii);
                    }

                    some path will never happen and it will removed them from the concrete implementation created when the concrete type is created. and the compiled code will become

                    void Do(int value) {
                    Do (value);
                    }

                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                    H 1 Reply Last reply
                    0
                    • S Super Lloyd

                      I think you probably underestimate the compiler here generic code are some sort of IL that is used to generate code on demand (when a concrete type is used) when, say A type is created the compiler will see that

                      void Do(int value) {
                      if (value is double d) { // dead end code prune by the compiler
                      }
                      if (value is int ii) Do (ii);
                      }

                      some path will never happen and it will removed them from the concrete implementation created when the concrete type is created. and the compiled code will become

                      void Do(int value) {
                      Do (value);
                      }

                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                      H Offline
                      H Offline
                      honey the codewitch
                      wrote on last edited by
                      #62

                      The reason I underestimate the compiler maybe is the last the time I really examined IL was in the .NET 2.0-3.0 days and the compiler didn't do hardly anything for program optimization. Microsoft's rationale seemed to be that JIT would take care of it, but JIT doesn't do whole program optimization. It can only do peephole optimization, so I don't know what they were thinking. My guess is it was an excuse due to deadlines. So I don't trust the compiler that much. Maybe my information is old. The compiler certainly has been revamped since then.

                      When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                      S 1 Reply Last reply
                      0
                      • H honey the codewitch

                        The reason I underestimate the compiler maybe is the last the time I really examined IL was in the .NET 2.0-3.0 days and the compiler didn't do hardly anything for program optimization. Microsoft's rationale seemed to be that JIT would take care of it, but JIT doesn't do whole program optimization. It can only do peephole optimization, so I don't know what they were thinking. My guess is it was an excuse due to deadlines. So I don't trust the compiler that much. Maybe my information is old. The compiler certainly has been revamped since then.

                        When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                        S Offline
                        S Offline
                        Super Lloyd
                        wrote on last edited by
                        #63

                        I mean it's such an obvious static type check optimisation.. I haven't explicitly checked for it, but I would wage $5 on it! ;P

                        void Do(int value) {
                        // I would wage $5 the compiler remove the if statement and execute the nested statement always
                        if (value is int ii) {
                        }
                        // I would wage 5 dollar this is removed by the compiler
                        if (value is double dd) {
                        }
                        }

                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                        H 1 Reply Last reply
                        0
                        • S Super Lloyd

                          I mean it's such an obvious static type check optimisation.. I haven't explicitly checked for it, but I would wage $5 on it! ;P

                          void Do(int value) {
                          // I would wage $5 the compiler remove the if statement and execute the nested statement always
                          if (value is int ii) {
                          }
                          // I would wage 5 dollar this is removed by the compiler
                          if (value is double dd) {
                          }
                          }

                          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                          H Offline
                          H Offline
                          honey the codewitch
                          wrote on last edited by
                          #64

                          based on my experience, I'd take that bet.

                          When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                          S 2 Replies Last reply
                          0
                          • H honey the codewitch

                            one example I'm running into right now is template specialization. I have a finite state machine engine and it works for any transition input type and any accept symbol type. However, there are additional features that can happen - significant ones that can only exist when the transition type is char - this specialization is effectively a regular expression engine, which means it can parse from a regular expression, and provide regex matching over string inputs. The other kind of FAs it wouldn't even make sense for that. So because of this I have two separate classes - one generic FA class, and one called CharFA where the TInput=char basically. It means more code to maintain because a lot of it is duplicated. To unduplicate a lot of which i could, I'd have to add another codefile with an interface, and another with static methods to share common functionality, which again, increases the code size. So it's not even that I can't do it with C#, it's that what is elegantly handled in C++ is clunky in C# to do the same thing, and requires more code.

                            When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                            O Offline
                            O Offline
                            obermd
                            wrote on last edited by
                            #65

                            Take a look at F# or another functional language. State machines and functional languages are made for each other.

                            H 1 Reply Last reply
                            0
                            • O obermd

                              Take a look at F# or another functional language. State machines and functional languages are made for each other.

                              H Offline
                              H Offline
                              honey the codewitch
                              wrote on last edited by
                              #66

                              I've strongly considered it. I might eventually move, but I'm familiar with C#. Maybe if they had Haskell I would have moved already. Edit: Adding, one of the drawbacks of functional programming is lack of state, and some of these equations are so complicated that state is necessary for optimization and I wonder how a functional language will handle such a thing. Recomputing or doing lazy iteration over these algorithms is grossly impractical even if it's "correct"

                              When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                              R 1 Reply Last reply
                              0
                              • H honey the codewitch

                                i never have. give me templates. or you may as well just give me something procedural. if i can't do generic programming i'm a sad honey bear. C# is barely adequate. And it's too object centric IMO. generics need to be able to do more. I want traits. I want the runtimes to do what i can make a C++ compiler do with templates. I probably just got the BAC up of this entire board saying that, but there it is.

                                When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                T Offline
                                T Offline
                                TNCaver
                                wrote on last edited by
                                #67

                                Alan Kay, the father of OOP, says we're doing it all wrong and regrets using the word "object" as it emphasizes the secondary concern of OOP and ignores the primary concern of messaging. Lots of very smart computer scientists say modern OOP makes programming more complex and prone to error rather than simplifying it.

                                If you think 'goto' is evil, try writing an Assembly program without JMP.

                                H 1 Reply Last reply
                                0
                                • T TNCaver

                                  Alan Kay, the father of OOP, says we're doing it all wrong and regrets using the word "object" as it emphasizes the secondary concern of OOP and ignores the primary concern of messaging. Lots of very smart computer scientists say modern OOP makes programming more complex and prone to error rather than simplifying it.

                                  If you think 'goto' is evil, try writing an Assembly program without JMP.

                                  H Offline
                                  H Offline
                                  honey the codewitch
                                  wrote on last edited by
                                  #68

                                  i like message/signal based systems but most runtimes don't include some basics that should be "primitives/intrinsics" or otherwise first class, like thread safe priority queues and circular buffers and such. At the very least they should be runtime libraries provided with the base framework. But I really think if Alan Kay had wanted a message based programming environment it should have been done somewhat differently than OOP. think something a bit more along lines of parallel programming style constructs and the like, except instead of dealing with iterations of loops you're dealing with signalling. honestly, it's easy enough to create a domain-specific set of "language extension" style headers in C++ to enable this. I love C++ for that. about 1/3 of the language is the headers and because of the way the preprocessor and template system works you can create your own pseudo language constructs. There's nothing else like it in major programming languages but I really wish their was.

                                  When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                  T 1 Reply Last reply
                                  0
                                  • H honey the codewitch

                                    based on my experience, I'd take that bet.

                                    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                    S Offline
                                    S Offline
                                    Super Lloyd
                                    wrote on last edited by
                                    #69

                                    well.. my assembly is a bit rusty (or almost non existent) I will let you judge... But here my test C# code

                                    class A
                                    {
                                        public void Do(T value)
                                        {
                                            if (value is int intV) Do(intV);
                                            else DoDefault(value);
                                        }
                                        void DoDefault(T value)
                                        {
                                            Console.WriteLine("Value: " + value);
                                        }
                                        void Do(int value)
                                        {
                                            Console.WriteLine("Int: " + value);
                                        }
                                    }
                                    class Program
                                    {
                                        static void Main(string\[\] args)
                                        {
                                            A a = new A();
                                            a.Do(1);
                                    
                                            A b = new A();
                                            b.Do(1.0);
                                        }
                                    }
                                    

                                    here is the code for a.Do(1) and b.Do(1.0) using go to disassembly in visual studio

                                            a.Do(1);
                                    

                                    00F70898 mov ecx,dword ptr [ebp-40h]
                                    00F7089B mov edx,1
                                    00F708A0 cmp dword ptr [ecx],ecx
                                    00F708A2 call 00F70478
                                    00F708A7 nop

                                            b.Do(1.0);
                                    

                                    00F708C3 fld qword ptr ds:[0F708E8h]
                                    00F708C9 sub esp,8
                                    00F708CC fstp qword ptr [esp]
                                    00F708CF mov ecx,dword ptr [ebp-44h]
                                    00F708D2 cmp dword ptr [ecx],ecx
                                    00F708D4 call 00F704A0
                                    00F708D9 nop

                                    I think there is no (assembly) if statement and direct execution of the relevant if (type) branch....

                                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                    H 1 Reply Last reply
                                    0
                                    • S Super Lloyd

                                      well.. my assembly is a bit rusty (or almost non existent) I will let you judge... But here my test C# code

                                      class A
                                      {
                                          public void Do(T value)
                                          {
                                              if (value is int intV) Do(intV);
                                              else DoDefault(value);
                                          }
                                          void DoDefault(T value)
                                          {
                                              Console.WriteLine("Value: " + value);
                                          }
                                          void Do(int value)
                                          {
                                              Console.WriteLine("Int: " + value);
                                          }
                                      }
                                      class Program
                                      {
                                          static void Main(string\[\] args)
                                          {
                                              A a = new A();
                                              a.Do(1);
                                      
                                              A b = new A();
                                              b.Do(1.0);
                                          }
                                      }
                                      

                                      here is the code for a.Do(1) and b.Do(1.0) using go to disassembly in visual studio

                                              a.Do(1);
                                      

                                      00F70898 mov ecx,dword ptr [ebp-40h]
                                      00F7089B mov edx,1
                                      00F708A0 cmp dword ptr [ecx],ecx
                                      00F708A2 call 00F70478
                                      00F708A7 nop

                                              b.Do(1.0);
                                      

                                      00F708C3 fld qword ptr ds:[0F708E8h]
                                      00F708C9 sub esp,8
                                      00F708CC fstp qword ptr [esp]
                                      00F708CF mov ecx,dword ptr [ebp-44h]
                                      00F708D2 cmp dword ptr [ecx],ecx
                                      00F708D4 call 00F704A0
                                      00F708D9 nop

                                      I think there is no (assembly) if statement and direct execution of the relevant if (type) branch....

                                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                      H Offline
                                      H Offline
                                      honey the codewitch
                                      wrote on last edited by
                                      #70

                                      there's a call in there that looks suspicious. I'd need to see the IL, not the asm.

                                      When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                      S 2 Replies Last reply
                                      0
                                      • H honey the codewitch

                                        based on my experience, I'd take that bet.

                                        When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                        S Offline
                                        S Offline
                                        Super Lloyd
                                        wrote on last edited by
                                        #71

                                        Oops forget my previous example, I was confused.. the debug assembly code does indeed look atrocious... Gotta try to check the release version

                                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                        H 1 Reply Last reply
                                        0
                                        • H honey the codewitch

                                          there's a call in there that looks suspicious. I'd need to see the IL, not the asm.

                                          When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                          S Offline
                                          S Offline
                                          Super Lloyd
                                          wrote on last edited by
                                          #72

                                          release code atrocious too...

                                          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                          H 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