Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
MeruFM
Jul 27, 2010
nevermind it's bad

Adbot
ADBOT LOVES YOU

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Skim Milk posted:

IS PYTHON BAD? [Y/n]

2 or 3?
yes and yes

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
that list thing wasn't very surprising. i wouldn't present it as a reason for why the language is bad.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
although "multiplying" lists to generate larger ones it pretty gimmicky

mystes
May 31, 2006

This behavior isn't at all surprising outside the context of python. Any language that has a way to pass a value to fill a list or array is going to have a problem with object references unless the array/list constructor deep copies the object by default. This is the biggest problem in Javascript, because the Array constructor specifically encourages you to make this mistake, but other languages that allow you to easily combine copies of references will have this problem to. In terms of other plangs, I just checked powershell actually has the exact same multiplication syntax with the same problem, although ironically its horrible automatic flattening of lists actually means you have to be really emphatic about keeping nested lists to have this problem.

The main problem in the case of python is that this syntax is actually considered the idiomatic way to make copies of lists of values (e.g. strings) in python, which is dumb considering this pitfall. The smart languages simply don't provide any obvious way to pass a single object to initialize an array/list, which at least makes it more likely that people will at least accidentally instantiate multiple copies.

Shaggar
Apr 26, 2006

Skim Milk posted:

IS PYTHON BAD? [Y/n]

very y

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

mystes posted:

This behavior isn't at all surprising outside the context of python. Any language that has a way to pass a value to fill a list or array is going to have a problem with object references unless the array/list constructor deep copies the object by default. This is the biggest problem in Javascript, because the Array constructor specifically encourages you to make this mistake, but other languages that allow you to easily combine copies of references will have this problem to. In terms of other plangs, I just checked powershell actually has the exact same multiplication syntax with the same problem, although ironically its horrible automatic flattening of lists actually means you have to be really emphatic about keeping nested lists to have this problem.

The main problem in the case of python is that this syntax is actually considered the idiomatic way to make copies of lists of values (e.g. strings) in python, which is dumb considering this pitfall. The smart languages simply don't provide any obvious way to pass a single object to initialize an array/list, which at least makes it more likely that people will at least accidentally instantiate multiple copies.

doesnt the c++ vector have a constructor that does that?


actually maybe i shouldn't be considering c++ among the "smart" languages

JewKiller 3000
Nov 28, 2006

by Lowtax
gosh it's almost like mutability is a low-level micro-optimization that should be handled by the compiler, rather than the biggest hammer in your programming language's abstraction toolbox that you pound the gently caress out of all your control flow with

Sapozhnik
Jan 2, 2005

Nap Ghost
full communism functional programming now

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

JewKiller 3000 posted:

gosh it's almost like mutability is a low-level micro-optimization that should be handled by the compiler, rather than the biggest hammer in your programming language's abstraction toolbox that you pound the gently caress out of all your control flow with

i'll mutate whatever the gently caress i want whenever i want you jackbooted fascist thug!

hobbesmaster
Jan 28, 2008

YeOldeButchere posted:

i'll mutate whatever the gently caress i want whenever i want you jackbooted fascist thug!

const_cast for the people!

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
no consts, no locks!

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
oh no now my compiler hasn't emitted the proper memory barriers and there's brutal fighting in my cores' caches over what should be trivial details! who could have seen this coming!?

MrMoo
Sep 14, 2000

Powerful Two-Hander posted:

now I've unfucked my solution..... is there a web graphing library that isn't a total pain to use?

c3 or d3?

Reuters has been working with the d3 team and making new HTML polymer objects for everything and it is starting to look incredibly nice.

JewKiller 3000
Nov 28, 2006

by Lowtax

YeOldeButchere posted:

i'll mutate whatever the gently caress i want whenever i want

YeOldeButchere posted:

oh no now my compiler hasn't emitted the proper memory barriers

have you ever considered the possibility of a causal relationship here

(i can't tell if you're joking or not. such is the state of the programming field)

LordSaturn
Aug 12, 2007

sadly unfunny

JewKiller 3000 posted:

have you ever considered the possibility of a causal relationship here

(i can't tell if you're joking or not. such is the state of the programming field)

pretty sure that was a joke

also if mutable vs. immutable isn't an important distinction in Python, then why have both tuple and list

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Mr Dog posted:

full communism and functional programming now

Luigi Thirty
Apr 30, 2006

Emergency confection port.

apparently cc65's assembler can target the 65816 but not its C compiler

annoying

the guy who wrote crapple's official Apple IIGS development environment 30 years ago still sells a package of all their native compilers, macro assemblers, utilities, and reference manuals for 25 bucks :pwn:

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

JewKiller 3000 posted:

have you ever considered the possibility of a causal relationship here

(i can't tell if you're joking or not. such is the state of the programming field)

ours is a universe where the thought "javascript on the server" doesn't seem to cause spontaneous combustion, so i can see how the confusion might arise

Sapozhnik
Jan 2, 2005

Nap Ghost
wasn't that a thing in Netscape's application server way back in the mists of time

VikingofRock
Aug 24, 2008




HappyHippo posted:

doesnt the c++ vector have a constructor that does that?


actually maybe i shouldn't be considering c++ among the "smart" languages

I thought C++ used the object's copy constructor to insert it into the vector (unless it's a vector of references), and copy constructors are supposed to provide deep copy semantics. So it actually wouldn't have this problem, right?

gonadic io
Feb 16, 2011

>>=

LordSaturn posted:

in case you're serious:

python's behavior is that all data is passed by reference at all times, but immutable types will make a new instance when you attempt to set them

integers are immutable so [x] * y makes a list of y distinct copies of integer x

lists are mutable so [a, b, c...] * y makes a list of y copies of a reference to [a, b, c...]

then when you subscript the mutable list and its mutable list child to set one immutable member, the correct operation is that the child list should replace the member with a newly-constructed immutable member. it just so happens that ALL the child lists are mutable references to the same data

EDIT: I bet I'm wrong about some of the details, like I know l1 = l2; l1 = [] will not delete l2. please pedant the poo poo out of my terrible post

i was serious yes, ty for this. while i have taught beginner python i don't really use it or know it

gonadic io
Feb 16, 2011

>>=

LordSaturn posted:

pretty sure that was a joke

also if mutable vs. immutable isn't an important distinction in Python, then why have both tuple and list

tuples have a statically known length, encoded in the typ....oh wait never mind

tuples are heterogeneous, i.e. different members can have different ty...poo poo never mind

you're not a cool modern lang unless you have tuples

VikingofRock
Aug 24, 2008




Soricidus posted:

wow both of you really overcomplicated your explanations by trying to introduce a non-existent distinction between immutable and mutable types.

the reason all the ints don't change isnt because python is magically making new ints, it's that you're not even trying to modify the ints. you're only modifying the lists.

python doesn't have any special concept of immutable types; the only reason things like tuples are immutable is because they don't implement any methods that modify them.

I never realized this. Thanks.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
hard to get excited about tuples unless your lang offers syntactic sugar around them

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

like what language

Xarn
Jun 26, 2015

VikingofRock posted:

I thought C++ used the object's copy constructor to insert it into the vector (unless it's a vector of references), and copy constructors are supposed to provide deep copy semantics. So it actually wouldn't have this problem, right?

C++ always uses value semantics unless you tell it otherwise, so yes. Also it won't let you create a vector of references, period, so you would have to gently caress up with pointer, but at that point, you are willingly trying to, so :shrug:.


Soricidus posted:

wow both of you really overcomplicated your explanations by trying to introduce a non-existent distinction between immutable and mutable types.

the reason all the ints don't change isnt because python is magically making new ints, it's that you're not even trying to modify the ints. you're only modifying the lists.

python doesn't have any special concept of immutable types; the only reason things like tuples are immutable is because they don't implement any methods that modify them.

code:
>>> a = ([], [])
>>> a[0] += [1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> a
([1], [])
>>>
:2bong:

This is actually my favorite "WTF are you doing Python?" snippet.

netcat
Apr 29, 2008

VikingofRock posted:

I thought C++ used the object's copy constructor to insert it into the vector (unless it's a vector of references), and copy constructors are supposed to provide deep copy semantics. So it actually wouldn't have this problem, right?

Luckily you cna't make a vector of references unless you wrap it in an std::ref or std::cref

Soricidus
Oct 21, 2010
freedom-hating statist shill

Xarn posted:

C++ always uses value semantics unless you tell it otherwise, so yes. Also it won't let you create a vector of references, period, so you would have to gently caress up with pointer, but at that point, you are willingly trying to, so :shrug:.


code:

>>> a = ([], [])
>>> a[0] += [1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> a
([1], [])
>>>

:2bong:

This is actually my favorite "WTF are you doing Python?" snippet.

+= may or may not modify the lhs in place, so it also tries to do a regular assignment. in this case the modification does happen in place but the assignment fails, so you get the results you see.

I'm not defending this but that's what's going on.

toiletbrush
May 17, 2010

MrMoo posted:

c3 or d3?

Reuters has been working with the d3 team and making new HTML polymer objects for everything and it is starting to look incredibly nice.
d3 seems pretty cool, I've only used it briefly but was able to knock up a decent reporting dashboard for a product demo really quick.

VikingofRock
Aug 24, 2008




Xarn posted:

C++ always uses value semantics unless you tell it otherwise, so yes. Also it won't let you create a vector of references, period, so you would have to gently caress up with pointer, but at that point, you are willingly trying to, so :shrug:.

Huh, I never knew that. I guess I just never tried to create a vector of references and always assumed you could.

quote:

code:
>>> a = ([], [])
>>> a[0] += [1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> a
([1], [])
>>>
:2bong:

This is actually my favorite "WTF are you doing Python?" snippet.

Okay WTF is going on here?

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
my coworkers have difficulties with some concepts of lazy loading. unfortunately i need the size of the result set regardless of only loading n results per page.

i asked one coworker to add a method to a rest interface to return the size of the data. he asked me why don't i just call the size method on the collection.

we also discussed why it sucks that we need the size of the result set (because the query to determine the size might be just about as heavy as the query to just get the data). so another coworker suggests that we just don't execute queries that match too many rows and instead show "too many results" on the ui.

cinci zoo sniper
Mar 15, 2013




VikingofRock posted:

Okay WTF is going on here?
one of these two
code:
>>> a = ([], [])
>>> a[0].append([1])
>>> print a
([[1]], [])
>>> a[1].append(1)
>>> print a
([[1]], [1])

redleader
Aug 18, 2005

Engage according to operational parameters

Powerful Two-Hander posted:

i have heard that there is a team at work that have written an xml import process in sql. unsurprisingly it fucks up all the time

this can probably be blamed on microsoft for giving sql server some pretty freakin good xml support. i can see the thought process too: "well, it's going to go into the database already, and it's already xml..."

for a feature that has no place in a loving database, sql server's xml facilities are astonishingly thorough and well-executed. however, i might be biased as i am intimately familiar with farting xml into and out of sql server

and at least within sql server, dynamic sql is your only option if you want to do some pivoting with data on the fly (i.e. given a set of pivot columns that are only known at runtime). we use dynamic sql (generated and executed in one stored proc) for exactly that reason, although it is (1) delicate (2) easy to gently caress up (3) a pain in the rear end to debug (4) basically black magic for the 90% of devs who are only casual to semi-professional sql users. i'd be interested to know if any other dbs do better with dynamic pivots

redleader
Aug 18, 2005

Engage according to operational parameters
a few years ago, we had a guy working on a big, important, visible project. his code went though uat just fine etc etc. he deployed it to production, and immediately maxed out the cpu on the db, bringing the site down

it turns out that every single stored procedure he'd written for that project used xml for input and output - exclusively. instead of passing an id in an integer parameter, he'd pass it in wrapped in an xml chunk and parse that out in the db, then return a blob of xml (which, of course, the application loaded into a string to pass around)

so instead of
SQL code:
CREATE PROCEDURE touch_butt (@butt_id INT, @is_sensual_touch BIT)...
SELECT cheek, firmness
FROM butts
WHERE butt_id = @butt_id
he'd go
SQL code:
CREATE PROCEDURE touch_butt (@data XML)...
DECLARE @butt_id INT = @data.value('//butt_id', 'INT')
DECLARE @is_sensual_touch BIT = @data.value('//is_sensual_touch, 'BIT')
...
SELECT cheek AS '@cheek', firmness AS '@firmness'
FROM butts
WHERE butt_id = @butt_id
FOR XML PATH('data'), ROOT('result'), TYPE
i can't remember if this pointless, verbose, cpu-burning overhead on every single db call ultimately turned out to be the root cause of the maxed database cpu, but holy hell it was irritating to work with

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

redleader posted:

it turns out that every single stored procedure he'd written for that project used xml for input and output - exclusively. instead of passing an id in an integer parameter, he'd pass it in wrapped in an xml chunk and parse that out in the db, then return a blob of xml (which, of course, the application loaded into a string to pass around)

his only mistake was using xml

if he'd done the same thing in json, he could have called his code "cilantrodb.js" and passed it off as a brilliant new noSql storage engine

hobbesmaster
Jan 28, 2008

NihilCredo posted:

if he'd done the same thing in json, he could have called his code "cilantrodb.js" and passed it off as a brilliant new noSql storage engine

this kills the shaggar

Bloody
Mar 3, 2013

loving hell this coworker

preaches a rewrite of our gui to c++ because ~its crossplatform~ and ~faster~ than c#

management bites because they don't know anything

coworker encounters endless bugs interfacing with our hardware and keeps blaming me, the guy who wrote the firmware (and also the c# library for interfacing with the hardware that hes too good to use and also the c# gui that was abandoned), demands i debug it

is just casually doing poo poo like using uninitialized array values, sending garbage data down the wire to our device
no poo poo it doesnt work
"this is a very high priority issue please fix"
resolution, provided by me, person who does not know c++:
for(auto i = 0; i < 20; i++)
{
butts[i] = 0;
}

i wanna run UBSan on this code base or something and print out the results and just leave it on management's desk

yes, by the way, this is (in theory, some day) for a medical device.

Mao Zedong Thot
Oct 16, 2008


hobbesmaster posted:

this kills the shaggar

if only

Adbot
ADBOT LOVES YOU

Bloody
Mar 3, 2013

of course, this is the same idiot coworker who doesn't think unit tests are a thing and insists that a dll is nothing (???)

  • Locked thread