I'm new to Python but I've seen a lot of projects and honestly it's a disgusting language. It does have some nice elements to it, but that's completely swamped by the mess it is. Unfortunately a lot of businesses make you use it so can we get some tips on how to make Python code look better? Just look at pic related for example. Disgusting.
I'm new to Python but I've seen a lot of projects and honestly it's a disgusting language...
Why the fuck are you using 8 spaces? 4 is the standard for python and always has been.
just get to work and stop worrying about stupid shit
I've used tabs for every language except html and css where I use 2 spaces (because they often have ridiculous amounts of indentations). tabs make it look a lot nicer. And no, soft-tabs are not tabs. A tab is 8 characters.. even more reason Python is a garbage language.
Good code needs to be readable. Python is nowhere near as readable as C. I don't like to write bad code, but Python forces me to. Python is like if JavaScript and Perl had a baby.
When will Sup Forums introduce multi-image posts like all the other good chans?
i didn't have an opinion on how big indentations should be before, but those arguments are so retarded maybe i should just assume the 2/4 camp is the intelligent one.
>assume
That's where you went wrong. Experiment for yourself and you'll find tabs are the way to go. I'd have to agree with Linus when he says more than 3 indents is bad code.
>tabs are not adjustable
Well, there goes the only advantage you had over spaces.
The only time I've used spaces is with html and css. Everything else should be 1 tab.
...
That does look a lot nicer, but I guess the comments helped space things out. Not that I'm saying comments are bad (they're great). It would look even nicer if you had 8 spaces instead of 4.
I agree that Python is ugly, but I don't give a shit about the syntax of the language or the number of spaces they recommend.
Is having so much mutable shit that bothers me. You can mutate a map that you pass into a function, and even date & time values are mutable, for fucks sake.
not to mention he should be using prepared statements, not string substitution to prepare a query
hello sql injection
You are literally the only person to use 8 spaces with python. Neck yourself.
It's converting XML to SQL, where there's 100s of different columns. Hardcoding 100s of different tags that might not cover all possibilities for a localized program seems kind of pointless.
I kind of doubt that. But either way, only babby's use Python by choice. I only started learning Python yesterday for a job, because at the end of the day, money's money.
You sounds like you just legit don't know what you're doing.
You sound like a code-babby. I learned Python in a day.
Usually it's not the language's fault code looks bad
>Usually
>It's converting XML to SQL, where there's 100s of different columns
You can still generate it all in the same. Just don't concat the values directly into the SQL. Its security 101 famalam
I guess I could if I put my mind to it, but that's not really what this thread's about. My biggest gripe with Python might be silly, but why can't we use curly braces for logic blocks?
you'd indent the code regardless of the braces, so why not just leave the braces out?
If I need to explain why braces are awesome you should read K&R's The C Programming Language. Can't hurt.
>Is having so much mutable shit that bothers me.
This is only a problem if you suck at programming and documentation. If you can't stop yourself from changing things you shouldn't be changing, you should probably use a language that provides more hand holding.
>Can't hurt.
Probably. But one has only so much time and the next deadline's around the corner.
Now if you'll excuse me, I'd have to fuck around with f2py and write some interfaces to couple our new humidity-dependent gas absorption code with a FORTRAN radiative transfer solver.
C could have braces removed from it and it wouldn't change anything.
There is however a small set of things that would be marginally nicer to use in Python if it had braces, mainly pertaining to lambdas.
>Probably. But one has only so much time and the next deadline's around the corner.
You have free time don't you? 20 minutes a day for a month and you'll finish it.
>C could have braces removed from it and it wouldn't change anything.
Blasphemy. You might as well suggest Lisp have its parenthesis removed.
>You have free time don't you? 20 minutes a day for a month and you'll finish it.
I'd rather use those 20 minutes to read up on new land surface models. Fuck programming, it takes up too much time already. I don't need to be able to recite the history of brackets in C, I'd rather do science.
You're one of those /sci/ shitposters that ironically hates programming aren't you
The languange tries to force you to mutate. E.g., there is no built-in function to get the result of merging multiple maps, you are expected to do it in place and there is no way to get the result of, say, setting, a datetime's day to 5, without doing mutating it.
Python is great because it exposes people like you for the idiots you are. Consider another career.
Fuck you moron. BDFL states that 4-space spacetabs are the only way to go. Your moronic way of thinking is clearly getting in the way and that's why you write shit code and cry on Sup Forums about it.
>Code-monkey problems
If you're overly fixated on how "pretty" your code looks it's because you're a code monkey with no real ideas.
>BDFL
Literally a meme. You're just another Python brainlet that can't think for themselves. Python really is the perfect language for you.
Samefag, let me just say that good code needs to be readable. Even people with real ideas know that.
>brainlet
Says the guy who can't write a couple loops in python without turning it into a massive shitheap
Oh, now we've devolved to ad hominem? Your a nigger monkey because I learned Python in a day.
hello
heard you were having programming language problems
that's too bad
>bdfl is a meme
>but torvalds is the law, even when talking about a different language
Tabs may be n characters long, where n should be between 1 and 8. Your formatting should not rely on them being a specific length.
Take your dead language elsewhere you double nigger.
>>bdfl is a meme
It "literally" is a meme though. Like, literally. As in the literal sense of the word. It was derived from from a Monty Python skit.
>>but torvalds is the law, even when talking about a different language
I trust the founder of Linux more than the founder of a poorly-written-shitpost on Sup Forums
>Your
You didn't learn shit, from the looks of it. You're a retard. Enjoy your $20/hr data entry job though.
2 space tabs is da best!
$20/hr for a job that could be easily automated sounds awesome. Your just jealous.
I guess every post is a shitpost when you want to get a rise out of someone, is it?
But trust him all you want. I'd love to see your three-indent rule classes.
He wasn't referring to everything you nigger. If you can't even see the logic behind that statement you're either shitposting or don't belong in programming.
:set ts=2 sw=2 expandtabs
And stop composing SQL by hand
Maybe assuming it's the same person is bad, but
I'll stop doing that when you :set redditspacing=off in you're .vimrc
So you did fail to see the logic behind it. How interesting.
>double newlines after a paragraph to make things easier to read
>le reddit maymay
No wonder you hate python. You hate readability.
Who are you quoting?
Python has more sex appeal than any other programming language. I often get semi-erect when reading through my old code
Stop browsing on your phone and spacing wouldn't be a problem.
Nice trips, fampai
>implying implication chevrons are quotes
The absolute state of Sup Forums gentlemen and gentlemen.
Who are you quoting?
Pray tell, what is it?
I'd trust the man with his practice, but not with his ideas about formatting.
It's not a be-all and end-all for formatting, but it's a good rule of practice.
I'm new to coding so I tore all your code down to replace it with something better:
for (let reportItem of tree('ReportItem')) {
my @cols;
our @datas;
for (auto e : reportItem.items()) {
if len(e->text) > 1 {
@cols.push(e::tag);
&datas.append(e.text);
}
}
var Str[] marklist;
var Str marks;
if \datas.elems {
@marklist.append(...('?' * datas.length));
$marks += marklist.join(`, `);
}
/************************************************
** TODO
************************************************/
itt python users demonstrate how they are the rick and morty watchers of programming
POO
Rigg n Morky maymes are dead you quad-nog. At least relate it to something new if your going to try and trigger me. Otherwise FUCK OFF bro
>A tab is 8 characters
But that's wrong, you monkey.
What's wrong with that? They have some needless verbosity, like the fact that ReportItem.iter() can be replaced with just ReportItem, but that's far more terse than you're going to get in any other language. Java would probably be twice the number of characters, and C/C++ would be even worse.
>But that's wrong, you monkey.
Compile and run this:
#include
int main(){
printf("%c", 9);
}
How many spaces is it equivalent to?
Zero, there's just a single tab.
But to achieve the same width would require 8 spaces.
No, that depends on what tab width you set in your terminal.
>But to achieve the same width would require 8 spaces.
No, that's your terminal emulator/editor doing that.
>t. totally not triggered pythonlet
Unix does that by default though, and everyone knows unix is superior. How many spaces would it be equivalent to when run in ASM?
> How many spaces would it be equivalent to when run in ASM?
What the actual fuck are you talking about? If you were to write the same program in asm it would output the same shit.
No I mean outputting the tab character by the ANSI standard.
>using spaces instead of tabs
>hurr durr the hard way makes i smrats
I bet you use emacs/vim
>No I mean outputting the tab character by the ANSI standard.
The tab character is one character.
It doesn't even expand to a fixed number of characters - it expands to the next tab stop. So if you put 3 characters, then a tab, if your tab stops are set to 8 characters, then the tab only takes up 5 columns. Also columns != characters (even ignoring tab) because non-printing characters and double-wide characters are a thing.
setting 1 tab to 4 spaces is in the python style guide you faggot
>hurr durr I am retarded and don't know how to kode but I wanted to reply
-(((You)))
>the hard way
It's another "i believe using spaces means actually pressing the space key" episode.
ANSI just says that 9 is a horizontal tab character, that's it.
Exactly. And in unix the tab character is equivalent to 8 spaces. Other faggotry should be forbidden.
>And in unix the tab character is equivalent to 8 spaces
But it's not.
The distance from one tab stop to the next is 8 characters (by default in terminal emulators and many editors, though this can generally be configured in editors), but that doesn't mean it's 8 characters.
Oh, but I agree on that.
By the way, OP, how does this look? (bad indent aside)
for ReportItem in tree.iter('ReportItem'):
elems = [e for e in ReportItem.iter() if len(e.text) > 1]
marks = ', '.join("?" for e in elems)
cols = ', '.join(e.tag.replace('-', '_') for e in elems)
# python 3 only
c.execute(f"INSERT INTO reports ({cols}) VALUES ({marks})", [e.text for e in elems])
Oh and obviously elems could also be a simple generator, but then it'd lose the __length_hint__ and the execute would construct the parameter list one element at a time. I assume you're iterating over some sort of XML mutable.
It might not be literal but it certainly is a standard. I never argued it was literal; note the part where I said "other faggotry should be forbidden"
That does look a lot better, thanks for teaching me a nicer and more efficient way of writing Python. I'd always thought logical operators aside from OR and AND had to be at the start, obviously I was wrong.
Removed some lines for you bro. Is this a bit more readable OP?
for ReportItem in tree.iter('ReportItem'): c.execute(f"INSERT INTO reports %s VALUES %s" %(', '.join(e.tag.replace('-'. '_') for e in [e for e in ReportItem.iter() if len(e.text) > 1]), ', '.join("?" for e in [e for e in ReportItem.iter() if len(e.text) > 1])), [e.text for e in [e for e in ReportItem.iter() if len(e.text) > 1]])
>I'm new to Python but I've seen a lot of projects and honestly it's a disgusting language
Sounds like you don't really know what you are talking about then.
The code you posted is ugly because it is poorly written.
you could have populated cols and datas with a list comprehension.
Using % to format strings is OOOOOOLD shit.
Naming a method `iter` is bad practice. You should have inherited from object and overwritten the __iter__ method.
Like there are so many problems with the code you posted, and a lot of them have nothing to do with python.
Maybe you should just git gud
he'll git gud as soon as you stop the reddit spacing
you should also remove those reddit spacing lines
>only babby's use Python by choice
>I only started learning Python yesterday for a job
lol dude. You're the fucking baby here in this case.
Yeah but I learned it in a day, dipshit. I'd like to see you do that you fucking brainlet. Also what's with you niggers and the r*ddit spacings recently?
>'learned' it in a day
I wouldn't consider producing shit code and then complaining about it on Sup Forums `learning python in a day`
All Python code looks shit though. I guess you're missing the part where I said "I've seen a lot of projects"
>I've seen a lot of projects
This literally doesn't matter.
You won't understand a project just by looking at it. It takes several weeks to a few months for average professionals at top companies to make meaningful contributions to production in complex projects they are completely new to and you are telling me you know that a language is shit because you've just looked at some code? Sounds like you are full of shit
It doesn't take a professional to see how disgusting code is. You should really learn another language.
The whole is the sum of its parts. A project made of shit code is a shit project.
>All Python code looks shit though
No it doesn't.
It's one of the absolute least boilerplate-y languages around.
The equivalent Java would probably be 3x the characters, and C at least 5x.
>It doesn't take a professional to see how disgusting code is
Yeah and it is obvious that code you posted is total shit, and not because its python
Maybe you should have learned something from those projects instead of writing this dog shit code.
Show me 1 example (one) where Python looks better than C. I'll wait.
> a shit project is a shit project
Yeah and water is wet. Keen observation.
This doesn't substantiate OPs claim that 'seeing a lot of python projects' makes them an expert on how python is shit?
who cares. code is a means to an end. If you obsess about neatness and other unimportant aspects of it, you will forever be a bottom rung code monkey making $40k/year.
Lol that looks like shit and it's entirely your fault. You probably write shit code in your other languages too.
Uh oh, someone's samefagging! The unique IP's didn't update when you posted! At least make an effort if you're going to attempt trolling me.
>Naming a method `iter` is bad practice
Blame LXML