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. Python and Option Explicit

Python and Option Explicit

Scheduled Pinned Locked Moved The Lounge
c++pythonquestion
24 Posts 14 Posters 2 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 den2k88

    Please someone adds an Option Explicit to Python. The fact that something like this is even conceivable, let alone valid, is atrocious:

    class Empty:
    pass

    Empty.completelyNewAttribute = "seriously?" # adds a class member

    obj = Empty()
    obj.randomTypo = 10 # adds an instance member only to obj

    Every new programmer makes fun of C++ for being unnecessarily hard to use but I think that a language like Python, with all the possible ways it enables programmers to shoot themselves, is 10 times harder than C++. And yes, my opinion that Python is VB with different clothes is only becoming stronger. Ugh.

    GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

    S Offline
    S Offline
    Slacker007
    wrote on last edited by
    #2

    when I see code statements like goto and option explicit, I run in the opposite direction.

    den2k88 wrote:

    with all the possible ways it enables programmers to shoot themselves

    I honestly think that is the objective (thinning the herd). :sigh:

    den2k88 wrote:

    Every new programmer makes fun of C++

    What is funny about this is that most of the software these "new programmers" run, was written partly or mostly in C++. Inconceivable! :laugh:

    D O T 3 Replies Last reply
    0
    • S Slacker007

      when I see code statements like goto and option explicit, I run in the opposite direction.

      den2k88 wrote:

      with all the possible ways it enables programmers to shoot themselves

      I honestly think that is the objective (thinning the herd). :sigh:

      den2k88 wrote:

      Every new programmer makes fun of C++

      What is funny about this is that most of the software these "new programmers" run, was written partly or mostly in C++. Inconceivable! :laugh:

      D Offline
      D Offline
      den2k88
      wrote on last edited by
      #3

      Slacker007 wrote:

      I honestly think that is the objective (thinning the herd). :sigh:

      I like the way you think. I work in embedded so the my particular herd is already very thin :D

      GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

      1 Reply Last reply
      0
      • D den2k88

        Please someone adds an Option Explicit to Python. The fact that something like this is even conceivable, let alone valid, is atrocious:

        class Empty:
        pass

        Empty.completelyNewAttribute = "seriously?" # adds a class member

        obj = Empty()
        obj.randomTypo = 10 # adds an instance member only to obj

        Every new programmer makes fun of C++ for being unnecessarily hard to use but I think that a language like Python, with all the possible ways it enables programmers to shoot themselves, is 10 times harder than C++. And yes, my opinion that Python is VB with different clothes is only becoming stronger. Ugh.

        GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

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

        You do understand that Python was named in honour of "Monty Python's Flying Circus" (where chaos and madness were the norm)?

        D S 2 Replies Last reply
        0
        • D den2k88

          Please someone adds an Option Explicit to Python. The fact that something like this is even conceivable, let alone valid, is atrocious:

          class Empty:
          pass

          Empty.completelyNewAttribute = "seriously?" # adds a class member

          obj = Empty()
          obj.randomTypo = 10 # adds an instance member only to obj

          Every new programmer makes fun of C++ for being unnecessarily hard to use but I think that a language like Python, with all the possible ways it enables programmers to shoot themselves, is 10 times harder than C++. And yes, my opinion that Python is VB with different clothes is only becoming stronger. Ugh.

          GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #5

          den2k88 wrote:

          I think that a language like Python...is 10 times harder than C++.

          I tried it for a few weeks but found it extremely hard to understand. I'll stick with C++ and Java.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          L D 2 Replies Last reply
          0
          • D David Crow

            den2k88 wrote:

            I think that a language like Python...is 10 times harder than C++.

            I tried it for a few weeks but found it extremely hard to understand. I'll stick with C++ and Java.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

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

            There are some slightly weird things you need to get your head round. Once you 'get' those things it really is quite an easy language to use.

            1 Reply Last reply
            0
            • S Slacker007

              when I see code statements like goto and option explicit, I run in the opposite direction.

              den2k88 wrote:

              with all the possible ways it enables programmers to shoot themselves

              I honestly think that is the objective (thinning the herd). :sigh:

              den2k88 wrote:

              Every new programmer makes fun of C++

              What is funny about this is that most of the software these "new programmers" run, was written partly or mostly in C++. Inconceivable! :laugh:

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

              Goto is an issue. Option Explicit is the programmer telling you how they're handling variables.

              S 1 Reply Last reply
              0
              • O obermd

                Goto is an issue. Option Explicit is the programmer telling you how they're handling variables.

                S Offline
                S Offline
                Slacker007
                wrote on last edited by
                #8

                obermd wrote:

                Option Explicit is the programmer telling you how they're handling variables.

                and that is supposed to make me feel more comfortable with it? :laugh: :laugh: :thumbsdown:

                O 1 Reply Last reply
                0
                • D den2k88

                  Please someone adds an Option Explicit to Python. The fact that something like this is even conceivable, let alone valid, is atrocious:

                  class Empty:
                  pass

                  Empty.completelyNewAttribute = "seriously?" # adds a class member

                  obj = Empty()
                  obj.randomTypo = 10 # adds an instance member only to obj

                  Every new programmer makes fun of C++ for being unnecessarily hard to use but I think that a language like Python, with all the possible ways it enables programmers to shoot themselves, is 10 times harder than C++. And yes, my opinion that Python is VB with different clothes is only becoming stronger. Ugh.

                  GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

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

                  Once you realize that objects are just dictionaries, and everything is an object, it all makes a lot more sense, but one does have to understand that there is a difference between an object's dictionary and an object's instance dictionary. :-D

                  Latest Articles:
                  ASP.NET Core Web API: Plugin Controllers and Services

                  D 1 Reply Last reply
                  0
                  • L Lost User

                    You do understand that Python was named in honour of "Monty Python's Flying Circus" (where chaos and madness were the norm)?

                    D Offline
                    D Offline
                    den2k88
                    wrote on last edited by
                    #10

                    Albatross!

                    GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                    1 Reply Last reply
                    0
                    • M Marc Clifton

                      Once you realize that objects are just dictionaries, and everything is an object, it all makes a lot more sense, but one does have to understand that there is a difference between an object's dictionary and an object's instance dictionary. :-D

                      Latest Articles:
                      ASP.NET Core Web API: Plugin Controllers and Services

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

                      That's the big gotcha indeed, it takes a while. Also scopes are dictionaries, everything is public, every line of code is executed, every method is static... and an object.

                      GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                      1 Reply Last reply
                      0
                      • D David Crow

                        den2k88 wrote:

                        I think that a language like Python...is 10 times harder than C++.

                        I tried it for a few weeks but found it extremely hard to understand. I'll stick with C++ and Java.

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                        D Offline
                        D Offline
                        den2k88
                        wrote on last edited by
                        #12

                        It's quirky. As I'm more and more convinced, it's VisualBasic all over again (they do share birth year, by the way). It's useful to automate random stuff, it's single thread, it has a strong support for binary calling and a nice quick graphic interface whose logic is 1:1 that of Windows. In my company we will probably start using Python for automated testing and data analysis so we will need to learn it; I do find myself in need of a quick GUI to link to my Serial / MODBUS / LIN libraries to prod and test our products; we also have a self improvement program that makes us choose courses to follow during the year. Given all of the above, the decent multiplatformity (is that even a word?) of Python and its ubiquity it makes for me a good choice.

                        GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                        1 Reply Last reply
                        0
                        • D den2k88

                          Please someone adds an Option Explicit to Python. The fact that something like this is even conceivable, let alone valid, is atrocious:

                          class Empty:
                          pass

                          Empty.completelyNewAttribute = "seriously?" # adds a class member

                          obj = Empty()
                          obj.randomTypo = 10 # adds an instance member only to obj

                          Every new programmer makes fun of C++ for being unnecessarily hard to use but I think that a language like Python, with all the possible ways it enables programmers to shoot themselves, is 10 times harder than C++. And yes, my opinion that Python is VB with different clothes is only becoming stronger. Ugh.

                          GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                          E Offline
                          E Offline
                          englebart
                          wrote on last edited by
                          #13

                          Remember when people complained about C, so someone came up with lint? Guess what? pylint.org 😊

                          D 1 Reply Last reply
                          0
                          • E englebart

                            Remember when people complained about C, so someone came up with lint? Guess what? pylint.org 😊

                            D Offline
                            D Offline
                            den2k88
                            wrote on last edited by
                            #14

                            Lint... the only tool that can take a perfectly readable piece of code and make a total mess out of it. I wonder what damages it can do with Python.

                            GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                            1 Reply Last reply
                            0
                            • D den2k88

                              Please someone adds an Option Explicit to Python. The fact that something like this is even conceivable, let alone valid, is atrocious:

                              class Empty:
                              pass

                              Empty.completelyNewAttribute = "seriously?" # adds a class member

                              obj = Empty()
                              obj.randomTypo = 10 # adds an instance member only to obj

                              Every new programmer makes fun of C++ for being unnecessarily hard to use but I think that a language like Python, with all the possible ways it enables programmers to shoot themselves, is 10 times harder than C++. And yes, my opinion that Python is VB with different clothes is only becoming stronger. Ugh.

                              GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                              U Offline
                              U Offline
                              User 14068359
                              wrote on last edited by
                              #15

                              I think what you're looking for are __slots__

                              class Empty:
                              __slots__ = ('completelyNewAttribute',)

                              Empty.completelyNewAttribute = "seriously?" # adds a class member

                              obj = Empty()
                              obj.randomTypo = 10 # raises AttributeError: 'Empty' object has no attribute 'randomTypo'

                              D 1 Reply Last reply
                              0
                              • U User 14068359

                                I think what you're looking for are __slots__

                                class Empty:
                                __slots__ = ('completelyNewAttribute',)

                                Empty.completelyNewAttribute = "seriously?" # adds a class member

                                obj = Empty()
                                obj.randomTypo = 10 # raises AttributeError: 'Empty' object has no attribute 'randomTypo'

                                D Offline
                                D Offline
                                den2k88
                                wrote on last edited by
                                #16

                                Thank you!

                                GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                                1 Reply Last reply
                                0
                                • D den2k88

                                  Please someone adds an Option Explicit to Python. The fact that something like this is even conceivable, let alone valid, is atrocious:

                                  class Empty:
                                  pass

                                  Empty.completelyNewAttribute = "seriously?" # adds a class member

                                  obj = Empty()
                                  obj.randomTypo = 10 # adds an instance member only to obj

                                  Every new programmer makes fun of C++ for being unnecessarily hard to use but I think that a language like Python, with all the possible ways it enables programmers to shoot themselves, is 10 times harder than C++. And yes, my opinion that Python is VB with different clothes is only becoming stronger. Ugh.

                                  GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                                  J Offline
                                  J Offline
                                  Jeff Laing
                                  wrote on last edited by
                                  #17

                                  read up on __slots__ 3. Data model — Python 3.10.2 documentation[^]

                                  1 Reply Last reply
                                  0
                                  • D den2k88

                                    Please someone adds an Option Explicit to Python. The fact that something like this is even conceivable, let alone valid, is atrocious:

                                    class Empty:
                                    pass

                                    Empty.completelyNewAttribute = "seriously?" # adds a class member

                                    obj = Empty()
                                    obj.randomTypo = 10 # adds an instance member only to obj

                                    Every new programmer makes fun of C++ for being unnecessarily hard to use but I think that a language like Python, with all the possible ways it enables programmers to shoot themselves, is 10 times harder than C++. And yes, my opinion that Python is VB with different clothes is only becoming stronger. Ugh.

                                    GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                                    J Offline
                                    J Offline
                                    JohanDuPlessisAtGMail
                                    wrote on last edited by
                                    #18

                                    No! It is about the right tool for the job.I love C++, Java, SQL and Python but all of them require different ways of thinking and is for solving different problems. If you approach Python like C++ it will frustrate you to no end. However, for the right problem Python is an absolute blast to use! If you need to get something done quickly, with lots of uncertainty and you have the opportunity to iterate Python is amazing. I love it when you can work with an interface/dataset which you only need a small portion of and you don't have to define and type the stuff you are not interested (which happens a LOT in the data world). Of course lots of people hate that uncertainty and would love for everything they work with to be 100% defined, but defining something 100% of which you only use 10% is literally a waste of time. Of course that depends on context. If you deal with transactional banking you want everything defined 100% and I will stick to Java/C++. If you are trying to extract value from an enterprise data lake quickly where you don't know all the data, will have no opportunity to know all the data then using Python for ML and other purposes is awesome.

                                    D 1 Reply Last reply
                                    0
                                    • J JohanDuPlessisAtGMail

                                      No! It is about the right tool for the job.I love C++, Java, SQL and Python but all of them require different ways of thinking and is for solving different problems. If you approach Python like C++ it will frustrate you to no end. However, for the right problem Python is an absolute blast to use! If you need to get something done quickly, with lots of uncertainty and you have the opportunity to iterate Python is amazing. I love it when you can work with an interface/dataset which you only need a small portion of and you don't have to define and type the stuff you are not interested (which happens a LOT in the data world). Of course lots of people hate that uncertainty and would love for everything they work with to be 100% defined, but defining something 100% of which you only use 10% is literally a waste of time. Of course that depends on context. If you deal with transactional banking you want everything defined 100% and I will stick to Java/C++. If you are trying to extract value from an enterprise data lake quickly where you don't know all the data, will have no opportunity to know all the data then using Python for ML and other purposes is awesome.

                                      D Offline
                                      D Offline
                                      den2k88
                                      wrote on last edited by
                                      #19

                                      Of course. I loved VB6 for its intended use and it had the following nigthmares

                                      Option Base 1
                                      Option Compare Text
                                      Option Explicit ' The issue is that it's not the default so it is actually like Python
                                      On Error Resume Next

                                      Dim variable as Variant

                                      I know where it comes from and what it is meant to do, I think it is awesome with its extensive standard library. I need it to automate stuff and talk to libraries while showing a minimal UI for expert users. So, the same as VB but portable and still maintained.

                                      GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                                      1 Reply Last reply
                                      0
                                      • S Slacker007

                                        obermd wrote:

                                        Option Explicit is the programmer telling you how they're handling variables.

                                        and that is supposed to make me feel more comfortable with it? :laugh: :laugh: :thumbsdown:

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

                                        Would you rather see an option explicit or wonder what the result of var sum = "6" + 6 is? Option explicit prevents the confusion.

                                        1 Reply Last reply
                                        0
                                        • L Lost User

                                          You do understand that Python was named in honour of "Monty Python's Flying Circus" (where chaos and madness were the norm)?

                                          S Offline
                                          S Offline
                                          scedastic
                                          wrote on last edited by
                                          #21

                                          That's what I keep telling people, especially when I see the logo of 2 intertwined snakes. :sigh:

                                          What's faster: the speed of light or the speed of dark?

                                          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