[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Find a legtitmate flaw, I dare you, /g/

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 47
Thread images: 5

File: Python.png (76KB, 1890x800px) Image search: [Google]
Python.png
76KB, 1890x800px
Find a legtitmate flaw, I dare you, /g/
>>
>>60438133
Python 3.
>>
>>60438133
>>> def foo(bar: str) -> str:
... return bar*4
...
>>> foo('a')
'aaaa'
>>> foo(3)
12
>>>


this really bummed me out the other day
>>
File: 1489934174949.png (116KB, 500x464px) Image search: [Google]
1489934174949.png
116KB, 500x464px
>>60438145
>>
Whitespace.
>>
File: __SAD_FACE__.gif (377KB, 245x140px) Image search: [Google]
__SAD_FACE__.gif
377KB, 245x140px
>>60438289
>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.
>>
>>60438133
GIL
indentation determines code structure... LEL
>>
>>60438289
>>60438931

Mypy seems to do what >>60438289 was hoping for.
>http://mypy-lang.org/
>>
>>60439001
You write shitty code anon?
>>
>>60438574
Just because you are shit at managing whitespace does not make it a flaw.
>>
>>60439001
>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.
>>
>>60438289
if bar.isinstance(str):
return bar*4


But I'm not arguing that your sentiment is wrong.
>>
>>60439032
This. If you do not follow proper formatting, that is a problem with you, not the language.
>>
>>60438289
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."
>>
>>60438289
If you really want that "strongly typed" feel then you should start using "assert."
>>
>>60438289
assert type(bar) == str

Problem solved.
>>
>>60438133
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.
>>
>>60439093

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

>>60439117
>>60439122

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

Those annotations should really be enforced though.
>>
it's slow.
>>
>>60439180
post code
>>
>>60439183
>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.
>>
>>60439296
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
>>
>>60439180
numba.jit or pypy
>>
>>60439122
>Won't be caught at compile/parse time

Trash
>>
>>60439377
That's python for you. Learn how to read code more effectively and it won't happen to you as much.
>>
File: what-a-fucking-retard.jpg.png (261KB, 552x414px) Image search: [Google]
what-a-fucking-retard.jpg.png
261KB, 552x414px
>>60439377
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.
>>
File: normalfags45.jpg (12KB, 275x183px) Image search: [Google]
normalfags45.jpg
12KB, 275x183px
>>60438133
>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.
>>
>>60439543
>Is worrying about excess processor use with Python

Do you also worry about your stove not cooling food for you?
>>
>>60439543
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
>>
>>60438133
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.
>>
>>60439642
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.
>>
>>60440856
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
>>
>>60438133
No macros, and even if it had one, it wouldn't be so nice to use because Python isn't homoiconic.
>>
>>60439183
It's a feature retard

String times int n is the string repeated n times
>>
>>60439316
Good god
>>
>>60441222
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.
>>
>>60440978
>python2
Yikes.
>>
it made it so n00bs could write code
>>
>>60440956
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.
>>
>>60441584
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.
>>
>>60441166
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
>>
>>60438289
What does 'aaaa'/4 do?
>>
>>60441754
TypeError: unsupported operand type(s) for /: 'str' and 'int'
Thread posts: 47
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.