Live data from Hacker News

A bite of Python

access.redhat.com

11–20 of 168 posts

Re: A bite of Python

#11

The behavior of 'assert' is not an anomaly. It comes from 'design by contract.' Assert is primarily meant to be documentation of constraints in code and secondarily a way of catching errors during development. "Contract conditions should never be violated during execution of a bug-free program. Contracts are therefore typically only checked in debug mode during software development. Later at release, the contract che…

It's not an anomaly, but it can be a surprise for people who don't understand what it does. For example, they use asserts for validation and then the validation doesn't work in production. It's absolutely right the way it works, but it's still a gotcha for the audience this blog post is aimed at.

Re: A bite of Python

#12
I love that the header and navbar is responsive, but the content itself is not.

Also input is truly baffling to me. Such a small mistake that could allow write access to your code.

Re: A bite of Python

#13

I love that the header and navbar is responsive, but the content itself is not. Also input is truly baffling to me. Such a small mistake that could allow write access to your code.

one of those little things that python 3 fixed.

Re: A bite of Python

#15

The behavior of 'assert' is not an anomaly. It comes from 'design by contract.' Assert is primarily meant to be documentation of constraints in code and secondarily a way of catching errors during development. "Contract conditions should never be violated during execution of a bug-free program. Contracts are therefore typically only checked in debug mode during software development. Later at release, the contract che…

> Assert is primarily meant to be documentation of constraints in code

Real or imagined constraints? AFAICT, an assert only tells me what you wish your program did, but that has absolutely no bearing on what it will actually do.

Re: A bite of Python

#16
The point the article makes on comparing floating point values and the floating point type is true, but it's not because of any rounding error.

It's because the comparison operators are defined for every value. That is, "True https://docs.python.org/3.0/whatsnew/3.0.html#ordering-compa...).

This is also not a case of Python doing something useful, like with '"foo"*2'. The result of the comparison is defined, but it's not useful. I suppose it was useful for making sure that you can always sort a list, but there are better ways to do that.

Re: A bite of Python

#17
The documentation of most modules cited in the article start with a paragraph in red and bold warning the reader of the same danger explained by the author. So this is a nice compilation, but nothing new and nothing somebody looking at the documention of the module he's using will miss.

There are nonetheless good remarks about poor design choices of Python which can lead to misconceptions to newbies, such as naming `input` the function that does `eval(raw_input(prompt))` (as casually documented[0]), and the existence of such function in a first place.

[0] https://docs.python.org/2/library/functions.html?highlight=i...

Re: A bite of Python

#18
post #11

The behavior of 'assert' is not an anomaly. It comes from 'design by contract.' Assert is primarily meant to be documentation of constraints in code and secondarily a way of catching errors during development. "Contract conditions should never be violated during execution of a bug-free program. Contracts are therefore typically only checked in debug mode during software development. Later at release, the contract che…

It's not an anomaly, but it can be a surprise for people who don't understand what it does. For example, they use asserts for validation and then the validation doesn't work in production. It's absolutely right the way it works, but it's still a gotcha for the audience this blog post is aimed at.

>It's not an anomaly, but it can be a surprise for people who don't understand what it does.

That's almost a tautology though.

Re: A bite of Python

#19

The point the article makes on comparing floating point values and the floating point type is true, but it's not because of any rounding error. It's because the comparison operators are defined for every value. That is, "True https://docs.python.org/3.0/whatsnew/3.0.html#ordering-compa... ). This is also not a case of Python doing something useful, like with '"foo"*2'. The result of the comparison is defined, but it'…

> The point the article makes on comparing floating point values and the floating point type is true, but it's not because of any rounding error.

Do you mean this example? (it's the only one I can find about floating point comparison)

> 2.2 * 3.0 == 3.3 * 2.0

It's definitely due to accuracy error. (rather than type comparison) How would you explain it otherwise?

Re: A bite of Python

#20

The behavior of 'assert' is not an anomaly. It comes from 'design by contract.' Assert is primarily meant to be documentation of constraints in code and secondarily a way of catching errors during development. "Contract conditions should never be violated during execution of a bug-free program. Contracts are therefore typically only checked in debug mode during software development. Later at release, the contract che…

> Assert is primarily meant to be documentation of constraints in code Real or imagined constraints? AFAICT, an assert only tells me what you wish your program did, but that has absolutely no bearing on what it will actually do.

Neither "real" nor "imagined".

An asserts checks DESIRED constraints.

>AFAICT, an assert only tells me what you wish your program did, but that has absolutely no bearing on what it will actually do.

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.

Post reply on HN