Re: Why Python When There Is Perl?

Liste des GroupesRevenir à ol advocacy 
Sujet : Re: Why Python When There Is Perl?
De : bowman (at) *nospam* montana.com (rbowman)
Groupes : comp.os.linux.advocacy
Date : 21. Mar 2024, 07:36:18
Autres entêtes
Message-ID : <l61vaiFn16lU2@mid.individual.net>
References : 1 2 3
User-Agent : Pan/0.149 (Bellevue; 4c157ba)
On Wed, 20 Mar 2024 18:31:00 -0400, DFS wrote:

After I learned enough python, I started working on the same problems
with C.  C executes 5x to 10x faster than Python, but requires 3x to 5x
the amt of time and code.  Note: you will NEVER recoup the extra C
development time with savings in program execution time.

To quote Kenny Rodgers (Don Schiltz actually) you've got to know when to
hold them and when to fold them. A common mistake is worrying too much
about optimization early in the development cycle.

While I agree on the volume as measured by lines of code I'm not sure
about the time, particularly when you have an established codebase.

url = f" https://itunes.apple.com/search?term={term}
&media=music&limit={self.limit}"
response = requests.get(url).json()
list = []
for result in response["results"]:

does a lot in four lines. I'm looking at some C code using the OpenSSL
library to connect to a host/port, do a HTTPS transaction. and return the
result. There's a generous amout of error checking and handling and it's
84 lines rather than 1.

BUT. amd this is the big but, like whoever developed the Python requests
package I wrote the code a long time ago. It's in a file called http.c
strangely enough. Include the file and the 84 lines becomes

static char* https_send(char* msg);

As the static implies that function isn't directly called. There are other
entry points that build the HTTP header as required, figure out the
ContentLength and so forth, 

The real time spent is figuring out what you want to do or to put it in
geek speak, developing the necessary algorithms and data structures.

I've been reading

https://www.amazon.com/Python-Tricks-Buffet-Awesome-Features/dp/1775093301

The sniipets aren't long but he goes into list comprehension, decorators,
some of the more obscure dunders, setting up classes with class variables,
instance variables, and static functions using decorators, why you might
want to do so, and how they work.

The section I'm on now is Common Data Structures in Python. Every Python
programmer knows what a list is, but how does it work? Is it a linked
list, and array, or what?  Again in C linked lists of structs are common.
They don't have the nice neat look of Python but I can build single or
doubly linked lists, insert or remove elements, set up sorting and so
forth in my sleep. If there isn't boilerplate I can cut'n'paste' the time
to implement one depends on my typing speed. The same can be said for C++
containers; if you know how to do it in C, it comes down to typing.




Date Sujet#  Auteur
2 Oct 24 o 

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal