Python Devs Will HATE YOU If You Do THIS

preview_player
Показать описание
Python devs will surely hate you if you do this. #python #code #shorts
Рекомендации по теме
Комментарии
Автор

python: "WE HAVE A STRICT INDENTATION RULE! SO PEOPLE COULD READ THE CODE BETTER!!!"

also python:

ban_droid
Автор

A literally thought this was a syntactic feature that allows you to call the first method available for a class. And then I was expecting that first method to have a name, like "the prime directive" or something.

humanrightsadvocate
Автор

Thinking that insignificant whitespace is "insane" is the most Python thing I have heard in a while lol.

ForeverZer
Автор

This is very usefull, as it allows you to put function calls on the next line.

It makes it very readable when you have a chanin of multiple functions where every function is on its own line.

Eg:

car = CarFactory()
.with_color(Colors.Red)
.with_sport_suspension()
.build()

nathanoy_
Автор

Pretty sure a lot of languages accept an arbritrary number of spaces. The main difference is that they also accept line breaks, to allow indenting method chains, which python does not (need backslash) so it's basically a useless feature here.

Scymet
Автор

Just about most languages do that I'm pretty sure. The compiler always removes spaces and crushes all the code together anyways

darux
Автор

Just use a formatter and problem solved. Never ever manually format your code anymore. When I inherit a codebase with a poor git history, the first thing I always do is reformatting using black (insulating the formatting in a commit). So I can focus on substance rather than form

etis
Автор

Bro found a way to compile python. Hallelujah 🎉

abiiranathan
Автор

1. Who the hell would do this?

2. You can do this in C and C++ as well:

struct test {
int a;
};

int main() {
const test myvar{5};
std::cout << ( myvar . a) << '\n;
}

output: 5

vorpal
Автор

Wow I'm going to do this in my code when I'm on notice period 😂

AnkitTiwari-dqqm
Автор

As a JavaScript developer, I can completely agree with you.

ProCodeSoftware
Автор

Use backslash before dots to emulate Rust's way to format methods

Randych
Автор

I only do this if it's necessary to make it easier to read -- e.g. float( 2 * 2 )

PotatoChips-jypk
Автор

This is true for most of the languages. If you take a look at how a lexer is written, there's always some whitespace skipping feature. Nothing surprising if you know how a compiler is made.

leschopinesns
Автор

This is the programming equivalent of a 3 year old saying "fart" and laughing their butt off

orterves
Автор

This is not unique to Python in any way. Lots of languages allow this.

pharoah
Автор

Pretty sure you can do this in any language? It's useful to split method call chains across multiple lines and such, but of course with great power comes great responsibility

Qbe_Root
Автор

Yes, I will personally hate anyone who does this. 😂

AWriterWandering
Автор

Whitespace forgiveness, not sure if that's the formal name in python. For a high level view see `Syntactically Significant Whitespace Considered Harmful` on the c2 wiki

TheNewton
Автор

Silly thing? SILLY THING?! This is a war crime

AtheistRising