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.
 
  • Post
  • Reply
Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

Rufo posted:

1. perl flattens arrays. ((1,2),(3,4)) means (1,2,3,4). this includes @_, the array of parameters received by a subroutine. so good luck passing two arrays, or anything more complicated, without the help of references

lol

Adbot
ADBOT LOVES YOU

Sang-
Nov 2, 2007

Rufo posted:

1. perl flattens arrays. ((1,2),(3,4)) means (1,2,3,4). this includes @_, the array of parameters received by a subroutine. so good luck passing two arrays, or anything more complicated, without the help of references

Curious to know why this is.

(I guess its because everything just gets pushed onto the stack? Which would explain why/how shift works.)

Rufus Ping
Dec 27, 2006





I'm a Friend of Rodney Nano

BonzoESC posted:

it was a rhetorical question,

yeah my reply was mainly for the benefit of people who dont know perl :)

BonzoESC posted:

$ref->{'whatever'}{'row'}{'column'} is objectively worse than ref['whatever']['row']['column']

took me a while to work out why, but now i agree wholeheartedly

BonzoESC posted:

everything in ruby is pass-by-reference-to-object
[] is just a method

yeah this is really neat and consistent

BonzoESC posted:

especially if the former is a world where "$arrayref->[123] meaning ${$arrayref}[123]" is true

not sure how this makes it worse than it otherwise is but w/e

MSPain
Jul 14, 2006
I don't see anything objectively wrong with being explicit about references, besides it being kind of annoying to learn. Javascript, for example, is clearly using references for arrays behind the scenes, but it pretends it's treating them the same way it treats scalars.

But then when you try to copy an array with arrOne = arrTwo Javascript gets all sheepish and says "well you see the thing about that is..."

HORATIO HORNBLOWER
Sep 21, 2002

no ambition,
no talent,
no chance
i start next week at my new job doing java and i keep thinking to myself hmm i should brush up on my java or something but i don't do it because honestly it's loving java how hard can it be

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

HORATIO HORNBLOWER posted:

i start next week at my new job doing java and i keep thinking to myself hmm i should brush up on my java or something but i don't do it because honestly it's loving java how hard can it be

its the deployment that's gonna kick your rear end

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome
probably

HORATIO HORNBLOWER
Sep 21, 2002

no ambition,
no talent,
no chance
i don't think that'll be my responsibility but ~~you never know~~

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>

HORATIO HORNBLOWER posted:

i start next week at my new job doing java and i keep thinking to myself hmm i should brush up on my java or something but i don't do it because honestly it's loving java how hard can it be

java is super easy. java ftw

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

ahhh spiders posted:

java is super easy. java ftw

:wth:

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>
java is cool because the complexity is in random things not working & gaps in cross-platform functionality, and also over-designed APIs

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Sang- posted:

Curious to know why this is.
it's because perl up to version 4 literally had no direct way to express a list of lists, so there was never any choice of what to do with nested lists other than flattening them

Stringent
Dec 22, 2004


image text goes here

Rufo posted:

took me a while to work out why, but now i agree wholeheartedly

idgi

Rufus Ping
Dec 27, 2006





I'm a Friend of Rodney Nano

its conceptually pretty neat to make everything an object and pass everything by reference and make [_] a method call rather than treating arrays as some special entity and managing ref/deref yourself. the way perl does things is a good solution, albeit a solution to a problem of its own creation.

i guess the ruby way means you need some kind of clone operation in the language though so maybe its not as neat and clean as it first appears. i dont know ruby

Stringent
Dec 22, 2004


image text goes here

Rufo posted:

its conceptually pretty neat to make everything an object and pass everything by reference and make [_] a method call rather than treating arrays as some special entity and managing ref/deref yourself. the way perl does things is a good solution, albeit a solution to a problem of its own creation.

i guess the ruby way means you need some kind of clone operation in the language though so maybe its not as neat and clean as it first appears. i dont know ruby

oh ok, i thought you meant there was something objectively better about the syntax itself.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Rufo posted:

i guess the ruby way means you need some kind of clone operation in the language though so maybe its not as neat and clean as it first appears. i dont know ruby

"clone" is a method implemented on Object and if you need a given class to always deep copy you can override "initialize_copy" to clone all its members

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Stringent posted:

oh ok, i thought you meant there was something objectively better about the syntax itself.

there's less of it

qntm
Jun 17, 2009

Sang- posted:

Curious to know why this is.

(I guess its because everything just gets pushed onto the stack? Which would explain why/how shift works.)

Because the same list syntax e.g. (1, 2, 3, 4) or (1 => 2, 3 => 4) is used to declare both arrays and hashes. Both of those expressions are the same list. => is just a synonym for ,. So Perl has no way of knowing whether a given list expression is supposed to declare an array or a hash, so it assumes neither and flattens the list out. There's probably a page and a half in Programming Perl where Larry Wall explains why this is actually completely intuitive and obvious and logical and useful.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

qntm posted:

Because the same list syntax e.g. (1, 2, 3, 4) or (1 => 2, 3 => 4) is used to declare both arrays and hashes. Both of those expressions are the same list. => is just a synonym for ,. So Perl has no way of knowing whether a given list expression is supposed to declare an array or a hash, so it assumes neither and flattens the list out. There's probably a page and a half in Programming Perl where Larry Wall explains why this is actually completely intuitive and obvious and logical and useful.
:catstare:

MSPain
Jul 14, 2006
hardest part about java is getting eclipse and all of its plugins to work on the first install, and then run smoothly on anything if you are doing tomcat at the same time.

Rufus Ping
Dec 27, 2006





I'm a Friend of Rodney Nano

qntm posted:

Perl has no way of knowing whether a given list expression is supposed to declare an array or a hash, so it assumes neither and flattens the list out.

eh lol no its essentially because this

Gazpacho posted:

it's because perl up to version 4 literally had no direct way to express a list of lists, so there was never any choice of what to do with nested lists other than flattening them

Rufus Ping
Dec 27, 2006





I'm a Friend of Rodney Nano

BonzoESC posted:

"clone" is a method implemented on Object and if you need a given class to always deep copy you can override "initialize_copy" to clone all its members

sounds good so far. whats the catch w/ ruby

jony neuemonic
Nov 13, 2009

Rufo posted:

sounds good so far. whats the catch w/ ruby

the ruby community

MSPain
Jul 14, 2006
chunky bacon lol

penus de milo
Mar 9, 2002

CHAR CHAR

fidel sarcastro posted:

the ruby community

"the ruby community" hasnt existed in the form you think it does since about 2008

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

MSPain posted:

hardest part about java is getting eclipse and all of its plugins to work on the first install, and then run smoothly on anything if you are doing tomcat at the same time.

imo the hardest part about java is knowing you could do the same poo poo with like 1/5th the typing in like python or ruby (or about a 1:30 ratio in clojure).

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>

trex eaterofcadrs posted:

imo the hardest part about java is knowing you could do the same poo poo with like 1/5th the typing in like python or ruby (or about a 1:30 ratio in clojure).

and no type checking

tef
May 30, 2004

-> some l-system crap ->

Rufo posted:

2. perl passes everything by value (when youre passing a reference youre still just passing a scalar by value)

um, perl is call by reference. python and ruby are call by object (i.e call by value where the value is a reference).

in perl you can write a subroutine called swap, and do swap($a,$b)

tef
May 30, 2004

-> some l-system crap ->

Rufo posted:

i only know a small amount of python but im reliably informed that

whoever told you this has no loving idea what they are talking about.

call by reference languages are not the same as call by values, where the values are references

tef
May 30, 2004

-> some l-system crap ->

quote:

the following types, and their subclasses, pass by reference:
list, dict, object (this includes all "new-style classes"), ClassType ("old-style classes")
and set
and functions

whereas these pass by value:
int, bool, tuple,
string,
unicode,
and a smattering of others

aka someone is full of poo poo. the first one is mutable and the second one is immutable.

seriously, it turns out that passing a reference to an immutable value is almost indistinguishable from passing that value. :q:


if you can do pass by reference, you can call a function swap(a,b) and that function can re-assign a,b within its scope and it affects the callee.

meanwhile, in a call by value language, you can't. perl and python are call by object value. so you pass a pointer/reference to the object to the function, and you can mutate what they point to, but you can't rebind the arguments.

what are they teaching you rufo :smith:

tef fucked around with this message at 02:14 on May 28, 2012

tef
May 30, 2004

-> some l-system crap ->
HAY IS JAVA CALL BY VALUE OR CALL BY REFERENCE

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>
i call huim hopkin green frog

double sulk
Jul 2, 2010

so the camel book is basically the k&r for perl right?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

tef posted:

um, perl is call by reference. python and ruby are call by object (i.e call by value where the value is a reference).

in perl you can write a subroutine called swap, and do swap($a,$b)

you used to be able to with evil.rb: http://www.koders.com/ruby/fid071535C0BD128E011EDCB3D9E4EFF0EE14607435.aspx#L464

Opinion Haver
Apr 9, 2007

Sulk posted:

so the camel book is basically the k&r for perl right?

yeah but much more in-depth

homercles
Feb 14, 2010

Rufo posted:

the short answer is "because you have to, because youre forced to handle references yourself, because of the way perl works"

specifically

1. perl flattens arrays. ((1,2),(3,4)) means (1,2,3,4). this includes @_, the array of parameters received by a subroutine. so good luck passing two arrays, or anything more complicated, without the help of references

2. perl passes everything by value (when youre passing a reference youre still just passing a scalar by value)

point #1 sounds like youre just working around a limitation of the language. arguably true but its not exactly hard to use [[1,2],[3,4]] or whatever. [] gives you a reference to an anonymous array. similarly the -> operator takes the pain out of dereferencing

id actually say #2 is a positive thing. you dont have to think wtf is happening when you call a subroutine. you know its all by value.
Not reeeaeaaaaally. This is recommended reading: http://perldoc.perl.org/perldata.html#List-value-constructors

Here's some fun:
code:
$ perl -le '%a = (1..100); print scalar %a'
33/64
:~$ perl -le '@a = (1..10); %a = (1..100); print scalar (@a,%a)'
33/64
$ perl -le '@a = (1..10); %a = (1..100); print (@a,%a)'
123456789106768333463642122717278171899100125556252627289596
838475765758616269705960495089903132353611125354919279808788
939477781314232465662930858639403497989105152414215164748818
27374373845461920434456
like tef said perl passes everything by reference what are you talking about. @_ is aliased to the incoming arguments.
code:
$ perl -e 'sub crash { $_[0]++ } crash(1)'
Modification of a read-only value attempted at -e line 1.
[e] table breaking

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

homercles posted:

Here's some fun:
code:
$ perl -le '%a = (1..100); print scalar %a'
33/64
:~$ perl -le '@a = (1..10); %a = (1..100); print scalar (@a,%a)'
33/64
$ perl -le '@a = (1..10); %a = (1..100); print (@a,%a)'
123456789106768333463642122717278171899100125556252627289596
838475765758616269705960495089903132353611125354919279808788
939477781314232465662930858639403497989105152414215164748818
27374373845461920434456

wtf

homercles
Feb 14, 2010

your first mistake was reading my post

tef
May 30, 2004

-> some l-system crap ->
Q: How many perl programmers does it take to change a light bulb?
A: HASH(0x814f708).

Adbot
ADBOT LOVES YOU

Opinion Haver
Apr 9, 2007

scalar %a is number of buckets in use/total available buckets, %a = (1..10) creates a hash mapping 1 to 2, 3 to 4, etc

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply