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. Why do I listen to my sleep coding self?

Why do I listen to my sleep coding self?

Scheduled Pinned Locked Moved The Lounge
csharpdesignquestion
41 Posts 20 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.
  • OriginalGriffO OriginalGriff

    In bed last night, I dreamt a wonderful improvement to the design of some software I'm working on. It would clean it up, move the code into it's appropriate classes, make it all beautiful. So I have just coded it. Or at least, I coded 3/4 of it. That was the point when I thought "Hang on a moment, you can't have abstract static methods in C#". :doh: Bugger. Note to self: don't listen to me when I'm sleepy. Anyone else done this? Constructed a massive edifice of beautiful code in your mind, only to find when you have got sufficient caffeine in your system that it has a fatal, fundamental, flaw?

    Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

    Mike HankeyM Offline
    Mike HankeyM Offline
    Mike Hankey
    wrote on last edited by
    #14

    Usually the code I dream about is good but occasionally I waste time on a bomb, depends what I had been drinking the night before? :)

    If first you don't succeed, hide all evidence you ever tried!

    K 1 Reply Last reply
    0
    • B BobJanova

      You're thinking too much about the C++ style implementation. There's actually no reason why you can't have vtable entries for static methods, though, even using that model – they'd just get passed nothing for the instance parameter. You just have to choose a different way of determining the type that should get dispatched, instead of using the instance's dynamic type, for example the declaration type of the method which was originally called. Delphi goes some way towards this but it doesn't really work well because it doesn't sort out the dispatch properly.

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

      BobJanova wrote:

      There's actually no reason why you can't have vtable entries for static methods

      Ok fair enough, obviously you can put anything in there, including random bytes, but that then brings us to:

      BobJanova wrote:

      You just have to choose a different way of determining the type that should get dispatched, instead of using the instance's dynamic type,

      I don't really see any options there, but that might be because I don't understand exactly what you mean by this:

      BobJanova wrote:

      the declaration type of the method which was originally called.

      B 1 Reply Last reply
      0
      • Mike HankeyM Mike Hankey

        Usually the code I dream about is good but occasionally I waste time on a bomb, depends what I had been drinking the night before? :)

        If first you don't succeed, hide all evidence you ever tried!

        K Offline
        K Offline
        Kenneth Haugland
        wrote on last edited by
        #16

        Quote:

        I waste time on a bomb

        Perhaps this is an indication of a flatulence problem in your sleep? :laugh:

        Mike HankeyM 1 Reply Last reply
        0
        • M Marco Bertschi

          OriginalGriff wrote:

          That means I don't get "fixated" on "this must be why" and my subconscious is free to "bing" me and say "Try this, not that".

          And that's how I defend smoking a pack a day :laugh:

          The console is a black place

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

          That's what I used to do - take a cigarette break every hour. When I gave up, I realized I wasn't getting as much work done, because I wasn't taking a break! :laugh: So rather than take up smoking again (and having seen the price they are charging for them these days, I can think of much, much better things to do with the money) I take a break without the cancer-stick.

          Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

          "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
          • K Kenneth Haugland

            Quote:

            I waste time on a bomb

            Perhaps this is an indication of a flatulence problem in your sleep? :laugh:

            Mike HankeyM Offline
            Mike HankeyM Offline
            Mike Hankey
            wrote on last edited by
            #18

            Kenneth Haugland wrote:

            Perhaps this is an indication of a flatulence problem in your sleep?

            When I can't sleep I don't count sheep I count... :)

            If first you don't succeed, hide all evidence you ever tried!

            1 Reply Last reply
            0
            • L Lost User

              BobJanova wrote:

              There's actually no reason why you can't have vtable entries for static methods

              Ok fair enough, obviously you can put anything in there, including random bytes, but that then brings us to:

              BobJanova wrote:

              You just have to choose a different way of determining the type that should get dispatched, instead of using the instance's dynamic type,

              I don't really see any options there, but that might be because I don't understand exactly what you mean by this:

              BobJanova wrote:

              the declaration type of the method which was originally called.

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

              Ok so let's have an example.

              public static class BaseService {
              public static void LoadData() {
              Console.WriteLine(GetDataSource());
              }

              protected virtual static string GetDataSource();
              }

              public static class FileService : BaseService {
              protected override static string GetDataSource() { return "file.dat"; }
              }

              public static class DatabaseService : BaseService {
              protected override static string GetDataSource() { return "database"; }
              }

              ... and calling code

              void Run() {
              DatabaseService.LoadData();
              FileService.LoadData();
              }

              This would print "database" and "file.dat", because the class used for the vtable lookups would be taken from the data type used for the call (i.e. DatabaseService.LoadData). That would be resolved at compile time and based on the static declaration type used in the call, not dynamic object type lookups as with instance dispatch. A related good idea is the ability to pass service classes around and dispatch off them:

              void Run(Class<BaseService> service) {
              service.LoadData();
              }

              ... called like Run(DatabaseService) which would bake in the type for dispatch.

              L 1 Reply Last reply
              0
              • B BobJanova

                Ok so let's have an example.

                public static class BaseService {
                public static void LoadData() {
                Console.WriteLine(GetDataSource());
                }

                protected virtual static string GetDataSource();
                }

                public static class FileService : BaseService {
                protected override static string GetDataSource() { return "file.dat"; }
                }

                public static class DatabaseService : BaseService {
                protected override static string GetDataSource() { return "database"; }
                }

                ... and calling code

                void Run() {
                DatabaseService.LoadData();
                FileService.LoadData();
                }

                This would print "database" and "file.dat", because the class used for the vtable lookups would be taken from the data type used for the call (i.e. DatabaseService.LoadData). That would be resolved at compile time and based on the static declaration type used in the call, not dynamic object type lookups as with instance dispatch. A related good idea is the ability to pass service classes around and dispatch off them:

                void Run(Class<BaseService> service) {
                service.LoadData();
                }

                ... called like Run(DatabaseService) which would bake in the type for dispatch.

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

                Ok, I see what you mean.

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  :laugh: I work for myself, so I give myself special permission to "goof off". :laugh:

                  Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                  A Offline
                  A Offline
                  AnnPandora
                  wrote on last edited by
                  #21

                  Lucky you! Allowed to give yourself some special permissions :laugh:

                  OriginalGriffO 1 Reply Last reply
                  0
                  • A AnnPandora

                    Lucky you! Allowed to give yourself some special permissions :laugh:

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

                    The down side is the Christmas party is a little lonely... ;)

                    Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                    "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

                    A 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      The down side is the Christmas party is a little lonely... ;)

                      Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                      A Offline
                      A Offline
                      AnnPandora
                      wrote on last edited by
                      #23

                      Started working here the week after they had their Christmas party so I can't give you any feedback on that one, yet! :-D

                      1 Reply Last reply
                      0
                      • L Lost User

                        0 times. I've wished that interfaces could contain static methods so that T.someFunction could exist for generics (constrained to that interface), but that's a completely separate issue. (that can't work in C# of course) How is "static virtual" even a reasonable concept? No instance = no vptr = no dynamic dispatch.

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

                        harold aptroot wrote:

                        no vptr

                        Don't get hung up on how current languages are implemented. I too would like a language that allows static members in interfaces and abstracts. If a Bright compiler developer wanted to make this happen, I'm sure he could, it would likely have to be very different from current implementations. (It's way beyond my skills of course.)

                        You'll never get very far if all you do is follow instructions.

                        J 1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          In bed last night, I dreamt a wonderful improvement to the design of some software I'm working on. It would clean it up, move the code into it's appropriate classes, make it all beautiful. So I have just coded it. Or at least, I coded 3/4 of it. That was the point when I thought "Hang on a moment, you can't have abstract static methods in C#". :doh: Bugger. Note to self: don't listen to me when I'm sleepy. Anyone else done this? Constructed a massive edifice of beautiful code in your mind, only to find when you have got sufficient caffeine in your system that it has a fatal, fundamental, flaw?

                          Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

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

                          OriginalGriff wrote:

                          abstract static

                          OriginalGriff wrote:

                          Anyone else done this?

                          Yes, for exactly the same thing. Was such a perfect solution to the problem. Except that it wasn't. Obviously. I even still have the code in place, safely commented out, just to remind me.

                          cheers Chris Maunder

                          1 Reply Last reply
                          0
                          • OriginalGriffO OriginalGriff

                            In bed last night, I dreamt a wonderful improvement to the design of some software I'm working on. It would clean it up, move the code into it's appropriate classes, make it all beautiful. So I have just coded it. Or at least, I coded 3/4 of it. That was the point when I thought "Hang on a moment, you can't have abstract static methods in C#". :doh: Bugger. Note to self: don't listen to me when I'm sleepy. Anyone else done this? Constructed a massive edifice of beautiful code in your mind, only to find when you have got sufficient caffeine in your system that it has a fatal, fundamental, flaw?

                            Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                            P Offline
                            P Offline
                            Paulo Zemek
                            wrote on last edited by
                            #26

                            Make it more dynamic. Instead of static abstract, make it a static property of a delegate type.

                            1 Reply Last reply
                            0
                            • L Lost User

                              OriginalGriff wrote:

                              you can't have abstract static methods in C# this universe

                              P Offline
                              P Offline
                              Paulo Zemek
                              wrote on last edited by
                              #27

                              Delphi allowed virtual static methods... so I think it probably allowed abstract static methods too.

                              1 Reply Last reply
                              0
                              • OriginalGriffO OriginalGriff

                                In bed last night, I dreamt a wonderful improvement to the design of some software I'm working on. It would clean it up, move the code into it's appropriate classes, make it all beautiful. So I have just coded it. Or at least, I coded 3/4 of it. That was the point when I thought "Hang on a moment, you can't have abstract static methods in C#". :doh: Bugger. Note to self: don't listen to me when I'm sleepy. Anyone else done this? Constructed a massive edifice of beautiful code in your mind, only to find when you have got sufficient caffeine in your system that it has a fatal, fundamental, flaw?

                                Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                                H Offline
                                H Offline
                                HardikPatel SE
                                wrote on last edited by
                                #28

                                I also made that mistake once.... :laugh: :laugh: :laugh:

                                Hardik Patel

                                1 Reply Last reply
                                0
                                • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                                  If you started to dream of coding you have only two options - doctor or vacation...

                                  I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                                  K Offline
                                  K Offline
                                  kalberts
                                  wrote on last edited by
                                  #29

                                  Check your passport photo: The 1st law of passport photos: The more you look like your passport photo, the more you need vacation

                                  1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    harold aptroot wrote:

                                    no vptr

                                    Don't get hung up on how current languages are implemented. I too would like a language that allows static members in interfaces and abstracts. If a Bright compiler developer wanted to make this happen, I'm sure he could, it would likely have to be very different from current implementations. (It's way beyond my skills of course.)

                                    You'll never get very far if all you do is follow instructions.

                                    J Offline
                                    J Offline
                                    JimmyRopes
                                    wrote on last edited by
                                    #30

                                    very different from current implementations[^] :-D

                                    **_Once you lose your pride the rest is easy.

                                    I would agree with you but then we both would be wrong._**
                                    The report of my death was an exaggeration - Mark Twain Simply Elegant Designs JimmyRopes Designs
                                    I'm on-line therefore I am. JimmyRopes

                                    P P 2 Replies Last reply
                                    0
                                    • L Lost User

                                      0 times. I've wished that interfaces could contain static methods so that T.someFunction could exist for generics (constrained to that interface), but that's a completely separate issue. (that can't work in C# of course) How is "static virtual" even a reasonable concept? No instance = no vptr = no dynamic dispatch.

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

                                      I once coded a class function in C++ that calls realloc() or malloc(), based on whether "this" points to null. It then deletes this and returns This.

                                      L 1 Reply Last reply
                                      0
                                      • S SortaCore

                                        I once coded a class function in C++ that calls realloc() or malloc(), based on whether "this" points to null. It then deletes this and returns This.

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

                                        That's.. kind of dirty

                                        S 1 Reply Last reply
                                        0
                                        • L Lost User

                                          That's.. kind of dirty

                                          S Offline
                                          S Offline
                                          SortaCore
                                          wrote on last edited by
                                          #33

                                          Not only that, it calls _msize() on the this pointer and checks against another size parameter for the realloc. The last member in the class was a 0-byte array, for which the _msize() of the pointer minus size of other class members gave the array size.

                                          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