Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Should i annotate types in my unit tests functions?
What also with overridden django methods like save and get or post functions in generic view?
This is arguably an opinion question but I think that there is a generally accepted answer, which is roughly "No".
One way of categorising programming languages is into statically typed and dynamically typed. Statically typed languages are generally more robust, especially for "programming in the large", and dynamically typed languages have advantages ito programming speed, and in modelling problems where it is beneficial to be able to accept data of various types. Type hints try to strike a balance. The rough rule being: if you are using the dynamic nature of the language to achieve something, don't worry about annotating it. If however, you are writing code that doesn't make specific use of the dynamic nature of the language, annotate
Perhaps to make the point clear, consider that if you DO annotate everything, well then why not just use Cython? Same effort but you actually get some speed up as well. The reason people use Python with annotations instead of Cython is that some problems are naturally better solved without specifying types.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am looking for resources that help me interpret python documentation effectivley. In particular, I am reading through the pythondocx module documentation, but am finding it hard to understand some sections.
As an example, when I read the Style Objects Section
, I am confused by lines such as class docx.styles.styles.Styles and what it is actually saying.
Any ideas on what I can do the to interpret documentation better?
I honestly think reading pythondocx module documentation is a bit of overkill.
The hard part of reading python documentation is understanding the specific logic of how objects and builtin's are organized in python. The best place to start, IMHO, is the index Python 3.8.1 documentation together with standard library and collections.
Even if you had studied other common languages before, like Java and C#, their API's are laid out in a different style. Each takes its own time for the reader to get used to. The python docs were written to be self-explanatory and after an initial learning curve that isn't especially steep the docs start making lots of sense.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have a background in structural programming (Pascal,Ada) and now I have been programming an app in Java because I needed to use a given package that was only available for Java,C++ and Python. I chose Java, but I think it was not the best idea as I am not into OOP and I am programming it in a structural way, this is, only with methods and the main program,avoiding to generate objects and those Java things.
Now that I have the "app" running in the windows console I need to generate a GUI to operate it, but before going to hell with Java and objects I would prefer to change to another programming language that permits me to constract the GUI with my structural programming mindset (if it is possible).
I have read that Tkinter in Python and GTkAda in Ada could be my saviours. In case of not being possible I guess I should try to get into OOP.
Thanks in advance
GtkAda is also object-oriented, and so is any other high-level GUI toolkit I've seen so far, so I don't think you can avoid object-oriented programming for the GUI, unless you use a more low-level approach.
Two more low-level approaches are:
An HTTP/HTML based interface.
Using the X protocol to talk directly with an X server.
Both of these approaches can be used with Ada, and probably also with Python. I don't know for sure if Python can do the necessary low-level formatting to talk with an X server, but it must be possible somehow.
If you're looking to use Python, try out PySimpleGUI. There are objects in use, but you don't have to do any object programming. You can copy and paste the "design patterns" without having to know exactly what they do. It was developed with beginners in mind, but can also support advanced, customized window layouts. Look at the Cookbook for code examples. You mostly need to learn how to do a "layout". You will not have to write the word "class" in your code, promise.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Cannot link the example to the title, so here it is: Python strategy design pattern example
First let's look at the basic idea of Strategy Pattern. What it really says is developing some algorithm (function/method/code fragment) which can be switched at run time.
If we are using an OOP supported language (Java, Python), most of the time, we can implement the Strategy pattern with the use of run time polymorphism. In your example also it shows how to achieve this exactly in that way.
No need to get confused with the notion of meta class. It's a python specific terminology, which is used to define the class object of Python. This one is a good answer, if you want to know more about meta classes in python.
And in your example, the notion of meta class doesn't quite related with Strategy pattern implementation. It was just used to mark the Strategy class there as an abstract class. You can develop your program even without that part. And it doesn't do any harm to the idea of Strategy pattern implementation.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
So I've been thinking to make a programming language written in python but I have no idea where to start, and I really don't know the steps creating it.
You would probably start by first planning out your language. That should take a lot of time. Then in Python... you would write a parser that can understand the syntax of your language, and an interpreter that can take the results of the parser and perform the actions of the program.
Your language that is written in Python with Python in-turn being written in C is practically guaranteed to be very slow and will not succeed, but this could be a really fun thing to do as a learning or education experience.
You will likely want to look at Abstract Syntax Trees. This is the underlying structure that python is built on. Take a look here at the documentation: https://docs.python.org/2/library/ast.html
Using ASTs you can at least define the syntax of your language. You will still need to solve the problem of how to interpret it on a platform to get your code to execute.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
First, why there is no end in python? Second, the fact that there is tabs and there is no end make python the best readable/beautiful language, why they do not introduce these characteristics in other languages?
You'll have to ask Guido van Rossum about why he didn't introduce an end construct, since it's a language design issue - but as you say, there are aesthetic reasons not to do so.
The reason this isn't introduced to existing languages is that there are already billions of lines of code written in them, and you don't want to force people to change all of that just for some aesthetics.
Why not have it as a backward-compatible change, such as e.g. allowing languages with C-like syntax to have the opening { but not the closing }? Probably because programmers in those languages are very used to it and might actually prefer it to not having closing marks, and probably don't see this as a useful feature. Also, it would be necessary to make it a per-file decision, as a mixture of explicit and implicit block ends would be extremely confusing and probably not parseable.
As a matter of fact, Python itself contains a joke about this, which I believe reflects the authors' opinion on the matter:
>>> from __future__ import braces
File "<stdin>", line 1
SyntaxError: not a chance
(__future__ is a module which you can use to import certain pieces of functionality that were introduced in newer versions of Python and have been backported to older versions.)