It is becoming difficult for me to be productive in Python
avi.im
avi.im
Let's consider the ultimate programming language that is able to infer your business requirement before you do or you even knowing what it is. Its only limitation (perhaps by design) is that it just can't write it. It can perform this amazing static analysis of the code and tell things like "hey, the requirement said to return a JSON with the following keys X and Y, but you are missing X. Oh and also you forgot to mail John the patch for that client".
Would programming in this language hard? OF COURSE! This language will constantly complain and wont run your program until you get your requirement exactly right. But I would argue this language is the best language to work with. You might say, "I will never ship a code because it will never be complete!" Well, dear friend, why not just admit that flaw and lower down your business requirement to include those deficiencies?
In addition, the only way type annotations are effective is if you use an editor that can parse types. Yuck.
Lastly, it is far too easy to create complex types with questionable value all over your code. Any time a developer wants to unravel a pre-existing complex type, it feels like working with C++. It's utter garbage.
No. Having types is always better than not. If you have a complex functionality, it is going to have a complex type. But now you KNOW its complex and not have to unravel its complexity for the 5th time this month.
I had to write something like this recently:
```
pub SearchInfo {
matches: Arc<HashMap<PathBuf, Vec<(usize, (usize, usize), String)>>>
}```
This is complex, yes, but just by reading the type and names given to it:
1. `Arc`. So that means it can be safely shared across thread.
2. `HashMap` from `PathBuf` to `X`. So I am probably mapping file/folders to X.
3. `Vec<(usize, (usize, usize), String)>`. So the first `usize` denotes the line number. `(usize,usize)` denotes the start and end characters and the `String` is the whole line itself!
Just imagine unraveling this whole crap if its all simply a JavaScript `Object`.
As software engineers, if you are relying on CI to verify language features, you are going backwards in time.
https://peps.python.org/pep-0585/ has been implemented in Python 3.9.
Type annotations are great for documentation and as a basic sanity test. They are especially useful with tools like code analysis or refactoring tools. But types are is no way a substitute for unit tests.
Sorry, I don't understand what you are saying here. By A and B are you referring to the correct output given an input, or just to the expected data type? Because there is a big difference, as with the `min()` example.
>inb4 just document it
that is what types are for
Static typing is a useful tool, just not a substitute for any unit tests. The risk of static typing is when it becomes a goal in itself and you start thinking correctness means the program satisfies the type checker.
And the argument that if you can’t prove your design correct then there is no point proving your code correct is a strange one. That’s like saying that there is no point writing tests because you can’t prove your design correct or guarantee that all tests needed will be written. Ehhhh nope. I have written and generated more than 9000 tests for a very large scale C++ applications that are used by large corporations around the world. And I haven’t had a bug in production for 5+ years. However I of course can’t prove that those tests cover everything or that my design is correct. But that doesn’t mean it isn’t worth doing.
Since dependent type systems are just another kind of code, this is still true.
a * sin(x) + b * cos (-x)
should have been a * sin(x) - b * cos (x)
type isn't worth a damn here.In a lot of situations you have related values of exactly the same type: floats, strings, integers, Widget objects, which get mixed up.
A warning about variable shadowing or unused variable can be worth more than a type diagnostic. E.g. suppose
a * sin(x) - a * cos (x)
is written by mistake. If that causes b to be an unused local variable, we get a valuable diagnostic.I’m guessing you’ve never talked to someone requesting dev work on upwork
They're known and readily available in the US, but never really caught on, even during and after widespread toilet paper shortages in 2020.
Probably California would ban them anyway along with toilets that actually work.
> Years of coding in Go gave me this comfortable feeling: if it compiles, it works.
That is never a rational feeling.
> Type hints solve these issues to some extent, but bugs can still slip through.
But the link is to a tweet showing how a Python static analysis tool actually caught the bug.
> You could set up CI/CD pipeline enforcing 100% code coverage, but that will affect team productivity and surely piss off people.
If enforcing optional type hints would piss people off then, surely, using a statically typed language would also piss people off.
As an example of stuff you can do with types. I was trying to teach a buddy how to program from a non CS background and I explored it a bit to make it as modular as possible so he could literally just change the structure and types and the code would all work for him. And it's really easy using some reflection
For example, to mimic a struct, you can use.
@dataclass
class CSVStruct:
x: int = 0
y: int = 0
foo: int = 0
bar: int = 0
Then you can typecast dynamically and generate random data(assuming you can go from int -> datatype) to fille in the data. arg_list = []
# Generating argument list dynamically
for field in dataclasses.fields(self.CSVStruct):
arg_list.append(field.type(randint(0, 100)))
Or to get all the names of a struct (In this case to print out any structure with headers into a CSV file. Can also be done with their values) # Getting column names
row_names = {field.name: field.type for field in dataclasses.fields(self.CSVStruct)}Python has its place in a programmers tool belt, but I often ask questions to determine the language to use. How long lived will this code base be? How critical will be every ms of performance? How many LoC will the final product be? How many people will work inside this project? How dense and complex is the system to be built?
Python is incredible at short, utilitarian scripts that perform a single task that is not normally done inside of your main code base. It’s robust library collection lets you easily do things that other languages would need to be built from scratch. A short script to scrape twitter or analyze data can provide an enormous amount of value for time invested.
IMHO for greenfield startup projects/POCs, I much prefer python for making things fast and getting things out to market asap. Spaghetti gets me fed.
This is good for python. It does break down for bigger more complex projects at a certain point.
This is a Django based tool to manage the tax rates you pay on any thing you might trade with the UK.
It can handle all the changes to the tax from the founding of the EU, through past Brexit when the UK has its own tariff as well.
Running it locally, it may not be straightforward to get hold of the right data (you can download it, but I don't think it's a turn key thing).
A defined wild guess of something which is not finalised is still miles better than an undefined, implicit, amorphous wild guess