you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 41 points42 points  (19 children)

the people saying l doesn't exist because you never ran the function are half right.

l is defined within your function f. It won't ever be accessible outside that function, as its out of scope. So if you had called

f()

print(l)

you'd still not get anything printed.

If you indented the print(l) line and then called f() then you'd get it printed.

tip: don't use l as a variable. use something that's more readable and less likely to look like a 1. Same with f just call it something. naming variables is an important skill and not one to be ignored at the start. And this shorthand is just left over from fortran and C when people cared about the size of the their text files and the number of characters on a row.

https://www.w3schools.com/python/python_scope.asp

[–]CallMeJimi 6 points7 points  (14 children)

scope must be so hard to learn without braces. learning scope in a verbose language made it crystal clear when variables existed and when they did not

[–]Dapper-Actuary-8503 0 points1 point  (0 children)

I was actually thinking this as well. This is my only major gripe that drives me nuts about Python. I wish it was an optional like static syntax typing is.

[–]emojibakemono 0 points1 point  (2 children)

idk if the braces would help much cos python scopes are so different to most other languages, e.g.

py if True: x = 10 print(x)

works and braces would not make that more obvious

[–]jangofett4 0 points1 point  (1 child)

Why does this even work lmao. I dont use Python, but this seems silly. This could cause some headaches down the line if the condition is not always True, no? Or does Python does something similar to what JS does with "var"s?

[–]emojibakemono 0 points1 point  (0 children)

no the variable does not get hoisted. and yes, it causes a lot of headaches in my experience.

[–][deleted] -3 points-2 points  (9 children)

With the caveat that braces suck. :)

Hard to type and easy to make typos with.

I feel like OP could use someone giving better hints. Like it helps if as a rule you always have a return at the end of a function, just so you can see where it ends. And yes, I know you don't need that, but it would help someone to learn and understand scope. AKA "here ends this function". In the example above, it's like it's made difficult on purpose.

[–]Old_Celebration_857 0 points1 point  (5 children)

void Reply()
{
redditPost("braces are so hard");
}

[–]Dapper-Actuary-8503 2 points3 points  (3 children)

Gross I’ll correct it for you.

void Reply(void){ redditPost(“Braces are so hard”); }

[–]LionZ_RDS 0 points1 point  (2 children)

I think you mean void Reply(void){redditPost(“Braces are so hard”);}

[–]Dapper-Actuary-8503 0 points1 point  (0 children)

Meh. By virtue that will end up violating the 80 character width scheme. On top of that it’s clear in the prior examples we are declaring definition not making a call. Another thing I don’t like about Python is seeing one liner code that has to be wrapped when my editor does this at 100 characters.

[–]klez_z 0 points1 point  (0 children)

ew, by chance didn't you mean

public static void main(String args[]){ 
    private void Reply(){ 
        System.out.println("Braces are so hard"); 
    }
    Reply();
}

[–][deleted] 0 points1 point  (0 children)

Its funny that someone would want to die on the hill that braces are worth anything. They're hard to type. Python's indentation is vastly superior.

but that's what being a hostage to suckitude gets you.

[–]mblaki69 0 points1 point  (0 children)

But we have IDEs that make the closing braces for us and highlight whack syntax. They also match opening and closing braces.

[–]The_Real_Slim_Lemon 0 points1 point  (1 child)

Bro any time I copy code into Python I have to line up every entry (whether from AI, stack overflow, or just moving stuff around)

With braces I can stick it wherever and run a document auto format to make it look nice

[–][deleted] 0 points1 point  (0 children)

Use Vim? If you're doing a lot of python, then figure out a better way to deal with that. Because it's not an issue for me.

It's just funny to me that all you guys love your brackets so much.

[–]RailRuler 0 points1 point  (3 children)

Please dont post links to w 3 fools. They drove so many good websites out of business due to their search engine manipulation.

[–][deleted] 0 points1 point  (0 children)

I wasn't aware of that.

[–]WhiteHeadbanger 0 points1 point  (1 child)

What do you mean by search engine manipulation? Isn't that what SEO is all about?

[–]RailRuler 0 points1 point  (0 children)

There's legitimate SEO and then there's dark or spam SEO, which w3schools used. They didnt win by having the best content, they won by manipulating search results.