MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/bun5px/dear_python2_user/epjhx3i/?context=3
r/Python • u/koungmeng • May 30 '19
275 comments sorted by
View all comments
Show parent comments
7
Maybe they aren't as useful as they could be, but how else could you write typed code without a performance penalty?
If you checked type at runtime everything would slow to a glacial crawl...
0 u/cj81499 May 30 '19 runtime type checking doesn't sound to me like something that would take a lot of time. Care to explain why you think this? 2 u/alkasm github.com/alkasm May 30 '19 Not for single objects, no---but think of data structures. Is it going to check that every element in a list is an int? What if the list has a million elements? 1 u/cj81499 May 30 '19 Suppose we have an array of type T, wouldn't running something likeif (type(element_to_add) != T): throw TypeErrorfor each insertion be enough? I can't imagine that having a huge performance impact. → More replies (1)
0
runtime type checking doesn't sound to me like something that would take a lot of time. Care to explain why you think this?
2 u/alkasm github.com/alkasm May 30 '19 Not for single objects, no---but think of data structures. Is it going to check that every element in a list is an int? What if the list has a million elements? 1 u/cj81499 May 30 '19 Suppose we have an array of type T, wouldn't running something likeif (type(element_to_add) != T): throw TypeErrorfor each insertion be enough? I can't imagine that having a huge performance impact. → More replies (1)
2
Not for single objects, no---but think of data structures. Is it going to check that every element in a list is an int? What if the list has a million elements?
1 u/cj81499 May 30 '19 Suppose we have an array of type T, wouldn't running something likeif (type(element_to_add) != T): throw TypeErrorfor each insertion be enough? I can't imagine that having a huge performance impact. → More replies (1)
1
Suppose we have an array of type T, wouldn't running something like
if (type(element_to_add) != T): throw TypeError
for each insertion be enough? I can't imagine that having a huge performance impact.
→ More replies (1)
7
u/[deleted] May 30 '19
Maybe they aren't as useful as they could be, but how else could you write typed code without a performance penalty?
If you checked type at runtime everything would slow to a glacial crawl...