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
Shaggar
Apr 26, 2006
you buffer the data that you are iterating over...

Adbot
ADBOT LOVES YOU

skeevy achievements
Feb 25, 2008

by merry exmarx

BonzoESC posted:

lots of that is comment

code:
i = (1..5).each
i.each { |n|
  puts n
}
groovy's the same but with more syntax
code:
i = (1..5).iterator()
for (n in i) {
  println n
}
yeah yeah i know shaggled again

eh in groovy just use a closure

code:
(1..5).each { i -> println i }
java exceptions were a big improvement over c++ if only because they gave a standardized way to report errors, they could get tedious if you were passing them up the chain but a) that's what tools are for and b) that's what architecture is for, you shouldn't be passing server file read exceptions up to your javascript widgets for handling anyway

using exceptions as signals ala python seems wrong unless they have a distinct mechanism for truly exceptional error states?

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

Internaut! posted:

eh in groovy just use a closure

code:
(1..5).each { i -> println i }
java exceptions were a big improvement over c++ if only because they gave a standardized way to report errors, they could get tedious if you were passing them up the chain but a) that's what tools are for and b) that's what architecture is for, you shouldn't be passing server file read exceptions up to your javascript widgets for handling anyway

using exceptions as signals ala python seems wrong unless they have a distinct mechanism for truly exceptional error states?

groovy's a little better than that
5.times { println it+1 }

Shaggar
Apr 26, 2006
ugh thats so grosssss

double sulk
Jul 2, 2010

Shaggar posted:

ugh thats so grosssss

shaggar was right

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

Sulk posted:

shaggar was right

says sulk

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

trex eaterofcadrs posted:

groovy's a little better than that
5.times { println it+1 }

if we're golfing it, ruby:

code:
puts *(1..5)

penus de milo
Mar 9, 2002

CHAR CHAR
please don't tarnish ruby's deserved reputation for writing expressive, literate code by giving in to the byte jockeys and their love for needless optimisation and unreadable "clever" code

skeevy achievements
Feb 25, 2008

by merry exmarx
eh assuming that reads "print all members of this set" that seems like good syntax to me

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Internaut! posted:

eh assuming that reads "print all members of this set" that seems like good syntax to me

it implicitly calls to_a (to array) on the range 1..5, expands it out into multiple arguments, and calls puts with them

code:
(1..5).map(&:even?) #=> [false, true, false, true, false]
casts the symbol :even? to a proc {|x| x.even? }, calls it with each entry in the range 1..5, and returns an array of the results

Shaggar
Apr 26, 2006

Internaut! posted:

eh assuming that reads "print all members of this set" that seems like good syntax to me

if you have to guess its bad syntax

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
you are allowed to write cute code in your language if everyone else is doing the same thing. i.e. it is idiomatic.

if "puts *(1..5)" is something you actually see often in "real" ruby code, then it's fine. i dont use ruby so my criticism doesnt count.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Shaggar posted:

if you have to guess its bad syntax

i dont understand this language i dont use, a blo bloo bloo

Opinion Haver
Apr 9, 2007

Shaggar posted:

you buffer the data that you are iterating over...

then you have to call has_next otherwise your code doesn't work, which is loving stupid, plus it means that anything that shows up between the call to has_next and next gets skipped

Shaggar
Apr 26, 2006
no i understand it. its just bad syntax

Shaggar
Apr 26, 2006

yaoi prophet posted:

then you have to call has_next otherwise your code doesn't work, which is loving stupid, plus it means that anything that shows up between the call to has_next and next gets skipped

of course you would call has_next, because you want to see if theres stuff available. not calling it would be idiotic. and anything that comes in between has_next and next is put at the end of the buffer in the order it came in. i mean, unles you're using really dumb poo poo like python where you can assume it does something horribly wrong.

Shaggar
Apr 26, 2006
although lets be honest an iterator is completely the wrong thing to use in that situation.

JawnV6
Jul 4, 2004

So hot ...
i fully expect these multiple statements in my high level language, possibly separated by control flow, to be atomic

Opinion Haver
Apr 9, 2007

Shaggar posted:

of course you would call has_next, because you want to see if theres stuff available. not calling it would be idiotic. and anything that comes in between has_next and next is put at the end of the buffer in the order it came in. i mean, unles you're using really dumb poo poo like python where you can assume it does something horribly wrong.

or instead of loving around with a buffer you could just throw an exception

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

JawnV6 posted:

i fully expect these multiple statements in my high level language, possibly separated by control flow, to be atomic

i want them to be useful, and it turns out that you can either not share anything (the right way) or use a bunch of janky ('cause they're easy to gently caress up) locking constructs to make them useful

JawnV6
Jul 4, 2004

So hot ...
lock bt[rs]l ought to be enough for anyone

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

JawnV6 posted:

lock bt[rs]l ought to be enough for anyone

anyone meaning implementors of compilers

erlang/otp supremacy

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
thought #lock cmpxchg8b was the lock hotness du jour

JawnV6
Jul 4, 2004

So hot ...
at the circus

for a clown to use

blorpy
Jan 5, 2005

you guys are arguing with shaggar. just fyi. didnt know if maybe you have usernames turned off or something

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

JawnV6 posted:

at the circus

for a clown to use

clownOS

penus de milo
Mar 9, 2002

CHAR CHAR

JawnV6 posted:

at the circus

for a clown to use

Shaggar
Apr 26, 2006

yaoi prophet posted:

or instead of loving around with a buffer you could just throw an exception

lol ya lets both use iterators for io and not buffer io - an idiot (aka python user)

skeevy achievements
Feb 25, 2008

by merry exmarx

BonzoESC posted:

i want them to be useful, and it turns out that you can either not share anything (the right way) or use a bunch of janky ('cause they're easy to gently caress up) locking constructs to make them useful

eh I look at actors in erlang/scala/clojure/etc and without looking too closely I know if they're both easy and foolproof there must be a catch and it's almost certainly performance

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Tiny Bug Child posted:

yeah strong typing rules i totally want my code to have more errors
i'm sure you'll agree with me that the main problem with php is that it does not treat every source file as a valid program

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Internaut! posted:

eh I look at actors in erlang/scala/clojure/etc and without looking too closely I know if they're both easy and foolproof there must be a catch and it's almost certainly performance

it probably is performance but the erlang app i work with is i/o bound not cpu bound so it's not that important

Sapozhnik
Jan 2, 2005

Nap Ghost
if you are iterating over something that's simultaneously changing while you're iterating over it then an iterator is probably not exactly the tool you want. no commonly used I/O system lets you send something to someone and then subsequently change your mind and un-send it. also if you really wanted to abuse iterators for I/O (let's make these completely different things look exactly the same) then you'd probably make next() block or something and only make has_next() return false on EOF.

if it isn't changing while you're iterating over it then constant data can't very well have a race condition can it (please don't bring up concurrent splay trees or something stupid like that)

C++ (ew) makes iterators pointer-shaped. Java's iterator interface uses hasNext() and next(). Literally every other imperative language with iterators manages to do this just fine without needing to use nonlocal jumps. Stop making up ridiculous contrived what-if cases to justify this design decision please.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Mr Dog posted:

also if you really wanted to abuse iterators for I/O (let's make these completely different things look exactly the same) then you'd probably make next() block or something and only make has_next() return false on EOF.

these are kind of the same thing though and it enables some cool stuff!

the "rack" http server protocol for ruby only requires that the response body respond to "each" and yield only String values to the block passed in to each

this means that regardless if your app is going to respond with "butts" or if it's going to stream a thing over a network you don't have to have the upstream app server know what's coming out (in the first case, the array of one string ["butts"]; in the second case, some kind of TCPSocket) or necessarily have your app buffer things

think of it as a duck-typed http://docs.oracle.com/javase/6/docs/api/java/io/Reader.html

Shaggar
Apr 26, 2006
in java low level inputstreams bring in raw bytes so u can just read them in (buffered or not) and throw them up to something smarter to figure out what they are.

although idk why you'd want a webserver that can read http but then also read some random protocol (on the same socket) like you're talking about?

Toady
Jan 12, 2009

nerds

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Shaggar posted:

you buffer the data that you are iterating over...
Here is an example iterator. How would you buffer it?

code:
import random, sys

def iter_and_maybe_die():
  while True:
    n = random.randint(0, 10)
    if n == 10:
      sys.exit()
    yield n

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>
my carefully constructed (contrived) edge case completely invalidates your tip that works most of the time :thumbsup:

blorpy
Jan 5, 2005

fuuuuuuuuuuuck.. holy shiiiiit


piiisssss

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

tef posted:

you call next() repeatedly until there is an error


deal with it

finding the end of an array is an exceptional condition

Adbot
ADBOT LOVES YOU

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome
lists end?!?. wait up here

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