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 would you ever want to do this?

Why would you ever want to do this?

Scheduled Pinned Locked Moved The Lounge
question
19 Posts 15 Posters 1 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.
  • E Eytukan

    uopz_rename — Rename a function at runtime

    This is how framework bloats start to happen?

    Full Reset

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #3

    One of the reasons I refuse to work in Ruby. [Monkey-patching](http://www.virtuouscode.com/2008/02/23/why-monkeypatching-is-destroying-ruby/). Or this amusing what-if scenario:

    You can add methods right to core classes! You don’t have to call Time.now.advance(days: -1), you can write 1.day.ago! It makes Ruby a joy to read and write. Until…

    You hit weird bugs because a patch changed Hash.

    You get confused about which code actually ran, so you can’t debug it when it breaks.

    And you finally figure out that all your problems were caused six months ago, when you monkey-patched Enumerable to make one line of code five characters shorter.

    Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

    E E A 3 Replies Last reply
    0
    • M Marc Clifton

      One of the reasons I refuse to work in Ruby. [Monkey-patching](http://www.virtuouscode.com/2008/02/23/why-monkeypatching-is-destroying-ruby/). Or this amusing what-if scenario:

      You can add methods right to core classes! You don’t have to call Time.now.advance(days: -1), you can write 1.day.ago! It makes Ruby a joy to read and write. Until…

      You hit weird bugs because a patch changed Hash.

      You get confused about which code actually ran, so you can’t debug it when it breaks.

      And you finally figure out that all your problems were caused six months ago, when you monkey-patched Enumerable to make one line of code five characters shorter.

      Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

      E Offline
      E Offline
      Eric Lynch
      wrote on last edited by
      #4

      Yeah, Ruby is no gem :)

      1 Reply Last reply
      0
      • M Marc Clifton

        One of the reasons I refuse to work in Ruby. [Monkey-patching](http://www.virtuouscode.com/2008/02/23/why-monkeypatching-is-destroying-ruby/). Or this amusing what-if scenario:

        You can add methods right to core classes! You don’t have to call Time.now.advance(days: -1), you can write 1.day.ago! It makes Ruby a joy to read and write. Until…

        You hit weird bugs because a patch changed Hash.

        You get confused about which code actually ran, so you can’t debug it when it breaks.

        And you finally figure out that all your problems were caused six months ago, when you monkey-patched Enumerable to make one line of code five characters shorter.

        Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

        E Offline
        E Offline
        Eytukan
        wrote on last edited by
        #5

        I think I would never prefer to work with languages like these, without any law & order. :)

        Full Reset

        1 Reply Last reply
        0
        • E Eytukan

          uopz_rename — Rename a function at runtime

          This is how framework bloats start to happen?

          Full Reset

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

          wow! you could rename everything to make your code look better... make it look just like, say, visual basic how cool would that be? :vomit: damn! gosh darn it! there's no vomit emoji!

          Message Signature (Click to edit ->)

          Richard DeemingR 1 Reply Last reply
          0
          • E Eytukan

            uopz_rename — Rename a function at runtime

            This is how framework bloats start to happen?

            Full Reset

            C Offline
            C Offline
            CodeWraith
            wrote on last edited by
            #7

            If I remember right, PHP did not have anything like namespaces. I think this was their grand alternative to solving name collision. Just what I would expect from guys playing around with a badly thought through interpreter.

            I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

            E 1 Reply Last reply
            0
            • L Lost User

              wow! you could rename everything to make your code look better... make it look just like, say, visual basic how cool would that be? :vomit: damn! gosh darn it! there's no vomit emoji!

              Message Signature (Click to edit ->)

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

              Lopatir wrote:

              there's no vomit emoji!

              This one comes close: X| Failing that, either 🤮 or 🤢 would do the trick.


              "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
              • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                Maybe to write your own strlen...

                "The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge". Stephen Hawking, 1942- 2018

                W Offline
                W Offline
                W Balboos GHB
                wrote on last edited by
                #9

                Although in some strange realm that may be something one needs to do, if one were writing their own strlen(...), would it not be better to give it its own name, too? Or maybe create some weird-ass overload if the language permits it? On the other hand, if it's scope is wide enough, think of the fun you could have with other members of some team when their code goes insane for no discernible reason.

                Ravings en masse^

                "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

                "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

                1 Reply Last reply
                0
                • E Eytukan

                  uopz_rename — Rename a function at runtime

                  This is how framework bloats start to happen?

                  Full Reset

                  F Offline
                  F Offline
                  F ES Sitecore
                  wrote on last edited by
                  #10

                  Imagine the pranks you could pull on your coworkers :laugh:

                  D 1 Reply Last reply
                  0
                  • F F ES Sitecore

                    Imagine the pranks you could pull on your coworkers :laugh:

                    D Offline
                    D Offline
                    dandy72
                    wrote on last edited by
                    #11

                    Anyone caught doing that is just begging for a bigger workload.

                    1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      Lopatir wrote:

                      there's no vomit emoji!

                      This one comes close: X| Failing that, either 🤮 or 🤢 would do the trick.


                      "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
                      dandy72
                      wrote on last edited by
                      #12

                      Richard Deeming wrote:

                      Failing that, either 🤮 or 🤢 would do the trick.

                      Well, apparently no, they won't do the trick....

                      1 Reply Last reply
                      0
                      • E Eytukan

                        uopz_rename — Rename a function at runtime

                        This is how framework bloats start to happen?

                        Full Reset

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

                        Someone told me that in Forth, every token is a symbol of a defined value. So you may define 3.14159 to have the value 3.0. Or to have the symbol 3 have the value 17. I never programmed in Forth, so I never tested out if this is true. If it is ... In spite of JavaScript, Forth, Python, Java and whathaveyou of late, later and latest binding languages: I still love those languages that are "You know what you get". Compile-time, static, reliable languages!

                        1 Reply Last reply
                        0
                        • E Eytukan

                          uopz_rename — Rename a function at runtime

                          This is how framework bloats start to happen?

                          Full Reset

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

                          What do you achieve that is different from an "override" or something as primitive as providing a subclass implementation of a virtual function? Once you let the cats loose, you loose control of them. You can't say "Define your own functions by providing implementation of virtual functions, but in no other way!" Once you have opened the cage, they run loose. There is not that much difference between providing an alternate virtual function definition from replacing one real function definition by another one.

                          1 Reply Last reply
                          0
                          • E Eytukan

                            uopz_rename — Rename a function at runtime

                            This is how framework bloats start to happen?

                            Full Reset

                            D Offline
                            D Offline
                            Daniel Pfeffer
                            wrote on last edited by
                            #15

                            Perhaps because I want to use the name for something else. For example: // is 'name' a strong lender? bool strlen( char const* name);

                            Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                            1 Reply Last reply
                            0
                            • C CodeWraith

                              If I remember right, PHP did not have anything like namespaces. I think this was their grand alternative to solving name collision. Just what I would expect from guys playing around with a badly thought through interpreter.

                              I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                              E Offline
                              E Offline
                              Eytukan
                              wrote on last edited by
                              #16

                              :thumbsup:

                              Full Reset

                              1 Reply Last reply
                              0
                              • E Eytukan

                                uopz_rename — Rename a function at runtime

                                This is how framework bloats start to happen?

                                Full Reset

                                J Offline
                                J Offline
                                Jimmytehbanana
                                wrote on last edited by
                                #17

                                Maybe not this specific example, but you could use it in testing (similar to monkey patching functions for unit tests in other languages). I’d never recommend using monkey patching in production code. It is helpful in unit testing though to patch functions outside the unit or to patch database access functions during unit testing. This is, of course, provided you unpatch the function at the end of the test. Not too sure if PHP has a defer mechanism for unpatching when the function is no longer in scope, but that is one way to test a single unit and have predictable interactions with external code (an external call to the unit fails, returns weird data, returns expected data, etc).

                                Sr. Software Engineer Go, Java, Python, Bash, Docker https://c2technology.net

                                1 Reply Last reply
                                0
                                • M Marc Clifton

                                  One of the reasons I refuse to work in Ruby. [Monkey-patching](http://www.virtuouscode.com/2008/02/23/why-monkeypatching-is-destroying-ruby/). Or this amusing what-if scenario:

                                  You can add methods right to core classes! You don’t have to call Time.now.advance(days: -1), you can write 1.day.ago! It makes Ruby a joy to read and write. Until…

                                  You hit weird bugs because a patch changed Hash.

                                  You get confused about which code actually ran, so you can’t debug it when it breaks.

                                  And you finally figure out that all your problems were caused six months ago, when you monkey-patched Enumerable to make one line of code five characters shorter.

                                  Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                                  A Offline
                                  A Offline
                                  Andre Pereira
                                  wrote on last edited by
                                  #18

                                  That example perfectly encapsulates one of the issues of modern programming languages. History repeats itself, as programmers in the 90's mistook less lines of code, with obfuscated one-liners. Now the line's not obfuscated, but you're still sacrificing so much... for a few lines of code. Never again, learn from history.

                                  1 Reply Last reply
                                  0
                                  • E Eytukan

                                    uopz_rename — Rename a function at runtime

                                    This is how framework bloats start to happen?

                                    Full Reset

                                    H Offline
                                    H Offline
                                    hpcoder2
                                    wrote on last edited by
                                    #19

                                    In answer to the original question, I have needed to do this in TCL, for example redefining exit to check whether the work has been saved and put up a dialog box if not, before calling out to the original function which gets renamed "tcl_exit". Of course, destructors are a better solution to this problem, but not many languages have those :)

                                    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