Suggest appropriate goals for a super-basic Python class (HS level)
-
@Zecc said in Suggest appropriate goals for a super-basic Python class (HS level):
@dfdub said in Suggest appropriate goals for a super-basic Python class (HS level):
dependency inversion
We no longer call it that. (inb4 "who's 'we'?")
"Dependency injection" is a better name.
Actually, "Dependency Injection" (both Constructor injection and Property injection) is simply one method of achieving "Dependency Inversion".....
-
@mikehurley said in Suggest appropriate goals for a super-basic Python class (HS level):
I think the biggest thing that bothered me about Typescript was it didn't fix how "this" is handled.
I think that's a single aspect of the larger problem with Typescript: it's designed as a superset of JavaScript, rather than an independent language that compiles down to JavaScript, and so is forced to inherit all of its flaws. (This same phenomenon is at the core of many of the problems with C++.)
-
@mikehurley said in Suggest appropriate goals for a super-basic Python class (HS level):
@hungrier said in Suggest appropriate goals for a super-basic Python class (HS level):
@mikehurley said in Suggest appropriate goals for a super-basic Python class (HS level):
The problem with Typescript's typing is that it's not required. You can write plain old Javascript in your Typescript and that's valid.
That's kind of true, in the sense that it all compiles down to Javascript eventually, and you can mark things with
any
which tells the compiler to ignore any type issues with that variable. But in general it'll highlight errors and warnings and fail to compile if you've done something wrong.I think the biggest thing that bothered me about Typescript was it didn't fix how "this" is handled.
When I used it (which I happened to mention the other day),
this
inside an arrow function would get aliased and behave the way you would expect, while regularfunction ()
functions would retain the normal Javascript behaviour.
-
@_P_ said in Suggest appropriate goals for a super-basic Python class (HS level):
Did you know that since Python 3.5 there's a
typing
module that provides type hints? If you don't want dynamic typing Python, use it.Yeah. The operable word there is "hints." It still won't error out at compile time if you try to pass a string to something expecting an int, because... well... for a lot of reasons, beginning with the fact that there is no compile-time. Type hints make it easier for IDEs to keep track of what you're doing, but an actual static type system they are not.
-
@dkf said in Suggest appropriate goals for a super-basic Python class (HS level):
Without the type system being Turing-complete, there's always going to be (many!) properties of the program that it can't reason about.
I'm not saying that we should adopt Scala's type system everywhere, but at least ad-hoc union types and ADTs should be more common. Sometimes, introducing an interface just isn't the right choice for your problem, and I always end up needing one of the two or both in languages that don't provide them.
-
@mikehurley said in Suggest appropriate goals for a super-basic Python class (HS level):
My understanding is the type hints in python 3 are only suggestions.
By default, yes, but you can consistently use them and then run
mypy
(a static type checker) on your code during the build.@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
Yeah. The operable word there is "hints." It still won't error out at compile time if you try to pass a string to something expecting an int, because... well... for a lot of reasons, beginning with the fact that there is no compile-time. Type hints make it easier for IDEs to keep track of what you're doing, but an actual static type system they are not.
See above. If you're building a Python package, you can simply add
mypy
to the build process and have static type checking.
-
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
@pie_flavor And why is dynamic polymorphism useful? Because it's so incredibly helpful in managing complexity.
But a particular kind of complexity. Which would otherwise be the solution to a particular kind of problem. It's not a tool for managing complexity in general, and certainly not the kind of complexity you'd find in a class for absolute beginners.
-
@Carnage said in Suggest appropriate goals for a super-basic Python class (HS level):
Interfaces for things with only one implementation
That's one of the reasons I really love Dart. Every class is also an interface, and you can implement it instead of extend it, so you can just expose your class instead of writing an interface and exposing it instead.
-
@mikehurley said in Suggest appropriate goals for a super-basic Python class (HS level):
My understanding is the type hints in python 3 are only suggestions.
This. Nobody cares if you can hint that something is supposed to be this type or that. Static analysis can only be so useful. This is why C#'s nullable reference types are next to useless while Kotlin's are so powerful - a null being passed to a nonnullable type in Kotlin instantly throws rather than an invalid value sinking deeper into your object hierarchy. Same reason JS blows in a way nothing else does - producing
undefined
for an invalid access rather than erroring out is the worst possible behavior for a language to have.
-
@pie_flavor That brings up another thing worth considering: a lot of the s in JavaScript stem from the fact that "the by-design purpose of JavaScript was to make the monkey dance when you moused over it."
It was designed to make very simple things easy to accomplish for non-technical people. Webpages began to outgrow that simplistic level of complexity almost immediately, and we've been dealing with the resulting headaches for over 2 decades now. In a lot of ways, Python seems like another language that was designed to make things easy for non-programmers, and it shares a lot of the same problems.
Philosophical question: is it really a good idea to make programming languages that make it easy for non-coders to code?
-
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
Philosophical question: is it really a good idea to make programming languages that make it easy for non-coders to code?
Either yes, because it lets users do useful things with the computer beyond just clicking in web forms by hand, or no, because it lets some monstrous abominations grow. Yet is the cost of stopping that, of effectively restricting programming to a High Priesthood of the Machine God, is that worthwhile? My fundamental intuition says “no, that's the worst option”.
Doesn't mean that Javascript is good.
-
@dkf said in Suggest appropriate goals for a super-basic Python class (HS level):
Yet is the cost of stopping that, of effectively restricting programming to a High Priesthood of the Machine God, is that worthwhile?
Reframed from a different perspective: in every other branch of engineering, we have professional standards backed by licensing and/or certification requirements to ensure some degree of competence. Software development is unique in that regard. It's also unique in how often its designs catastrophically fail; hacks and serious crashes happen far more often than, say, bridges collapsing, buildings collapsing, or car companies producing Pintos.
We have a "High Priesthood of the Machine God" in the design of actual machines, which tend to be orders of magnitude less complex in terms of "moving parts" than modern software... and it turns out to be a system that works pretty well. Would it truly be a bad thing, on balance, to apply similar principles to software?
-
@Mason_Wheeler That would be a horrible idea. None of the other kinds of engineering are publishable on a broad scale without any kind of resources - you can hardly have a civil engineering hackathon, at least not one where the final product is ready to use. This is important because software would not be what it is were open-source communities not so freely available. Many people use my programs for things that make them money, and if I had to get them certified and licensed I wouldn't be able to do it. Yet most of the massive breaches come from services that too are offered for free; how can you divide between them?
Also, points of failure in other engineering are environmental in nature. It must be able to withstand this weight, this pressure, etc. Software engineering is breached by people specifically trying to breach it, which you can't apply a uniform set of stress-tests for.
-
@pie_flavor Yes, that's certainly a valid point of view, although as 3D printing technology becomes more mature and more mainstream, the statement that "none of the other kinds of engineering are publishable on a broad scale without any kind of resources" becomes less true. What's a good way to deal with the issues that that's already beginning to cause?
-
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
@dkf said in Suggest appropriate goals for a super-basic Python class (HS level):
Yet is the cost of stopping that, of effectively restricting programming to a High Priesthood of the Machine God, is that worthwhile?
Reframed from a different perspective: in every other branch of engineering, we have professional standards backed by licensing and/or certification requirements to ensure some degree of competence. Software development is unique in that regard. It's also unique in how often its designs catastrophically fail; hacks and serious crashes happen far more often than, say, bridges collapsing, buildings collapsing, or car companies producing Pintos.
We have a "High Priesthood of the Machine God" in the design of actual machines, which tend to be orders of magnitude less complex in terms of "moving parts" than modern software... and it turns out to be a system that works pretty well. Would it truly be a bad thing, on balance, to apply similar principles to software?
While there are professional standards for an Engineer. Nothing stops me from tinkering in my garage and offering (selling) those gadgets that I have created to others.
-
@pie_flavor said in Suggest appropriate goals for a super-basic Python class (HS level):
Software engineering is breached by people specifically trying to breach it, which you can't apply a uniform set of stress-tests for.
Yes, that's one failure mode. It also fails under load or under legitimate use cases that amateur designers failed to to anticipate, just like other engineering projects.
-
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
@dkf said in Suggest appropriate goals for a super-basic Python class (HS level):
Yet is the cost of stopping that, of effectively restricting programming to a High Priesthood of the Machine God, is that worthwhile?
Reframed from a different perspective: in every other branch of engineering, we have professional standards backed by licensing and/or certification requirements to ensure some degree of competence. Software development is unique in that regard. It's also unique in how often its designs catastrophically fail; hacks and serious crashes happen far more often than, say, bridges collapsing, buildings collapsing, or car companies producing Pintos.
We have a "High Priesthood of the Machine God" in the design of actual machines, which tend to be orders of magnitude less complex in terms of "moving parts" than modern software... and it turns out to be a system that works pretty well. Would it truly be a bad thing, on balance, to apply similar principles to software?
In pretty much every other branch of engineering, it's perfectly ok for the home gamer to build whatever they damn please in the comfort of their own empire of dirt. People without degrees or licenses are allowed to build cars from scratch if they so please. Or houses. Or a lot of other things.
Why should we limit programming in ways that we do not limit other branches of engineering?
-
@Carnage said in Suggest appropriate goals for a super-basic Python class (HS level):
People without degrees or licenses are allowed to build cars from scratch if they so please.
But you can't drive them in public if they don't meet very strict and specific requirements.
Or houses.
...which will get you in trouble if they're not up to code.
You literally just named two of the most significant sectors in which legal competence requirements do exist.
-
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
You literally just named two of the most significant sectors in which legal competence requirements do exist.
They have to meet the code standards for that application, but nothing says they have to be an engineer to do it.
-
@Dragoon ...which is still way ahead of what we have for software.
-
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
@Carnage said in Suggest appropriate goals for a super-basic Python class (HS level):
People without degrees or licenses are allowed to build cars from scratch if they so please.
But you can't drive them in public if they don't meet very strict and specific requirements.
No licenses required, no education required.
And really, getting a one off approved for public roads is not particularly hard. Once I get enough money to buy myself a proper shop, I'm planning to build myself both a car and a motorcycle.Or houses.
...which will get you in trouble if they're not up to code.
You literally just named two of the most significant sectors in which legal competence requirements do exist.
And you're still allowed to do it without having a license.
Granted, in the case of a house, no insurance company will ever insure you unless you've gotten the wiring inspected and given the thumbs up by a licensed electrician, and wet spaces need to be up to craftsman quality, but you are allowed to do both.
-
Regarding the teach or not OOP, I would say that by the students initial level they will not reach a point in this course when some formal OOP would make sense, and probably there's no need for them to write their own clases.
Still, they could be familiarized with the underlying ideas and motivation.
-
let them use strings and lists. The idea of data plus methods will turn natural
-
when functions growth too much, lets they train on breaking in smaller functions
-
When lines of code and confusion goes up, introduce modules. Show how moving functions related to a 'theme', helps to better understand and navigate the projects
-
is only natural to move symbols used only by a module from the global space to the module, and why it is a good idea
They will learn good practices, and if later (other course or whatever) they need to use Classes, the distance of what they know and handle to what they will need is reduced.
My 2cents.
-
-
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
in every other branch of engineering, we have professional standards backed by licensing and/or certification requirements to ensure some degree of competence. Software development is unique in that regard.
Not really. On the hardware side of things, as an EE, I don't have any sort of professional license or certification. The ME who designed your tool-free ATX mini-tower case probably doesn't have one, either. Chances are most of the MEs working for Ford, GM, Toyota, or whoever don't, although possibly the Chief Engineers do.
Such certification is most common in the fields of Civil, Structural, Aeronautical, large-scale Electrical (power generation and distribution), perhaps Chemical Engineering — large-scale, safety-critical projects. However, even in those fields, one can work as an employee without being personally licensed or certified, as long as one is not the project head making the final approval of and taking responsibility for the plans, nor doing services as a consultant for anyone outside your company.
Jurisdictions vary widely in their requirements, and the statements above are generally true in the US, but details differ between states. Other countries may have completely different requirements.
-
@HardwareGeek Again, that's still a significantly higher standard than software is held to.
-
@Carnage said in Suggest appropriate goals for a super-basic Python class (HS level):
Granted, in the case of a house, no insurance company will ever insure you unless you've gotten the wiring inspected and given the thumbs up by a licensed electrician, and wet spaces need to be up to craftsman quality, but you are allowed to do both.
And in most, if not all, jurisdictions (in the US, anyway; I don't know anything about other countries), before you even start, you have to get permits from the city or county Building Department, which requires having plans approved by a Department engineer. So even if you're not a licensed electrician, plumber or whatever, someone who is has to approve.
-
@Mason_Wheeler I think my point kind of got lost in the description of fields that do require licensure.
Consumer and small commercial electronics don't. At all. I'm reasonably sure I've never in my career worked for a company that employed a licensed Professional Engineer.
-
@dkf said in Suggest appropriate goals for a super-basic Python class (HS level):
@_P_ said in Suggest appropriate goals for a super-basic Python class (HS level):
@dkf said in Suggest appropriate goals for a super-basic Python class (HS level):
The worst misfeatures of Python's classes are mitigated by defining
__slots__
on every class you create (where possible).I think you're using Python .
I knew someone would bring that up.
Let's just say that I disagree, based on both performance data and ease of support for users.
I'm reading this StackOverflow answer about
__slots__
:It looks like all the caveats are exactly the same you'd get from the Java-like class OO designs, and the suggested "workaround" is also exactly the same thing you'd do in languages like Java (using
ABC
to create abstract classes that do nothing and inherit from it). So besides performance and memory optimization, it basically turns Python into what it sought to destroy? Also, IMO, if someone's looking for those things (tight space and good performance), Python is not the language for that.
-
@HardwareGeek said in Suggest appropriate goals for a super-basic Python class (HS level):
@Carnage said in Suggest appropriate goals for a super-basic Python class (HS level):
Granted, in the case of a house, no insurance company will ever insure you unless you've gotten the wiring inspected and given the thumbs up by a licensed electrician, and wet spaces need to be up to craftsman quality, but you are allowed to do both.
And in most, if not all, jurisdictions (in the US, anyway; I don't know anything about other countries), before you even start, you have to get permits from the city or county Building Department, which requires having plans approved by a Department engineer. So even if you're not a licensed electrician, plumber or whatever, someone who is has to approve.
In Sweden, this depends on what size of house you plan on building, where the property is situated and what's already built on the property. There are two kinds of permits, one that's basically notifying that you plan on building and a bureaucrat just rubber stamps more or less, and then there is the full building permit where it needs to check all the boxes and not piss off anyone in particular.
And you might not need either of them, depending on what you plan to build.
-
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
@HardwareGeek Again, that's still a significantly higher standard than software is held to.
Not really. Safety critical software (e.g., in avionics or railway signalling) is most definitely held to much higher requirements. Most software is not safety critical; people only die when a mapping app fails if they're also seriously stupid, and it is the stupid that kills them and not the software failure. It takes a truly contorted situation for people to die as a direct result of a web login page not working right (without the core problem being elsewhere)…
-
@_P_ said in Suggest appropriate goals for a super-basic Python class (HS level):
Also, IMO, if someone's looking for those things (tight space and good performance), Python is not the language for that.
Without knowing the whole of the application, you can't begin to evaluate that judgement usefully.
The core problem is that Python's basic hash table implementation is not exactly fast even by the standards of dynamic programming languages. This matters because it's precisely what makes doing everything dynamically so expensive in terms of time. (Slots work by binding field accesses to indexes into an array of variables. They're a problem because there is a single such array per concrete class.) Other programming languages have solutions for this, but I don't know that they could possibly be applied to Python's execution model…
-
@dkf said in Suggest appropriate goals for a super-basic Python class (HS level):
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
@HardwareGeek Again, that's still a significantly higher standard than software is held to.
Not really. Safety critical software (e.g., in avionics or railway signalling) is most definitely held to much higher requirements. Most software is not safety critical; people only die when a mapping app fails if they're also seriously stupid, and it is the stupid that kills them and not the software failure. It takes a truly contorted situation for people to die as a direct result of a web login page not working right (without the core problem being elsewhere)…
True enough. Software screwing up doesn't usually kill anyone. It does, however, do millions of dollars worth of damage with distressing regularity.
-
@dkf said in Suggest appropriate goals for a super-basic Python class (HS level):
when a mapping app fails if they're also seriously stupid, and it is the stupid that kills them and not the software failure
Yes, it's the stupid. No, the gene pool was not improved.
Edit: Found some gene pool corrections: https://arstechnica.com/cars/2016/05/death-by-gps/
-
@Mason_Wheeler said in Suggest appropriate goals for a super-basic Python class (HS level):
Software screwing up doesn't usually kill anyone. It does, however, do millions of dollars worth of damage with distressing regularity.
And when it does, consultants get paid lots of money to come in and fix it. I don't see a problem
-
@Jaloopa Lemme guess. You're a consultant?