<eydaimon>
why do no style guides (except Erlang that I can find) have restrictions on the number of lines that a function is OK to have?
<eydaimon>
A function with too many lines is clearly unwieldly and breaks all kinds of rules of being modular
<Mon_Ouie>
I am against having a hard limit to the amount of lines in a method — because it ends up encouraging to write stupid code just to fit into that limit
areil has joined #ruby-lang
<eydaimon>
Mon_Ouie: there's never a hard limit, not even on the number of characters in a line. That doesn't mean 5,000 lines should be acceptable
spectra has joined #ruby-lang
nertzy has quit [Quit: This computer has gone to sleep]
<eydaimon>
There's a soft limit which is flexible based on readability.
<Mon_Ouie>
Well, I have seen people seriously suggest 5-line methods at most :p
<Mon_Ouie>
But in that case, I don't see what a style guide could say, other than "methods shouldn't be too long, based on common sense"
<eydaimon>
well, we're limiting character length to 80 based on a 80x25 terminal. Seems 25 lines is a pretty good guideline for functions
<eydaimon>
how often do you write methods which are longer anyway? When I do, I question implementation
<Mon_Ouie>
A common case of longer methods is a large when … then … list
certainty has joined #ruby-lang
<eydaimon>
you mean a case statement? Even those shouldn't need to be too long ... just put method calls when the conditionals are met
<eydaimon>
case value
<eydaimon>
when "blah"
<eydaimon>
method_here
<eydaimon>
end
<eydaimon>
i've never had the need to make those excessivly long anyway
banisterfiend has joined #ruby-lang
<Mon_Ouie>
I mean when there are more than 25 possible values
<eydaimon>
imperator: try simplifying the issue and get rid of some cruft. may help you find the problem
<imperator>
is that supposed to be a joke?
<eydaimon>
nope. you can get rid of the ffi stuff
<eydaimon>
it doesn't need to be there to prove your point
igotnolegs has quit [Quit: Computer has gone to sleep.]
<imperator>
eydaimon, i can't duplicate it outside of an ffi example
<imperator>
can you?
<eydaimon>
I don't know. but doesn't that tell you something?
<certainty>
:)
<imperator>
jesus, is that your idea of insight? you're pissing me off
<imperator>
NO SHIT
<certainty>
do have dup'ed strings references to their originals that a foreign function could mess with?
<Mon_Ouie>
:string is probably interpreted as const char* — so it may just pass the buffer used by the String object without bothering to copy it
<Mon_Ouie>
And since Ruby uses copy on write…
<Mon_Ouie>
Use an FFI::MemoryPointer instead, and write the string in it before passing it to your function
savage- has quit [Remote host closed the connection]
<certainty>
Mon_Ouie: but the buffer that is passed to the foreign function should be the one that comes from the dup'ed string. Do duped strings share structure?
<Mon_Ouie>
certainty: That's what copy-on-write is about
<Mon_Ouie>
They share the same buffer until one of them is changed
<imperator>
Mon_Ouie, yeah, that worked; thought i tried it before and failed, but i may not have .dup'd the arg before when i tried
<certainty>
Mon_Ouie: aha! Thanks for the clarification
<imperator>
eydaimon, THAT is my idea of insight
<imperator>
^^^^
<eydaimon>
imperator: if you had thought about it more, you could have realized it yourself with my insight
<Mon_Ouie>
imperator: Using the MemoryPointer you shouldn't need to dup anything
dc5ala has joined #ruby-lang
<imperator>
Mon_Ouie, yes; i don't know what i did wrong before :(
<eydaimon>
I've got a junior guy who keep implementing really long functions (500+ lines). I suggested he make them smaller and he made this really long convoluted excuse.
woollyams has quit [Ping timeout: 240 seconds]
Z33K|Lux has quit []
<eydaimon>
His code is really hard to follow. very very long lines, many many levels of indentation, the long functions, camelCased code, etc
<imperator>
testing usually cures that, not style guides
<eydaimon>
he doesn't believe in testing
<eydaimon>
that's another hurdle
JohnBat26 has joined #ruby-lang
zmack has joined #ruby-lang
<imperator>
doesn't believe in testing? a junior guy?
zmack_ has joined #ruby-lang
<imperator>
i haven't seen that attitude except from crusty old programmers from days of yore
<eydaimon>
imperator: junior PHP guy .... when I asked him about ruby, he said he doesn't like the ruby community. I forget what other BS he said.
<eydaimon>
But that was his excuse for not liking Ruby
<eydaimon>
smart guy, but junior
<eydaimon>
although my previous comment probably conflicts with the one above
<eydaimon>
hm. jQuery is the only coding standard I've seen that says tabs instead of spaces
boardyuk has joined #ruby-lang
workmad3 has quit [Read error: Operation timed out]
zmack has quit [Ping timeout: 264 seconds]
<imperator>
doesn't' like the community, oh lord
<imperator>
people get hung up on the weirdest stuff sometimes
<eydaimon>
no kidding
<imperator>
DHH said 'fuck' in a presentation, better switch to PHP
<eydaimon>
he worries about THAT, but is completely fine with no testing
JoshWines has quit [Ping timeout: 260 seconds]
<eydaimon>
imperator: sorry about earlier. I would have helped more if I knew. I was just hoping to get you thinking about the solution.
<imperator>
Mon_Ouie, think i was struggling with UTF-16LE before
dhruvasagar has joined #ruby-lang
wallerdev has quit [Quit: wallerdev]
fayimora has quit [Quit: Busy…..zzzzz]
dc5ala has quit [Quit: Ex-Chat]
slyphon has quit [Ping timeout: 245 seconds]
mssola has joined #ruby-lang
JoshWines has joined #ruby-lang
sepp2k has quit [Ping timeout: 260 seconds]
sepp2k has joined #ruby-lang
dc5ala has joined #ruby-lang
setmeaway2 has joined #ruby-lang
setmeaway has quit [Read error: Connection reset by peer]
wycats has quit [Excess Flood]
wycats has joined #ruby-lang
Criztian has joined #ruby-lang
tooky has joined #ruby-lang
Criztian has quit [Remote host closed the connection]
srbartlett has quit [Remote host closed the connection]
fgomez has quit [Ping timeout: 264 seconds]
kristofferrr has joined #ruby-lang
pemeon has quit [Ping timeout: 260 seconds]
boardyuk has quit [Ping timeout: 260 seconds]
boardyuk has joined #ruby-lang
krzkrzkrz has joined #ruby-lang
krz has quit [Ping timeout: 260 seconds]
krzkrzkrz is now known as krz
WillMarshall has joined #ruby-lang
pcboy_ has quit [Ping timeout: 245 seconds]
charliesome has joined #ruby-lang
gsav has quit [Ping timeout: 248 seconds]
pcboy_ has joined #ruby-lang
d3vic3 has joined #ruby-lang
gsav has joined #ruby-lang
concernedcitizen has quit [Remote host closed the connection]
perryh is now known as perryh_away
workmad3 has joined #ruby-lang
postmodern has quit [Quit: Leaving]
future_chimp has joined #ruby-lang
jarib has quit [Excess Flood]
sora_h is now known as s0ra_h
jarib has joined #ruby-lang
boardyuk has quit [Read error: Connection reset by peer]
lsegal has quit [Quit: Quit: Quit: Quit: Stack Overflow.]
boardyuk has joined #ruby-lang
boardyuk_ has joined #ruby-lang
boardyuk_ has quit [Read error: Connection reset by peer]
jxie has quit [Quit: leaving]
boardyuk_ has joined #ruby-lang
boardyuk has quit [Ping timeout: 248 seconds]
boardyuk_ has quit [Read error: Connection reset by peer]
perryh_away has quit [Ping timeout: 245 seconds]
boardyuk has joined #ruby-lang
perryh has joined #ruby-lang
gregmoreno has quit [Read error: No route to host]
boardyuk has quit [Read error: Connection reset by peer]
boardyuk has joined #ruby-lang
gregmoreno has joined #ruby-lang
krzkrzkrz has joined #ruby-lang
gsav has quit [Quit: Lost terminal]
gsav has joined #ruby-lang
neocoin has joined #ruby-lang
krz has quit [Ping timeout: 264 seconds]
krzkrzkrz is now known as krz
perryh has quit [Ping timeout: 248 seconds]
mjbamford has joined #ruby-lang
Caius has quit [Read error: Connection reset by peer]
Piglop has joined #ruby-lang
pajama has joined #ruby-lang
krz has quit [Quit: krz]
tonni has joined #ruby-lang
heftig has quit [Read error: Operation timed out]
boardyuk has quit [Read error: Connection reset by peer]
boardyuk has joined #ruby-lang
apeiros_ has joined #ruby-lang
neocoin has quit [Remote host closed the connection]
krz has joined #ruby-lang
face has joined #ruby-lang
chendo_ has joined #ruby-lang
tonni has quit [Ping timeout: 248 seconds]
the-newsman has joined #ruby-lang
neoesque has quit [Quit: Bye!]
tonni has joined #ruby-lang
boardyuk has quit [Quit: boardyuk]
heftig has joined #ruby-lang
cha1tanya has quit [Quit: आलोच..]
kedare has joined #ruby-lang
s0ra_h is now known as sora_h
x0F has quit [Disconnected by services]
x0F_ has joined #ruby-lang
x0F_ is now known as x0F
pajama has quit [Remote host closed the connection]
krz has quit [Quit: krz]
pajama has joined #ruby-lang
tonni has quit [Remote host closed the connection]
sora_h is now known as s0ra_h
mjbamford has quit [Quit: Leaving...]
mjbamford has joined #ruby-lang
neocoin has joined #ruby-lang
cha1tanya has joined #ruby-lang
cha1tanya has quit [Changing host]
cha1tanya has joined #ruby-lang
s0ra_h is now known as sora_h
neocoin_ has joined #ruby-lang
neocoin has quit [Ping timeout: 260 seconds]
woollyams has joined #ruby-lang
fromhet has joined #ruby-lang
<fromhet>
Hi! I am learning ruby, and am now working with file IO. If I in rib do "File.open('foo','w')", it obviously creates file 'foo' in the . directory. If I on the other hand type File.open('~/Desktop/foo','w') I get "Errno::ENOENT: No such file or directory - ~/Desktop/foo". Why is this? Can't I use ~ in ruby? What can I then use instead?
<crankharder>
[nil, nil, false, "a", 1].blah{|i| i} => "a"
<apeiros_>
.find
<crankharder>
now you've confused me... thats not what i want
DEac- has quit [Ping timeout: 248 seconds]
<crankharder>
[User, Event, Team, OtherARClass].blah{|k| k.find_by_id(some_id)} => first instance that's found
<crankharder>
e.g., i need the result of the block returned
<apeiros_>
you want some kind of map_find?
<crankharder>
i dont know what map_find is
pajama_ has joined #ruby-lang
pajama has quit [Read error: Connection reset by peer]
<crankharder>
it's functionally the same as select(&:stuff).first, but works like detect/find where it stops iterating after it finds a truthy result
verbad has joined #ruby-lang
<banisterfiend>
crankharder: it seems a kind of weird thing to want, cos the block you want to use both for its truthiness as well and for its actual object return value
<crankharder>
you're weird
<lianj>
^^
sailias has quit [Ping timeout: 260 seconds]
verbad has quit [Remote host closed the connection]
mistym has quit [Remote host closed the connection]
<banisterfiend>
workmad3: he wants this value: k.find_by_id(some_id)
<DefV>
crankharder: what you are describing (select.first) is .find
<banisterfiend>
rather than 'k'
<workmad3>
oh, bugger yeah
<workmad3>
bleh
<workmad3>
yeah, that's odd :P
<certainty>
:)
<apeiros_>
crankharder: you're contradicting your self
<apeiros_>
first you describe something that'd be select { … }.first (which find)
<banisterfiend>
crankharder: your hack is cool
<banisterfiend>
hehe
<apeiros_>
then you describe something that'd be map { … }.find
<apeiros_>
make up your mind
<crankharder>
yea i am, fail :(
<apeiros_>
your example is the latter
<apeiros_>
module Enumerable; def map_find; return enum_for(__method__) unless block_given?; each { |*a| result = yield(*a); return result if result }; nil; end; end
<banisterfiend>
apeiros_: check out this shit: callcc{ |back| ["y","x","foo"].each{ |elt| ((match = elt.match(/foo/)) && back[match]) } }
<apeiros_>
[User, Event, Team, OtherARClass].map_find { |k| k.find_by_id(some_id) } # should/would work the way you described it
<apeiros_>
banisterfiend: do continuations work in jruby yet?
<apeiros_>
but yes, I think earlier enumerators were cc based
<certainty>
i labeled it explictely as a hack. Please don't take it too serious
melter has quit [Remote host closed the connection]
<certainty>
continuations are slow (and at least in older rubies may leak memory), also i believe the will be removed? (in 1.9.3 you can have them if you require 'continuation' though
coryf has joined #ruby-lang
pajama_ has quit [Remote host closed the connection]
coryf has quit [Remote host closed the connection]
iamjarvo has joined #ruby-lang
DEac- has quit [Read error: No route to host]
DEac- has joined #ruby-lang
Defusal has quit [Quit: brb]
Defusal has joined #ruby-lang
<banisterfiend>
certainty: do you have a github account?
<certainty>
banisterfiend: yeah, but i do not do much there. I'm more a mercurial and thus a bitbucket guy
<banisterfiend>
certainty: what's your account name on those sites
<certainty>
banisterfiend: certainty
<banisterfiend>
thanks
<manveru>
certainty: continuations are now implemented in terms of fibers
yugui_zzz is now known as yugui
<certainty>
manveru: i see. Thanks for pointing that out
<manveru>
there was talk about deprecating them because it's impossible to implement them in some other interpreters, i think
imajes has quit [Excess Flood]
<manveru>
probably mostly relating to jruby
<andrewvos>
Hmm. I'm writing an app that periodically hits a whole lot of twitter users and stores their tweets in a database. I want to use resque to do this. Can someone suggest how to do this in terms of what tasks I would have?
<banisterfiend>
certainty: can u give me the bitbucketlink?
<andrewvos>
Do I have a task that spawns multiple tasks per twitter user for example?
imajes has joined #ruby-lang
<andrewvos>
Or just one task that does all of it?
<certainty>
banisterfiend: sure https://bitbucket.org/certainty. But you won't find much ruby there. It's mostly scheme and a bit of CL
<andrewvos>
bitbucket
henrikhodne has joined #ruby-lang
Jake232 has joined #ruby-lang
yugui is now known as yugui_zzz
concernedcitizen has joined #ruby-lang
concernedcitizen has quit [Changing host]
concernedcitizen has joined #ruby-lang
slyphon has joined #ruby-lang
hynkle has joined #ruby-lang
<workmad3>
andrewvos: either
<workmad3>
andrewvos: there's advantages, pitfalls and reasons for either approach
concernedcitizen has quit [Read error: Connection reset by peer]
suckerpunch has joined #ruby-lang
suckerpunch is now known as Guest40362
concernedcitizen has joined #ruby-lang
concernedcitizen has quit [Changing host]
concernedcitizen has joined #ruby-lang
sailias has joined #ruby-lang
Guest40362 has quit [Client Quit]
iamjarvo has quit [Quit: Computer has gone to sleep.]
apeiros_ has quit [Remote host closed the connection]
<andrewvos>
workmad3: Was just discussing this with a colleague. So if you have one task that launches multiple tasks then you have more chances to succeed.
<andrewvos>
workmad3: I'm now thinking one task to pull the json from twitter, and another to store in the databse.
cantonic has joined #ruby-lang
yugui_zzz is now known as yugui
mistym has joined #ruby-lang
mistym has quit [Changing host]
mistym has joined #ruby-lang
verbad has quit [Remote host closed the connection]
dv310p3r has joined #ruby-lang
Dreamer3 has quit [Ping timeout: 246 seconds]
lun_ has joined #ruby-lang
concernedcitizen has quit [Remote host closed the connection]
Dreamer3 has joined #ruby-lang
pajama has joined #ruby-lang
savage- has quit [Remote host closed the connection]
fromhet has quit [Quit: fromhet]
yugui is now known as yugui_zzz
bfreeman has quit [Quit: bfreeman]
JustinCampbell has joined #ruby-lang
henrik_hodne has joined #ruby-lang
henrikhodne has quit [Read error: Connection reset by peer]
<workmad3>
andrewvos: yes, but it also requires more resources... you mentioned database saving for example, so you'd need several connections, each one only saving a single user, rather than one connection batching a load together
<workmad3>
andrewvos: and it'll also depend on whether half of a thing should succeed :)
shevy has quit [Ping timeout: 260 seconds]
<andrewvos>
workmad3: haha good point
<workmad3>
andrewvos: hence why it's a 'either way can work' question ;)
<andrewvos>
So in this case I have to do twitter requests for a number of twitter accounts.
<andrewvos>
To get their tweets
<andrewvos>
So each request could potentially fail, but the others shoudl still continue on.
pajama has quit [Remote host closed the connection]
<workmad3>
andrewvos: and don't forget, retrieval and saving don't have to be synchronised... you could do something like - a set of tasks that are pulling down twitter users, and a periodic task that batch saves a load of retrieved users to the db
<canton7>
ridders24, the return value from the block is printed out. in ruby, if there's no explicit return statement, the last statement in the block is returned. here, it's the "G: ..." line. So you'll never get the "C: ... " line
<canton7>
as for newlines, I think you need to learn a bit of HTML before writing a website
<lianj>
[string_one, string_two].join("\n") # or join("<br />")
Hakon has quit [Quit: Leaving...]
alessio has joined #ruby-lang
rolfb has quit [Quit: Leaving...]
<ridders24>
lianj: would that not produce both results on the same line?
<shevy>
lianj! my brother!
<burgestrand>
ridders24: join("\n") concatenates the lines together with a newline between each one
apeiros_ has quit [Remote host closed the connection]
<burgestrand>
ridders24: however, in HTML it does not matter it will be printed on the same line anyway unless you’ve changed the text formatting
apeiros_ has joined #ruby-lang
apeiros_ has quit [Read error: Connection reset by peer]
apeiros has joined #ruby-lang
<ridders24>
that makes sence, I just dont understand how to scructure the page with sinatra. Off to google
apeiros has quit [Remote host closed the connection]
<burgestrand>
ridders24: sinatra has a good introduction document
<erikh>
andrewvos: I made this call for your video, so show me maybe?
carloslopes has quit [Quit: Leaving.]
mistym has joined #ruby-lang
mistym has quit [Changing host]
mistym has joined #ruby-lang
akira989 has quit [Remote host closed the connection]
akira989 has joined #ruby-lang
arooni-mobile has quit [Ping timeout: 260 seconds]
yugui_zzz is now known as yugui
woollyams has joined #ruby-lang
srbartlett has joined #ruby-lang
nertzy has joined #ruby-lang
Sambalero has quit [Remote host closed the connection]
s0ra_h is now known as sora_h
ilyam has joined #ruby-lang
lun_ has quit [Ping timeout: 248 seconds]
yugui is now known as yugui_zzz
arooni-mobile has joined #ruby-lang
seanstickle has joined #ruby-lang
postmodern has joined #ruby-lang
wpaulson has joined #ruby-lang
<andrewhl>
is it possible to use the map shorthand &: to do something like (1..10).map {|n| puts n}? (1..10).map {&:puts} doesn't work, since I guess .puts is not a method belonging to the current object
petercooper has joined #ruby-lang
<andrewhl>
i'm fine not using the shorthand for that kind of stuff. Just curious to know if there's some syntax I'm missing
<drbrain>
andrewvos: you'd need a wrapper method to swap the receiver and argument of puts
<drbrain>
this doesn't work either: Kernel.send :public, :puts; (1..10).map(&:puts)
tomb_ has quit [Quit: Computer has gone to sleep.]
deryl has quit [Quit: deryl]
<whitequark>
andrewhl: (1..10).map &method(:puts)
<andrewhl>
whitequark: awesome! thanks
<whitequark>
& does exactly this: invokes .to_proc on the passed value, extracts the InstructionSequence from the result (i.e. it _must_ be a Proc), and then passes resultant ISeq to the method in the implicit block argument position