Code editors and style for Python 3

Need help with C, C++, perl, python, etc?

Code editors and style for Python 3

Postby Wheelerof4te » 2020-01-01 20:30

I started writing Python about 5 months ago and I am loving it. It allows me to automate some of the tasks I do, experiment with useful CLI programs, even write a game or two.

My style:
I am mostly writing in procedural style, using classes for simple objects with modifiable attributes that need a shared method applied to them. I try to keep my code organized in small files, with classes and functions related to each other in one file. For the syntax style, PEP 8 rules, so it's 4 spaces indents, CamelCase for classes, lowercase for vars, _ as word separator, etc.
I wanted to learn more OOP style, but then quickly backtracked. I think it's silly to use classes outside of custom objects creation, just for the purpose of abstracting things. Python is an object oriented language, but I saw a lot of OO Python code and it is not pretty. And don't get me started on the inheritance mess. That concept needs to die. As do most of the libraries found on PyPi, using them sometimes feels like learning a new language, haha. Standard lib FTW.

Editors I tried are VS Code, Atom, Geany, PyCharm and of course IDLE. Now I am digging Gedit with a few plugins, since it's fast and light, forcing me to focus on my code. Atom and PyCharm are bloated mess, I don't even wanna start. Geany is a fine editor, but Gedit is cleaner. VS Code was nice, but it's still Electron application and it's developed by Microsoft, so no thank you. Also, VS Code complains about some things when you try to write around limitations like auto-appending to lists. Variable not used, like hell.

So, what are your favorite editors and programming styles for writing Python?
BTW, RIP Python 2. I haven't used it, but it sure was a great language.

print "Bye World!"
Wheelerof4te
 
Posts: 1454
Joined: 2015-08-30 20:14

Re: Code editors and style for Python 3

Postby Soul Singin' » 2020-01-01 20:59

Wheelerof4te wrote:So, what are your favorite editors ... ?

Emacs

Wheelerof4te wrote:So, what are your favorite ... programming styles ... ?

Perl

Wheelerof4te wrote:Python?

Python has a lot of good libraries and it's very easy to write mathematical functions in the language, but for regular expressions and for organizing complex data structures, nothing beats Perl.

You can write regular expressions in Python, but first you have to import the module. Regular expressions are not an integral part of the Python language. Perl's regular expressions are much easier to use because they are an integral part of the Perl language.

Python has dictionaries, but Perl has scalars, arrays and hashes that are much easier to combine. Check out the Data Structures Cookbook by Tom Christiansen. It's like a Python dictionary on steroids.
User avatar
Soul Singin'
 
Posts: 1607
Joined: 2008-12-21 07:02

Re: Code editors and style for Python 3

Postby Soul Singin' » 2020-01-01 22:26

Soul Singin' wrote:regular expressions in Python

Suppose you have the string "red socks" and you want to change it to "blue socks".

So let's start with the string. Strings are simple in both languages.

Python:
Code: Select all
clothes = 'red socks'

Perl:
Code: Select all
my $clothes = "red socks";


Now let's perform the substitution. In Python, you first have to compile the pattern. Only then can you perform the substitution. In Perl, there's only one step. And it's much shorter.

Python:
Code: Select all
pattern = re.compile('red')
clothes = pattern.sub('blue',clothes)

Perl:
Code: Select all
$clothes =~ s/red/blue/g;


Python requires you to remember the name of the variable that you saved the pattern to. That's horribly confusing.

Perl requires far less typing and the substitution is much clearer. It literally says: "replace 'red' with 'blue'."
User avatar
Soul Singin'
 
Posts: 1607
Joined: 2008-12-21 07:02

Re: Code editors and style for Python 3

Postby arzgi » 2020-01-02 09:58

Good choice to start learning python! :D

I use only vim for programming, it has at least hundreds if not thousands plugins, many in Debian repo, rest in https://www.vim.org/scripts/index.php

I do most of my programming in python(3), so have installed autocompletion and syntax-checker plugins: jedi and syntastic. But these are not the only one like, vimballs are eaysy to install and purge, so I've tried many. If it does not feel right or is cumbersome to use, let if go!
arzgi
 
Posts: 639
Joined: 2008-02-21 17:03
Location: Finland

Re: Code editors and style for Python 3

Postby Head_on_a_Stick » 2020-01-02 10:09

Vim ftw!
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12492
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Code editors and style for Python 3

Postby Wheelerof4te » 2020-01-02 10:26

I once opened Vim. ...yeah. But I know it has a bunch of useful little plugins like above mentioned.

@Soul Singin':
Perl requires far less typing and the substitution is much clearer. It literally says: "replace 'red' with 'blue'."

I don't know, I never tried Perl, but that syntax feels confusing to me:
$clothes =~ s/red/blue/g;

What do 's' and 'g' mean? Switch, generate? So confusing, even that ~ is confusing and a PITA to write. But with Python:
clothes = pattern.sub('blue',clothes)

you know that .sub means substitute, and that it's a method of an instanced object "pattern".
It just feels more natural to write in Python to me, as I don't have to deal with syntax magic as in most other languages. Lack of syntax magic is also what drives me ever closer to Go, as it might be my next language. The only worry there is Google.
Wheelerof4te
 
Posts: 1454
Joined: 2015-08-30 20:14

Re: Code editors and style for Python 3

Postby Soul Singin' » 2020-01-02 12:28

Wheelerof4te wrote:
Soul Singin' wrote:$clothes =~ s/red/blue/g;

What do 's' and 'g' mean? Switch, generate?

"s" means "substitute" and "g" means "globally" -- When you learn how to program, you'll notice that sed uses the same syntax.

Wheelerof4te wrote:So confusing, even that ~ is confusing and a PITA to write.

How is it a "PITA to write" two characters ("=~"), but not a "PITA to write" two whole lines?

Wheelerof4te wrote:But with Python:
Soul Singin' wrote:clothes = pattern.sub('blue',clothes)

you know that .sub means substitute, and that it's a method of an instanced object "pattern".

So you would seriously prefer to create an instanced object for every pattern you wish to match? Really? You don't think that's a "PITA to write"? Try writing a website scraper -- where you have to match dozens of patterns -- and I promise you that you will feel differently.

Wheelerof4te wrote:It just feels more natural to write in Python to me, as I don't have to deal with syntax magic as in most other languages.

So you would seriously prefer not to have any shortcuts to simplify your task? How is that not "PITA to write"?

Wheelerof4te wrote:Lack of syntax magic is also what drives me ever closer to Go, as it might be my next language. The only worry there is Google.

That a major technology company might devote time, money and resources to developing the language? That worries you? Seriously?
User avatar
Soul Singin'
 
Posts: 1607
Joined: 2008-12-21 07:02

Re: Code editors and style for Python 3

Postby Wheelerof4te » 2020-01-02 13:10

Soul Singin' wrote:So you would seriously prefer not to have any shortcuts to simplify your task? How is that not "PITA to write"?

Same reason as C is much easier to learn and write than C++: because it's just a simpler language with far fewer features. I don't measure language's simplicity by lenght of lines written, but by amount of abstractions and syntax magic the language forces you to learn.
Soul Singin' wrote:How is it a "PITA to write" two characters ("=~")

I meant that it's PITA to write the character ~, at least on my keyboard. I usually don't reach for ` with SHIFT on my QWERTZ keys.
As for Google, I don't trust a Big Tech, monopolistic company based in USA, period.
Soul Singin' wrote:When you learn how to program

This is just rude. Let's not turn this thread into Perl vs Python flame war :D
Wheelerof4te
 
Posts: 1454
Joined: 2015-08-30 20:14

Re: Code editors and style for Python 3

Postby Soul Singin' » 2020-01-02 13:29

Wheelerof4te wrote:
Soul Singin' wrote:How is it a "PITA to write" two characters ("=~")

I meant that it's PITA to write the character ~, at least on my keyboard. I usually don't reach for ` with SHIFT on my QWERTZ keys.

Seriously? You would prefer to write several lines of code than to reach once for the upper left corner of the keyboard?

Wheelerof4te wrote:Let's not turn this thread into Perl vs Python flame war :D

Of course, not. Python already lost that war.

For example, if you study Natural Language Processing, you'll notice that Python's mosestokenizer module consists of wrappers for the Perl scripts in the Moses toolkit. Why does the Python module use wrappers? because it's easier to write regular expressions in Perl.
User avatar
Soul Singin'
 
Posts: 1607
Joined: 2008-12-21 07:02

Re: Code editors and style for Python 3

Postby arzgi » 2020-01-02 13:32

Perl brain washing, yea! :mrgreen: Every programming language has it's own strengths, but is it really necessary advocate your preferred language, when someone ask advice for his/her selected.

I would say python is better for general purpose programming than perl (let the flame war begin!). I'm only a hobby programmer, for me python, bash, sed and awk have been good enough. Depends what you need.
arzgi
 
Posts: 639
Joined: 2008-02-21 17:03
Location: Finland

Re: Code editors and style for Python 3

Postby Head_on_a_Stick » 2020-01-02 13:39

POSIX sh ftw! :mrgreen:

But seriously, Go was created by Rob Pike & Ken Thompson. Don't let the big G association put you off, it's not like they can control your programs if you write them in Go.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12492
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Code editors and style for Python 3

Postby Soul Singin' » 2020-01-02 13:41

arzgi wrote:Perl brain washing, yea! :mrgreen: Every programming language has it's own strengths, but is it really necessary advocate your preferred language, when someone ask advice for his/her selected.

The very first sentence that I wrote in this thread was:

Soul Singin' wrote:Python has a lot of good libraries and it's very easy to write mathematical functions in the language,

In other words, you pick the tool that's right for the job. Python has its strengths. A lot of them. The war occurs because inexperienced Python users ignore its weaknesses.
User avatar
Soul Singin'
 
Posts: 1607
Joined: 2008-12-21 07:02

Re: Code editors and style for Python 3

Postby Wheelerof4te » 2020-01-02 13:53

Soul Singin' wrote:. Python has its strengths. A lot of them. The war occurs because inexperienced Python users ignore its weaknesses


I didn't write about any of the Perl's weaknesess, and I'm sure it has plenty. As I said in one of my previous posts, Perl is not my forte, nor did I write a single line of Perl in my life. So stop with "muh Perl is better than Python", none asked and no one cares. What I do care is what is your prefered programming style, that was the question. Is it procedural, pure functional, or OOP?
Not the language, the language in this thread is Python, although you can talk about your experiences with other languages. I want to choose my second language, so far that choice is Go.
Head_on_a_Stick wrote:But seriously, Go was created by Rob Pike & Ken Thompson. Don't let the big G association put you off

Yeah, Ken is the big name in Unix and C. I will consider it, thanks.
Wheelerof4te
 
Posts: 1454
Joined: 2015-08-30 20:14

Re: Code editors and style for Python 3

Postby Soul Singin' » 2020-01-02 14:12

Wheelerof4te wrote:
Soul Singin' wrote:. Python has its strengths. A lot of them. The war occurs because inexperienced Python users ignore its weaknesses

I didn't write about any of the Perl's weaknesess, and I'm sure it has plenty. As I said in one of my previous posts, Perl is not my forte, nor did I write a single line of Perl in my life. So stop with "muh Perl is better than Python", none asked and no one cares.

The war occurs because inexperienced Python users ignore its weaknesses.

Thank you for proving my point.
User avatar
Soul Singin'
 
Posts: 1607
Joined: 2008-12-21 07:02

Re: Code editors and style for Python 3

Postby Wheelerof4te » 2020-01-02 14:55

So, I have to write Perl to be considered an experienced Python programmer?!
Yeah, no.

@HoaS:
How did you install Go? Using apt, or by downloading it from golang.org? Will Go 1.11 be enough for a beginner? I don't want to bother with modules right now.
Wheelerof4te
 
Posts: 1454
Joined: 2015-08-30 20:14

Next

Return to Programming

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable