Live data from Hacker News

A bite of Python

access.redhat.com

81–90 of 168 posts

Re: A bite of Python

#81
post #64

Earlier quoted context omitted.

The single leading underscore?

Is conventional, it doesn't do anything at the language level.

Which is my point, it's still roll-your-own, with some magic when necessary. I don't want to make a fuss about it, I mean, it's great for tinkering or small projects, but I prefer when my compiler works harder for me and actually enforces what is intended (bar some runtime reflection for very special cases).

Re: A bite of Python

#82
post #79
post #74

Earlier quoted context omitted.

I mean, this one is solvable by not using magic constants. Pretty easy to avoid. Can also lint it.

I don't get what you're saying. How is it possible to write code without string literals? subprocess.check_call([ "/usr/bin/env", "echo" "hello world" ])

I think she meant to not pass the strings but assign them to constants and then pass those.

Re: A bite of Python

#83
post #53

Earlier quoted context omitted.

> An asserts checks DESIRED constraints. Then imagined it is. Your desires are totally a part of your imagination, unless you make them become real. > Depending on the implementation, an assert can either merely log or absolutely stop a program that doesn't pass its test, so it very much has a bearing on what the program will actually do. Point taken. Unfortunately, logging errors or aborting the program won't make a…

> Then imagined it is. Only in the most pedantic and useless sense of the term. Asserts are not just some random imagination, they are added based on the program's specifications and expected/desired functionality and constraints. The CS term for those kind of constraints are "invariants", and asserts are a way to be notified if those invariants are violated. > unless you make them become real. Only there are no assu…

> The CS term for those kind of constraints are "invariants", and asserts are a way to be notified if those invariants are violated.

An “invariant” is a function of the process state whose value remains constant (hence “invariant”) in spite of changes to the process state. Perhaps you meant “precondition” or “postcondition”?

> Only there are no assurances for that. If the invariants in your program were somehow guaranteed to be "real"

Guaranteeing that preconditions, postconditions and invariants hold when they're supposed to hold is your job, not the computer's.

> then you wouldn't need asserts.

I absolutely don't need asserts. An assert merely describes what you want, but that's useless to me, unless you establish a relation between what you want and what your program actually does - with proof.

> Asserts are there because whether you tried to make your invariants "become real" or not, you'll still miss things, have bugs,

It will become patently clear when the proof doesn't go through.

> have unexpected interactions with code/systems outside your control etc.

What happened to sanitizing input at system boundaries?

> Assertions are not expected to "magically become true"

Of course. Assertions are expected to always be true.

Re: A bite of Python

#84
post #79
post #74

Earlier quoted context omitted.

I mean, this one is solvable by not using magic constants. Pretty easy to avoid. Can also lint it.

I don't get what you're saying. How is it possible to write code without string literals? subprocess.check_call([ "/usr/bin/env", "echo" "hello world" ])

he probably meant not using string literals / ints outside of top-level declarations, so you would instead assign all these parameters to "constants" at top level and then use those constants in function calls, hence avoiding this error.

Re: A bite of Python

#85
post #57

Earlier quoted context omitted.

> If you have the process quit it definitely stops them from being false though. The assertion remains false for the final process state, before the process quits. Outside of the process, the assertion is simply meaningless (neither true nor false), because the assertion's free variables are only bound inside the process.

> The assertion remains false for the final process state, before the process quits. Which is inconsequential. Programmers don't expect automatic "recovery" from assertions, they expect them to notify them of the violated constraint, and/or to ensure that a program wont go on and use a value that violates an assertion further down -- which program termination achieves. > Outside of the process, the assertion is simpl…

> Programmers don't expect automatic "recovery" from assertions,

Users don't expect failed asserts at all.

> Captain Obvious?

Apparently not obvious enough for JonnieCache, who said: “If you have the process quit it definitely stops them from being false though.”

Re: A bite of Python

#86
post #82
post #79

Earlier quoted context omitted.

I don't get what you're saying. How is it possible to write code without string literals? subprocess.check_call([ "/usr/bin/env", "echo" "hello world" ])

I think she meant to not pass the strings but assign them to constants and then pass those.

Yep! But, like I mentioned, linter can catch this too.

Re: A bite of Python

#87
post #74

Earlier quoted context omitted.

I love Python, but I have to agree on this one.

I mean, this one is solvable by not using magic constants. Pretty easy to avoid. Can also lint it.

Unless I'm using a string more than once or its meaning is unclear, I always use the literal. In most cases, I find it more legible than having to go look up a constant's definition.

Then yes, I rely on the linter and testing.

Re: A bite of Python

#88
Completely out of context, sorry, but couldn't avoid to note this:

"Being easy to pick up and progress quickly towards developing larger and more complicated applications, Python is becoming increasingly ubiquitous in computing environments".

Why would you change the order of the subject in such an unreadable way? Isn't much easier to say:

"Python is becoming increasingly ubiquitous in computing environments, as it's easy to pick up and progress quickly towards developing larger and more complicated applications"

I'm not expert in writing, it just sounded weird. If anyone can explains what's going on there, really appreciated.

Re: A bite of Python

#89

Completely out of context, sorry, but couldn't avoid to note this: "Being easy to pick up and progress quickly towards developing larger and more complicated applications, Python is becoming increasingly ubiquitous in computing environments". Why would you change the order of the subject in such an unreadable way? Isn't much easier to say: "Python is becoming increasingly ubiquitous in computing environments, as it's…

Sounds to me like they started with something like "Being easy to pick up, Python is becoming increasingly ubiquitous..." and then made the old engineer-as-writer error of adding extra specificity.

Re: A bite of Python

#90

Completely out of context, sorry, but couldn't avoid to note this: "Being easy to pick up and progress quickly towards developing larger and more complicated applications, Python is becoming increasingly ubiquitous in computing environments". Why would you change the order of the subject in such an unreadable way? Isn't much easier to say: "Python is becoming increasingly ubiquitous in computing environments, as it's…

I forget the second half of the line, but one of my high school English teachers would always say "being is bad, ...", meaning there's rarely ever a time when you'd want to use it over some other way of saying it. I guess it's along the same lines as "don't end a sentence in a preposition".
Post reply on HN