Find a legtitmate flaw, I dare you, Sup Forums

Find a legtitmate flaw, I dare you, Sup Forums

Other urls found in this thread:

mypy-lang.org/
twitter.com/AnonBabble

Python 3.

>>> def foo(bar: str) -> str:
... return bar*4
...
>>> foo('a')
'aaaa'
>>> foo(3)
12
>>>


this really bummed me out the other day

...

Whitespace.

>PEP 3107 -- Function Annotations
>By itself, Python does not attach any particular meaning or significance to annotations.
>The only way that annotations take on meaning is when they are interpreted by third-party libraries.

Performance

Other than that it's solid.

GIL
indentation determines code structure... LEL

Mypy seems to do what was hoping for.
>mypy-lang.org/

You write shitty code user?

Just because you are shit at managing whitespace does not make it a flaw.

>indentation determines code structure

This is literally the only good thing about it though. It's great because it forces fizzbuzzing interns to properly format their stupid code so that it is readable by non-autistic humans.

if bar.isinstance(str):
return bar*4

But I'm not arguing that your sentiment is wrong.

This. If you do not follow proper formatting, that is a problem with you, not the language.

What exactly did you want the intended behavior to be for a? Take the ASCII value of it and multiply it by 4? Being ambiguous with what you want will lead to problems in any language. That is just the standard thing people want when they say "multiply a character by 4."

If you really want that "strongly typed" feel then you should start using "assert."

assert type(bar) == str
Problem solved.

It's slow as piss. The fastest sieve I can manage, which I spend months tweaking, is barely under 300ms for limit=2e6. C-fags can sum the primes under 2 million in under a 1ms and laugh in my face.

I would expect it to throw a type error when "bar: str" is actually an int, and when the return value (again supposed to be a string) is an int

desu this shit is my only real complaint. python is a solid language.

Those annotations should really be enforced though.

it's slow.

post code

>Those annotations should really be enforced
No, they shouldn't, instead you should read the documentation before spewing. They're there so someone looking at the source or the docstring can get a quick handle on the argument and return type. If argument must be a string, then you use assert within the function. That way, you can catch assertion errors as well.

import array

def sieve(limit):
"""
Sieve of Eratosthenes.
Generate primes up to limit.
"""
if limit >= 2:
yield 2
sieve_limit = int(limit - 1) // 2 # Divide out even range, minus unit 1
x = array.array('B', [1])*sieve_limit
for i in range(sieve_limit):
if x[i]:
p = i*2 + 3
yield p
j = (p*p - 3) >> 1 # sqrt of p minus even range
if j < sieve_limit:
for k in range(j, sieve_limit, p):
x[k] = 0
else:
for k in range(i + 1, sieve_limit):
if x[k]:
yield k*2 + 3
return

numba.jit or pypy

>Won't be caught at compile/parse time

Trash

That's python for you. Learn how to read code more effectively and it won't happen to you as much.

That is the whole point, dumbass. Learn to code properly and you will not have an issue. You are complacent because you are used to languages finding all your shitty logical errors. Do not make errors and you will be fine.

>Dude just use assert bro

Yeah I mean it's not like people need efficient programs or anything. It's totally alright to waste processor power on resource heavy shit like assertion statements. I mean it's 2017 after all.

>Is worrying about excess processor use with Python

Do you also worry about your stove not cooling food for you?

check for the methods you need if you absolutely want a pretty error message, type() is usually wrong so stop thinking like a pajeet and use duck typing like intended

GIL niggers

So far nobody has posted a genuine flaw except run speed.

In real life, run speed is rarely important, although if it is then you should not be using a dynamic interpreted language in the first place. For critical bottlenecks in Python you can always drop to C.

In that example type() (or more correctly, isinstance()) is the ideal solution.

Think about it, he wants the function to return a str, and only a str, but his operation works on lots of different types. Explicitly testing for type is quicker and saner than try/excepting (e.g.) bar.lower() only to throw away the result.

so what you're saying is, I should pick Python back up and finish reading introducing Python

It's not perl.

print "flaw"

Found it

No macros, and even if it had one, it wouldn't be so nice to use because Python isn't homoiconic.

It's a feature retard

String times int n is the string repeated n times

Good god

Name one (1) problem with it. It's faster than any sieve in Python I've come across, it only checks odd numbers, and it's memory efficient due to using an unsigned char array for truth testing instead of builtin list.

>python2
Yikes.

it made it so n00bs could write code

If you genuinely need to invest any work into learning python, then I doubt you know any other language.

Literally anyone who wants to get paid to write any sort of code should learn python. It takes an afternoon to get a working understanding of it, and it greatly increases your employability.

I'm good until I get to flow control.

I meant pick it up again as in finish learning it. Previous job had me working weird hours and life happened. I'm only studying this as a hobby because I like the subject of programming.

are you... actually retarded?

he's not talking about 'a'*4 == 'aaaa'

he's talking about this not throwing exceptions.

>>> def foo(bar: str) -> str:
... return bar*4
>>> foo(3)
12

What does 'aaaa'/4 do?

TypeError: unsupported operand type(s) for /: 'str' and 'int'