<baweaver>
So then, fun time, what is that doing? A Hash can take a block constructor that allows you to define the value for a missing key, a default if you will
JsilverT has joined #ruby
<baweaver>
That block is called the default_proc of the hash
<baweaver>
and since `h` in that block is the hash itself, you can borrow that block and make a new Hash with that same block indefinitely
<baweaver>
Now this isn't "true" autovivification as Perl would let you mix and match with Arrays. Ruby can only really get away with Hashes like this
cagomez has quit [Remote host closed the connection]
<RickHull>
It may be Monday, but the weather is beautiful here after a gray, drizzly weekend :)
<dminuoso>
RickHull, oh man
<dminuoso>
I prepared a gist about why some functional stuff was so awesome
<dminuoso>
Accidentally closed the tab and forgot what I wrote.
tamouse__ has quit [Ping timeout: 240 seconds]
<dminuoso>
Currying!
<RickHull>
i think there is a reasonable CLI interface to gists -- like setting up push/pull
<RickHull>
but I always just use the web ui
troys has joined #ruby
<RickHull>
oh, you can probably restore old tabs too
<dminuoso>
RickHull, in the end I just tried to point out how the function-returning perspective is so useful. How defc :eq { |a, b| a == b } is a "predicate constructor"
<dminuoso>
RickHull, I was drunk, didnt notice.
<RickHull>
shoot, maybe it never even happened ;)
milardovich has quit [Ping timeout: 240 seconds]
<dminuoso>
RickHull, so something like eq('foo') can be viewed as a partially applied equal test.
<dminuoso>
But if you look at what you get back, its just something of the shape: [String] -> Bool
<dminuoso>
err String -> Bool
raynold has joined #ruby
<dminuoso>
And we call this a predicate.
<RickHull>
overloaded term
<dminuoso>
We use this a lot in fact. For example in Array#filter
<RickHull>
in ruby
eckhardt has joined #ruby
<dminuoso>
RickHull, when I say eq, I mean extensional equality without looking into object id
<RickHull>
no, i mean as in predicate method like is_a?
<dminuoso>
RickHull, same exact thing!
<RickHull>
huh...
<dminuoso>
is_a? :: Module -> Bool
<dminuoso>
Its a predicate.
<RickHull>
the defining characteristic of returning a bool, isn't that just coincidental in your case?
<dminuoso>
No, thats what's called a predicate.
ta_ has joined #ruby
kinduff has joined #ruby
<dminuoso>
Anything that returns a bool is called a predicate.
<RickHull>
ok, I thought you were implying something else
<dminuoso>
So my point is just that defc :eq { |a, b| ... } taking two parameters can also be viewed in this JS notation
<dminuoso>
eq = (a) => (b) => a === b
<dminuoso>
so eq is just a function that takes an argument, and returns a predicate.
<dminuoso>
it literally constructs predicates.
<RickHull>
sure
<dminuoso>
RickHull, So how you do filter an array for an element that equals "foo" in the canonical way?
<dminuoso>
Just do the natural thing that comes to mind
<RickHull>
ary.select { |a| a == 'foo' }
<dminuoso>
Great.
<dminuoso>
Lets look at that. You called select, and (semantically) passed one argument: the block
<dminuoso>
{ |a| a == 'foo' } is just a very explicit construction of a predicate function.
<RickHull>
ary.select(&:eq('foo')) ?
<dminuoso>
You made a predicate function.
xco has joined #ruby
<RickHull>
ary.select(&:eq, 'foo') ?
<dminuoso>
And Im just saying, why not invent functions that construct them for you? It also saves you the trouble of finding a sensible name for that parameter
<dminuoso>
ary.select eq('foo') # would be kind of cool.
<RickHull>
yeah
jrafanie has joined #ruby
<dminuoso>
RickHull, you have been doing this style of function constructoin in a different space
<RickHull>
i think this is kinda how perl's map works?
vee__ has quit [Ping timeout: 248 seconds]
<dminuoso>
RickHull, [1,2,3], convert this into an array of strings, where each number gets converted to a string using .to_s
<dminuoso>
Using the short and elegant syntax.
<RickHull>
[1,2,3].map(&:to_s)
<dminuoso>
&:to_s can be viewed as a higher order function.
<dminuoso>
When invoked (through to_proc), it returns a function back (a Proc object).
<RickHull>
for ary.select eq('foo') -- is 'foo' a or b?
<RickHull>
what code is responsible for assigning the other value in the comparison?
<dminuoso>
RickHull, good question. Lack of expressive syntax means you have to rely on convention.
<dminuoso>
RickHull, eq curries.
<RickHull>
so something in select
<dminuoso>
RickHull, well select would have to be rigged to work with lambdas of course.
<dminuoso>
(Which my upcoming fp library does)
<dminuoso>
you could also do it the hard way ary.select &eq('foo')
<dminuoso>
but that'
dionysus69 has quit [Ping timeout: 248 seconds]
<dminuoso>
thats ugly
<dminuoso>
RickHull, think about what select does with your block
exhiled has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<dminuoso>
RickHull, it just *calls* it.
<dminuoso>
RickHull, so if eq('foo') returns a predicate (a _function_ returning bool), and select *calls* whatever you give it for each element..
<RickHull>
so 'foo' is a?
<dminuoso>
string
<RickHull>
and select provides b?
kapil___ has joined #ruby
<dminuoso>
RickHull, yes.
<RickHull>
ha, is a? xD
<dminuoso>
RickHull, in haskell you could do even do this with operators like: map (/2) [1,2,3,]
<dminuoso>
RickHull, this makes it quite obvious which "parameter" is not applied in (/2)
exhiled has joined #ruby
sinduck has quit [Ping timeout: 240 seconds]
pskosinski has quit [Read error: Connection reset by peer]
<RickHull>
I suppose it doesn't much matter which is which, but in the current version of select, select provides 'a' and the block locally defines b
biox has quit [Quit: Ping timeout (120 seconds)]
<dminuoso>
if the operator is commutative it does not. but in case for division it does.
exhiled has quit [Client Quit]
<dminuoso>
luckily you also come with a flip operator
<dminuoso>
(it just flips the argument of a 2-arity function)
biox has joined #ruby
pskosinski has joined #ruby
<dminuoso>
so you can always "apply the other one"
cagomez has joined #ruby
s2013 has quit [Max SendQ exceeded]
pskosinski is now known as Guest2039
<RickHull>
it's pretty neat, but what about barking up the wrong tree for a language without typed method signatures?
<dminuoso>
so if you wanted to divide an entire list by 2 element wise, you could do: [1,2,3,4,5].fmap flip(div).(2)
Scient has quit [Ping timeout: 240 seconds]
<dminuoso>
RickHull, in JS I have been using comments with haskell style type signatures
<RickHull>
i think, for readability, I like the ary.map { |i| i / 2 }
<dminuoso>
It works quite well to keep track on what types you have
<dminuoso>
RickHull, yeah this is not an ideal example.
RougeR has joined #ruby
RougeR is now known as Guest17442
cagomez has quit [Remote host closed the connection]
Scient has joined #ruby
sinduck has joined #ruby
Technodrome has joined #ruby
<dminuoso>
RickHull, let me find a real world example for you
7GHAA6JEP has quit [Quit: 7GHAA6JEP]
larcara has joined #ruby
exhiled has joined #ruby
exhiled has quit [Client Quit]
cagomez has joined #ruby
cagomez has quit [Remote host closed the connection]
cagomez has joined #ruby
vee__ has joined #ruby
urk187 has quit []
jrafanie_ has joined #ruby
roshanavand has joined #ruby
jrafanie has quit [Ping timeout: 268 seconds]
elphe has joined #ruby
<RickHull>
no need, really -- I'm more or less a true believer, except I prefer to do this stuff in Elixir, where the language is more encouraging of this style
<RickHull>
I think Elixir is better suited for large, more complex apps, where the work types do is worth their expense
orbyt_ has quit [Ping timeout: 248 seconds]
<RickHull>
and Ruby is more optimized for smaller libs and microservices, where the API is the unit of abstraction
<RickHull>
somewhat more expressive in the procedural realm
<dminuoso>
This is made up and can be tweaked in a few ways.
d5sx43 has joined #ruby
<dminuoso>
But almost every function in there is only partially applied to obtain the "build me a function of some shape with desired behavior" semantics
d5sx43 has quit [Client Quit]
<RickHull>
I like the general structure here, building up
<RickHull>
i don't quite follow L22
<RickHull>
what is postsL and special path?
<dminuoso>
postsL is a lens.
exhiled has joined #ruby
<RickHull>
i thought so :/
<dminuoso>
They are functions of a very special kind. Basically think of them as something like XPath
<dminuoso>
But without the ugliness. You can create them through functoinal means, compose them
<dminuoso>
And do a lot of extremely wild things.
<RickHull>
sounds a bit like the C# thing, LINC?
<RickHull>
whatsitcalled?
<dminuoso>
mmm no.
<havenwood>
LINQ
<dminuoso>
RickHull, think closer to like... imagine you have a huge nested hash with arrays and more hashes and so forth.
<RickHull>
running into a lens there is like going down a nice path in the woods with berries and squirrels and running into a bear
milardovich has joined #ruby
<dminuoso>
RickHull, and for some reason you are only interested in one particular point of the structure
<dminuoso>
perhaps you want to look at it, or modify it.
<RickHull>
yeah, that makes sense
<dminuoso>
and a lens is just the "point at the thing"
<RickHull>
it's ugly and hacky trying to that in a general way with basic ruby
<dminuoso>
Yup.
<dminuoso>
over/set/view take a lens and then either update/set/look at that point the lens points at.
<dminuoso>
And like in optics, you can chain lenses to combine their effects.
muelleme has joined #ruby
jackjackdripper has joined #ruby
conta2 has joined #ruby
<dminuoso>
RickHull, this dealing with nested structures is one of the more painfully things to do in traditional ruby. you frequently end up using highly imperative code that suggests the structure
<RickHull>
my hesitation here is that maybe deeply nested structures aren't that great to reason about in general
<RickHull>
maybe rather than sharper tools, we should compose the problem differently
<RickHull>
to reduce the deep nesting
<dminuoso>
RickHull, you get them everywhere. Not many APIs follow JSON:API. So there better be an elegant way to deal with it.
jackjackdripper has quit [Client Quit]
<dminuoso>
RickHull, its the same need how css selectors and XPath have been invented
jackjackdripper has joined #ruby
<dminuoso>
the need to somehow find expressive ways of describing "how something can be found" from code.
milardov_ has quit [Ping timeout: 240 seconds]
<dminuoso>
*and decoupling it from code
tcopeland has joined #ruby
<RickHull>
FWIW, i haven't felt tempted to use XPath in a long time. though maybe it's from prior trauma at working with deeply nested structures.
<dminuoso>
RickHull, its essentially the same reason why you dont use for to iterate over arrays. You use map.
<RickHull>
I haven't written many functions that take more than a 2 dim array either
Dimik has joined #ruby
<RickHull>
i'll rely on the caller to give me something simpler
Guest17442 is now known as Rouge__
Technodrome has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<dminuoso>
RickHull, another great thing about lenses is that it allows you to express how to access a certain portion of an object in a uniform manner.
<dminuoso>
No longer do you have 17 source files all doing their own iteration and inspection
<dminuoso>
You just share a set of single lenses that you can combine.
<RickHull>
that seems sensible
<dminuoso>
And in a way that both parties interested in mutating as well as viewing are using the same exact code.
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
conta2 has quit [Ping timeout: 258 seconds]
Technodrome has joined #ruby
<RickHull>
the worst part about deeply nested structures is that assumptions get made, and you address something like foo.bar.internals.undercarriage.drivetrain.hub.bearing
exhiled has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<RickHull>
and then the domain model shifts slightly
<dminuoso>
And better yet, if the structure is renested somewhere else, combining their lens with yours is as simple as: myLensL * yourNestedObjL
<dminuoso>
Tadaa, done.
<dminuoso>
New lens created.
larcara has quit [Remote host closed the connection]
<dminuoso>
RickHull, yup
<dminuoso>
RickHull, and now to make things interesting, optics allow you to sneak in Maybe
<dminuoso>
RickHull, so suddenly you can sanely deal with "but what if internals does not exist?"
<dminuoso>
but in a meaningful and expressive way.
larcara has joined #ruby
<dminuoso>
The usual way would be to start foo.bar.internals.undercarriage&.drivetrain&.hub&.bearing. But what if you also want foo.bar.internals.undercarriage.drivetrain.hub.master?
hutch34 has quit [Ping timeout: 246 seconds]
<dminuoso>
And what if there's an array or hash in between. &.[](0) is anything but sexy.
<dminuoso>
These are not made up, I've dealt with this many times with deeply nested structures, where the structure might depend on values. Where intermediate path segments might not be present.
<RickHull>
another way to do it is to just deal with a Drivetrain, and let some outer layer do a lot of nil checking and fail fast if the model has clearly shifted
<RickHull>
yeah, arrays get gross -- you almost always have to take the first, but wonder if that's correct
lagweezle_away is now known as lagweezle
tcopeland has quit [Quit: tcopeland]
<dminuoso>
RickHull, and now you maybe want to traverse over intermediate paths.
<dminuoso>
say you have this rigorous foo.bar.internals.undercarriage.drivetrain.hub.bearing structure
<dminuoso>
and internals is an array.
<dminuoso>
and you want an array of all bearings.
<dminuoso>
Which may or may not exist
<RickHull>
so maybe use relational algebra?
exhiled has joined #ruby
exhiled has quit [Client Quit]
<dminuoso>
RickHull, right. So you quickly start to explore things that act lawful.
<dminuoso>
Things that compose.
<dminuoso>
Things that express.
<dminuoso>
Lenses are in that box of solutions that fit.
<RickHull>
but relational algebra is an argument against hierarchical models, right?
<RickHull>
an alternative to deeply nested structures?
mikecmpbll has quit [Quit: inabit. zz.]
nogic has joined #ruby
zarubin1 has quit [Quit: Leaving.]
<dminuoso>
RickHull, again. What if you have an API just gives you these deeply nested structures?
<dminuoso>
Especially with web APIs this happens so frequently its not funny.
<RickHull>
use a different API, I say!
<RickHull>
agreed :)
zarubin1 has joined #ruby
hutch34 has joined #ruby
zarubin1 has quit [Client Quit]
LocaMocha has quit [Ping timeout: 248 seconds]
<RickHull>
the tricky part with arrays in the middle of a hierarchy, is that one tends to want to address leaves
bmurt has joined #ruby
larcara has quit [Ping timeout: 258 seconds]
<RickHull>
in a static-looking way
<RickHull>
but almost always you need a function to properly select the array member
<RickHull>
and #first gets used by default
<RickHull>
and what if two members pass the filter?
<RickHull>
your address starts to become unreasonable
kozrar has joined #ruby
<RickHull>
or else encodes unreasonable assumptions
<dminuoso>
RickHull, Im not saying the imperative approach is wrong or unsustainable. But FP is equipped with certain things that have universal "go through an enumerable set of things, and then do transformations with effects"
kozrar has quit [Remote host closed the connection]
<erciccione_[m]>
I already asked on /r/ruby and /r/learningruby, but haven't got many answers yet. My main concern is the overall structure
<dminuoso>
they are called traversals, and if you have any compsci background (your programs imply you do), then you will recognize this in tree traversals.
hutch34 has quit [Ping timeout: 258 seconds]
<dminuoso>
Hiya erciccione_[m], and welcome to ruby :)
<dminuoso>
RickHull, ^- hah you see that? Lots of probing into structures!
<erciccione_[m]>
Thanks Hiya! ( no '_[m]' needed ;) )
<dminuoso>
erciccione_[m], my tab completion does this on its own.
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tomphp has joined #ruby
cseder has joined #ruby
<dminuoso>
erciccione_[m], which languages do you come from?
<RickHull>
erciccione_[m]: proper indentation would help
<erciccione_[m]>
dminuoso: yes i guess IRC doesn't understand that [m]
<dminuoso>
erciccione_[m], if this is truly your first program, I don't think there's too many things to critize, except the complete disregard of ruby's object oriented nature.
<dminuoso>
erciccione_[m], it's part of your nickname currently.
<erciccione_[m]>
sorry i have no it background
<dminuoso>
erciccione_[m], does it work™?
cseder has quit [Client Quit]
<erciccione_[m]>
yes, I still need to properly understand that. [m] is because I'm using matrix/riot
<RickHull>
dminuoso: well, my sense that when you have a tree with millions of items, very small perturbations to how operations are performed can have massive performance and resource implications
<dminuoso>
erciccione_[m], then feel free to ignore it.
tcopeland has joined #ruby
cseder has joined #ruby
<dminuoso>
RickHull, granted. I would not use my FP style to write high performance ruby code.
<dminuoso>
But then again I wouldn't be writing it in ruby in the first place.
<RickHull>
and so when you have such trees or structures at very large scale, you use tools that help with that. and ruby probably isn't one of them
<dminuoso>
RickHull, and then FP languages are back in the game.
<RickHull>
yep
<RickHull>
so when I choose ruby to tackle a problem, it's usually because I'm optimizing for expressiveness, and that means I can shrink the scope to something manageable
<dminuoso>
RickHull, my Haskell experience is quite early. But I find that Haskell offers me a higher level of expressiveness through higher order functions and the incredibly amazing type system.
<RickHull>
and if I get back a big terrible undercarriage thing, I'll use a disciplined procedural approach to validate its structure and fail fast if it doesn't meet the assumptions
<erciccione_[m]>
dminuoso: thanks btw, will better check the indentation and object programming
<RickHull>
dminuoso: agreed
kyrofa has joined #ruby
<dminuoso>
erciccione_[m], be sure to check out the books link in the topic. It has some great resources for learning.
imode has joined #ruby
<RickHull>
but Haskell and FP are also very sensitive to small perturbations, where something that basically looks right does unexpected stuff
<dminuoso>
RickHull, something like Monoid m => [m] -> [m] tells me a lot of things without even seeing the *name* of the functions.
<erciccione_[m]>
dminuoso: will do!
<dminuoso>
RickHull, parametricity tells me so much about what laws this *must* hold.
<kyrofa>
Can anyone explain to me how Ruby determines its arch-specific RUBYLIB path?
<dminuoso>
RickHull, like its fundamentally impossible for that to not adhere to certain laws.
<AliasSpider>
ᦡ
ur5us has joined #ruby
tvw has quit [Remote host closed the connection]
<dminuoso>
RickHull, well any programming language has that.
<RickHull>
dminuoso: that is true, but with Ruby, it's easier to mentally trace what the code does. Haskell requires a big load of the haskell model into the reader's brain
<dminuoso>
RickHull, but a rigid type system catches errors.
<kyrofa>
On amd64 it ends up with ruby/2.4.0/x86_64-linux, for example. However, on my raspberry pi it ends up with ruby/2.4.0/armv7l-linux-eabihf
<RickHull>
agreed, I am more of a fan of types now
<dminuoso>
RickHull, this "type correctness does not provide validity" is silly in two important ways: With parametricity you actually can prove validity in some cases. And more importantly: if your program does NOT typecheck it *IS* wrong.
<RickHull>
kyrofa: it is probably part of the compile time options for the ruby interpreter
<kyrofa>
RickHull, right, I'm building from source with no options
<dminuoso>
I have spent numerous times debugging the wrong library, because duck typing allowed a faulty object to be passed in the wrong spot. And for some reasons it wasnt until in some seemingly unrelated code it explode.
<RickHull>
kyrofa: have you looked at $LOAD_PATH as well?
<RickHull>
kyrofa: you may want to look at what ruby-build and ruby-install projects do
Technodrome has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<kyrofa>
RickHull, I'm really just trying to figure out where the eabihf comes from.
<dminuoso>
RickHull, I mean a trivial example: imagine a maximally malicious implementatoin of Enumerable where #each will at random yield and *then* delete an object.
<RickHull>
kyrofa: uname maybe?
<dminuoso>
Making sure that something like #filter would produce hilarious results.
claudiuinberlin has joined #ruby
vipaca has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Papierkorb>
dminuoso: read-only "variables" are part of the memory model used, not directly the type system
<Papierkorb>
Though not being able to type in ruby is the biggest disvantage of the language.
Asher has quit [Ping timeout: 246 seconds]
vipaca has joined #ruby
<dminuoso>
Papierkorb, that depends. There are typesystems where side-effects *have* to reside in special types.
<dminuoso>
(Which allows you to look at a functions return type and see whether it has effects or not)
<Papierkorb>
ah sure, the memory model and type model interact quite heavily
<RickHull>
dminuoso: my sense is that going full-retard-FP has downsides that are mitigated by a type system. so I want to add FP sensibility to my ruby programs where it helps expressiveness. but Lenses without types might be more trouble than worth
<dminuoso>
RickHull, I agree that its difficult to use right without a type system because you often wont understand what went wrong.
FrostCandy has joined #ruby
<dminuoso>
It makes it difficult in JS, but it is doable with some discipline.
vipaca has quit [Client Quit]
<dminuoso>
(Though flow can give you a lot back)
<dminuoso>
Papierkorb, this is something elixir has done right with protocols.
<dminuoso>
RickHull, its also called "concepts", "typeclasses", "protocols"
<dminuoso>
but they are all the same idea.
troys is now known as troys_
<dminuoso>
RickHull, an example of using this would be: Ord a => [a] -> [a] which is saying: this works with anything that has Ord (which means objects of that typeclass are orderable). This strongly implies that whatever the function does, its very likely ordering related.
<Papierkorb>
Crystal is 100% statically typed, even if the code (sometimes) doesn't look like that at all (Which is awesome). We don't have a "VM" under us while executing code
<AliasSpider>
ᖤ
Technodrome has joined #ruby
^mtkd has quit [Ping timeout: 240 seconds]
<dminuoso>
It does not care what it gets, as long as whatever type you pass it has been declared an instance of Ord (and by doing that you have to implement a method for comparing two objects)
<Papierkorb>
dminuoso: Are you impressed by that?
vipaca has quit [Client Quit]
<dminuoso>
Papierkorb, no but only because I already knew crystal compiled to LLMV :P
mtkd has joined #ruby
<Papierkorb>
I mean, that's a normal feature for a statically typed language I guess
milardov_ has joined #ruby
<dminuoso>
Papierkorb, but type inference (what you meant by "doesnt look like that at all") is what makes rigid type systems usable.
larcara has joined #ruby
<Papierkorb>
Yes
<dminuoso>
Being forced to be fully explicit is what makes Java so absolutely disgusting.
<RickHull>
dminuoso: would Crystal be a better substrate for a ruby-like FP adventure?
<Papierkorb>
It's .. among the issues of the Java language lul
<dminuoso>
RickHull, if you want something with static types yes.
<RickHull>
how about types at all?
<dminuoso>
RickHull, elixir would be another option (but that has.. no real types.. well. it does)
vipaca has joined #ruby
<RickHull>
are Haskell types static?
<dminuoso>
RickHull, ruby has types.
<Papierkorb>
RickHull: There's #crystal-lang on Freenode where we hang out
Asher has joined #ruby
<RickHull>
Papierkorb: we've chatted in there in the last month ;)
<dminuoso>
RickHull, yes. Haskell is strongly and statically typed.
<Papierkorb>
Yeah I wasn't sure RickHull :P
<RickHull>
I'll be back
<dminuoso>
RickHull, Haskell has no "type conversion" except in some special spots with language extensions turned on.
<dminuoso>
RickHull, instead Haskell has something better. Polymorphic types.
<waveprop>
does an undergrad CS degree usually cover theory of computation, automata, like the Hindley-Milner etc
hutch34 has joined #ruby
<waveprop>
s/like the//
<RickHull>
waveprop: yes, though I didn't study H-M
<dminuoso>
waveprop, HM would only appear in specialized courses.
tcopeland has quit [Quit: tcopeland]
milardovich has quit [Ping timeout: 258 seconds]
<RickHull>
dminuoso: so wouldn't Crystal be more suitable than Ruby for this effort?
<waveprop>
ok cool. might enroll then
<dminuoso>
RickHull, I feel that Elixir has more application in industry high-performance/high-availability situations to the richness of OTP
<waveprop>
thx guys
<Papierkorb>
Elixir is more "appropriate" if you want to learn something to get a job now
<RickHull>
I don't disagree, but that's a different question ;)
<RickHull>
OTP plus pattern matching and abandoning some OOP handcuffs
<dminuoso>
RickHull, but crystal does not come with any of those fancy FP paradigms. What you get is a cleaned up language with a fast implementation, no "oops. someone just monkey patched String" situatoins
<dminuoso>
Its the Ruby that should have been.
<dminuoso>
From what I can tell.
<dminuoso>
Papierkorb should know more
<RickHull>
sure, and real types
<RickHull>
with enforcement and signatures
vipaca has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Papierkorb>
I like FP as far it actually helps me. After that, nah.
kyrofa has left #ruby ["Leaving"]
<dminuoso>
RickHull, dont ever try out dependent types.
<dminuoso>
Im now jealous to not have them everywhere.
vipaca has joined #ruby
<dminuoso>
Saw this amazing presentation of a PhD I think, who built a custom regex implementation that matched some simple string, and then demonstrated "it works"
<RickHull>
my main exposure to types is via Elixir a few years ago -- I'm surely still a type klutz
<Papierkorb>
#map and friends is good shit. Maybe at some point we get more rich guardy-clauses to do `def foo(0); 1; end; def foo(n) foo(n-1)*n; end`
<Papierkorb>
but that's already cutting it, and I don't like that example
<dminuoso>
Papierkorb, I think the expressivity falls down if you dont have = notatoin
<Papierkorb>
= notation?
<dminuoso>
f 1 = 2 makes a lot of sense in the mathematical way
<Papierkorb>
Programming isn't math
<dminuoso>
def foo(0) 1; end
<dminuoso>
does feel like noise
<Papierkorb>
Because that's not what you write
<Papierkorb>
If something feels wrong, it's usually because it's wrong
<dminuoso>
Papierkorb, no its just a syntax issue
armando has quit [Ping timeout: 248 seconds]
<dminuoso>
Papierkorb, I mean Im deeply used to it from template specialization in C++, but its harsh to read
airdisa has joined #ruby
<RickHull>
good languages guide you to do the right thing, where an approach feels good or bad
<RickHull>
but syntax is more of a taste thing, and your tastes adjust
armando has joined #ruby
dviola has quit [Quit: WeeChat 1.9.1]
<dminuoso>
<Papierkorb> #map and friends is good shit. Maybe at some point we get more rich guardy-clauses to do `def foo(0); 1; end; def foo(n) foo(n-1)*n; end`
<dminuoso>
And is this not induction?
<dminuoso>
Thats very mathy!
eckhardt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<havenwood>
Multi-methods!
<Papierkorb>
dminuoso: What, that I used a sample which I even wrote I don't like?
<dminuoso>
heh
<Papierkorb>
Sure you can reduce everything to 1s and 0s
<Papierkorb>
You don't have to.
muelleme has joined #ruby
<Papierkorb>
The problem with the math-only view is that more often than not, it only focuses on the local issues, and completely disregards the global issues
jrafanie_ has quit [Remote host closed the connection]
<havenwood>
Papierkorb: multimethods could theoretically be added just as a different class of method
<havenwood>
Papierkorb: like clojure's defmulti
<dminuoso>
Papierkorb, I dont think that really applies.
jrafanie has joined #ruby
airdisa_ has quit [Ping timeout: 250 seconds]
PaulCapestany has quit [Read error: Connection reset by peer]
<dminuoso>
Papierkorb, I rather tend to view it the different way around. The reason is that imperative languages constantly force you to think what happens in the smallest scale.
<dminuoso>
Papierkorb, but in FP you construct complexity by building functions together. So at each step you grow into a larger scope
<Papierkorb>
dminuoso: I'm a low level guy. I want to know what happens there.
hutch34 has quit [Ping timeout: 252 seconds]
<dminuoso>
Papierkorb, oh thats fair enough.
<Papierkorb>
And yeah, that's what you do in imperative or OOP too.
<dminuoso>
Papierkorb, Im not saying it's wrong, because thousands of software projects demonstrate that you can successfully write programs that way.
michael3 has joined #ruby
tcopeland has joined #ruby
<dminuoso>
Papierkorb, yup. I mean ultimately you compose by using routines - but a lot of these require understanding exact semantics on a low level (because everything could have someside-effect)
ldnunes has quit [Quit: Leaving]
jenrzzz has joined #ruby
<havenwood>
I always like the Perl term "subroutine"
<dminuoso>
havenwood, yeah it's the one thing about the language they got right.
<dminuoso>
:p
milardov_ has quit [Remote host closed the connection]
<dminuoso>
Papierkorb, but I can respect your point of view. I was in that mindset for a long time. Personally I just found comfort in being able to zoom out and not look at details anymore when I wanted to.
PaulCapestany has joined #ruby
<RickHull>
is one defining characteristic of subroutine that it's a closure, basically? it can refer to outside variables?
<Papierkorb>
dminuoso: thing is, I've not come across a single realworld sample yet where this has been an issue. "State might change!" so then just don't? Developer discipline can't be directed by a type system.
PaulCapestany has quit [Read error: Connection reset by peer]
<dminuoso>
RickHull, its rather meant as a distinction from functions in the mathematical sense. (referential transparency, lack of side effects)
<RickHull>
also, where people like to use lambdas, essentially giving a variable name to a block of code -- seems like a function, but it's a closure unlike a function?
PaulCapestany has joined #ruby
anisha has quit [Quit: This computer has gone to sleep]
<dminuoso>
RickHull, closure is about something else uhm...
hutch34 has joined #ruby
<dminuoso>
RickHull, a closure is a way of implementing free variables in lambda calculus.
<RickHull>
closing over the environment
PaulCapestany has quit [Read error: Connection reset by peer]
troys_ is now known as troys
<RickHull>
able to refer to outside variables
<dminuoso>
but its only *one* method
conta1 has quit [Quit: conta1]
chmurifree is now known as chmuri
<dminuoso>
RickHull, a lambda is just an anonymous functoin
<RickHull>
but often one assigns a variable name to it
<RickHull>
so in *that* case
<dminuoso>
RickHull, the point is just to treat it like a first class citizen.
<RickHull>
what is the major distinction to a function?
<dminuoso>
You can stuff it into an object and pass it around.
<dminuoso>
RickHull, a function has referential transparency.
<dminuoso>
and no side-effects.
airdisa has quit [Remote host closed the connection]
<RickHull>
s/function/ruby method/
<dminuoso>
(nowadays the term "function" has been changed to "pure function" in programming, because imperativist have stolen the word "function"
jenrzzz has quit [Ping timeout: 248 seconds]
<RickHull>
i'm talking about preferring to assign a lambda to a local var in ruby, rather than def foo
<dminuoso>
RickHull, for the purpose of this discussion I will not differentiate between method/function/proc/lambda/block.
PaulCapestany has joined #ruby
<RickHull>
it's going to be tough to answer my question, I suspect xD
<dminuoso>
You can trivially recover a proc from a block, or a proc from a method.
<dminuoso>
or Method from a method I guess
<dminuoso>
but thats close enough
<dminuoso>
RickHull, the point is just: referential transparency and lack of side effects. output is only determinstically determined by parameters.
vipaca has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
conta2 has joined #ruby
<dminuoso>
basically a simple way to test this is: if you can memoize a function call f(1) its pure.
hutch34 has quit [Ping timeout: 252 seconds]
mson has quit [Quit: Connection closed for inactivity]
<dminuoso>
puts "foo" can very obviously not be memoized.
<RickHull>
my question is tangential to the current discussion: "where a lambda is assigned to a local var foo, this is done in preference to `def foo` because the lambda is a closure, unlike the method foo"
<dminuoso>
RickHull, oh no. This is because ruby shadows names.
<dminuoso>
(Interestingly lambda calculus does this too)
<dminuoso>
Or I guess they are tightly related.
<RickHull>
I believe my statement is more or less correct, but perhaps there are other reasons to assign a lambda to a local var
<RickHull>
perhaps one cannot def methods in the current scope?
jrafanie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<dminuoso>
RickHull, a reason is to pass the function as an argument...
<dminuoso>
for that to work it has to exist as an object.
PaulCapestany has quit [Read error: Connection reset by peer]
G66K has joined #ruby
<RickHull>
I have seem lambdas used, where `def` would work just as well, in one or more of your gists
<RickHull>
and wasn't sure why
<G66K>
hello all im new to ruby what is the best practice to learn it fast ?
<c-c_>
I wonder why the named pipes always need a flush before they push the written out.
<dminuoso>
RickHull, it makes reusability (due to their first class nature) a lot easier.
<dminuoso>
RickHull, its a habit I picked up.
<RickHull>
G66K: write it fast and execute it fast
<dminuoso>
Hiya G66K
<c-c_>
G66K: pick a real world problem, write hour every day for 90 days, learn linux, editor and bash as well (ie. 3 hours a day)
cagomez has quit [Remote host closed the connection]
<dminuoso>
G66K, check out the topic. It contains some useful information, as well as a good book list.
PaulCapestany has joined #ruby
<c-c_>
I thought IO.puts promises to feed a line feed...
<dminuoso>
RickHull, this is also why I wrote defc to sneakily convert methods into lambdas..
<RickHull>
c-c_: not sure on the details but it's a common C idiom
<RickHull>
c-c_: incorrect, look at the need for $stdout.sync
<c-c_>
...wonder what is special about flush, whats it do that \n doesn't.
<G66K>
RickHull: :D
<dminuoso>
RickHull, (could have also used proc, but lambda has just subtly better semantics)
* c-c_
looks
<mozzarella>
dminuoso: why not use method(:symbol)?
<G66K>
c-c im already linux user since years i just came from different programming language and i want to learn something new
<G66K>
dminuoso: thanks :)
<dminuoso>
mozzarella, because you now have to bind it to something in order to call it.
<RickHull>
c-c_: buffering output is a performance optimization -- you can get more throughput with controlling the flush behavior
<c-c_>
G66K: what do you plan to use ruby for?
hutch34 has joined #ruby
<RickHull>
c-c_: or you can set to autoflush with more predictable behavior but generally less performance
<dminuoso>
mozzarella, my defc trick has that amazing property that you can do: f = [1,2,3].include?; puts f.(10)
<c-c_>
RickHull: yeah just wondering if I'm doing it wrong or if misunderstood something
<dminuoso>
mozzarella, and you can still do [1,2,3].include? 10 if you wanted to
<RickHull>
c-c_: my understanding is that it's a C/Unix idiom, like fsync on the filesystem
<G66K>
c-c_: i found some free framework on the wild and i love them i was thinking to edit them to fit my need :)
<G66K>
loved *
<dminuoso>
G66K, what languages do you come from?
<c-c_>
G66K: web MVC things?
<G66K>
dminuoso: perl php js python /etc
<dminuoso>
mozzarella, also I like that very concise way of passing a function by simply naming it but not invoking it.
<G66K>
c-c its network framework
<RickHull>
c-c_: there may be some C APIs in which "\n" is significant and acts to flush, but in general "\n" is just another integer to C
jrafanie has joined #ruby
<dminuoso>
G66K, Eloquent Ruby is probably the best pick for you.
<c-c_>
hehe I want nonblocking sync...
<RickHull>
async sync, sure buddy...
<c-c_>
hm, I wonder if 'sync' implies ruby doesn't wait on it, or that the opened IO object is forced to block until done?
<dminuoso>
c-c_, you can use IO#sync(bool) to change whether an IO is buffered or not.
<G66K>
dminuoso: yes i figured that its quit simple and i love the syntax of it
<dminuoso>
(The end might *still* be buffered)
hutch34 has quit [Ping timeout: 250 seconds]
<dminuoso>
G66K, I think you misunderstood. Thats the name of a book (its listed in the books guide)
<Papierkorb>
c-c_: Somethings' telling me you're looking for select(3), or `IO.select` in ruby
<c-c_>
but if I want to write, always have to write: pipe_to_engine.puts msg_str; pipe_to_engine.flush;
<Papierkorb>
I remember advising someone on how to refactor that code
<G66K>
dminuoso: i saw that :) but for now i perfer lynda courses
<c-c_>
- the flush gives me the "extra non-succinct line that looks non-dry"
aScottishBoat has quit [Ping timeout: 252 seconds]
<Papierkorb>
Then write a method that does what you want c-c_?
vipaca has joined #ruby
<Papierkorb>
You could dig out the big hammer and build a proxy object
hutch34 has joined #ruby
<Papierkorb>
Or .. maybe putting it into unbuffered mode is enough for your use-case
<c-c_>
Papierkorb: yes, I'm wondering if I should attach a new method on the IO object that putsflushes. But not sure if I'm just DIW or flush is "for my own non-blocking good" or something.
<RickHull>
you could put the pipe into sync mode
<RickHull>
or if flush does block, you could spin a tiny thread for it
vipaca has quit [Client Quit]
<c-c_>
no I don't want to run the pipe in blocking mode as that stops the kernel io
<Papierkorb>
c-c_: why not have a simple helper function in the class wrapping the pipe?
<Papierkorb>
c-c_: That class can simply offer a #write (and/or other IO methods, or include IO itself), in which it does the write/flush
<Papierkorb>
clean and simple
<c-c_>
Papierkorb: class wrapping the pipe? what, do you think I'm some kind of a real programmer :)
<Papierkorb>
Yeah I heard a few mins ago that you can't do that in OOP
* c-c_
is aiming for "just a couple of lines of monkey patching and OS/Kernel does the work"
<Papierkorb>
you don't want to though. The program environment is a big sandbox. There are many playing in it, so a single one shouldn't mess it up for everyone else
<dminuoso>
c-c_, I tried this too. With my macbook. Turns out that messing with one without having a clue what one does has a tendency to break things.
<c-c_>
yeah I don't want to monkey patch everything, just the utilities I'm using and contain them in their own little process(es).
<RickHull>
c-c_: what's the big concern with calling flush? that it blocks, or that it makes your code look ugly?
<dminuoso>
After my "repair" the spacebar was no longer in its spot, but on my lap...
<RickHull>
or?
tamouse__ has joined #ruby
muelleme has quit [Ping timeout: 248 seconds]
<c-c_>
I wondered earlier maybe I should just implement json messaging with them pipes and forget this simple stuff. But thats another 4 weeks more work.
<RickHull>
as noted, you could just make a class SewagePipe that autoflushes and provides a cleaner API
<c-c_>
BubblegumAndPAckingTapePipe
<RickHull>
if it's bidirectional, call it a Bidet
<Papierkorb>
c-c_: You can more or less rely on that JSON is always single-line, even if it contains multi-line strings. Hence, on the receiving end, a IO#gets may be sufficient
<c-c_>
Or maybe that should be just named_pipe.put! do |arg| ... ?
jenrzzz has quit [Ping timeout: 248 seconds]
crst has quit [Quit: Leaving...]
hutch34 has quit [Ping timeout: 240 seconds]
goyox86 has quit [Quit: goyox86]
conta2 has quit [Ping timeout: 268 seconds]
larcara has quit []
<eam>
c-c_: if you don't want to flush, use syswrite
biberu has quit []
PaulCapestany has quit [Read error: Connection reset by peer]
imode has quit [Ping timeout: 240 seconds]
<c-c_>
hm, would doing named_pipe.put do; #method body; end -actually define a method on the class? Where does that go?
Aech has joined #ruby
elphe has quit [Ping timeout: 248 seconds]
hutch34 has joined #ruby
eckhardt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Devalo has joined #ruby
PaulCape_ has joined #ruby
eckhardt has joined #ruby
imode has joined #ruby
<c-c_>
eam yeah, I wonder if you've already told me the diff between rb_io_write and rb_write_internal
hutch34 has quit [Ping timeout: 240 seconds]
cagomez has joined #ruby
Devalo has quit [Remote host closed the connection]
hutch34 has joined #ruby
Devalo has joined #ruby
<c-c_>
looks like the linux kernel has a 4 kb buffer for the named pipes that ruby opens
<c-c_>
Also, I don't get the deal with '\n'. Even syswrite needs that to actually ever write the message. Must be somewhere in the C.
tcopeland has quit [Quit: tcopeland]
Devalo has quit [Ping timeout: 248 seconds]
hutch34 has quit [Ping timeout: 264 seconds]
milardov_ has joined #ruby
<c-c_>
Wow! Howcome I didn't use Marshal. It's one of the first things I ever used in ruby (for a rw-ormy object store)
err_ok_ has joined #ruby
chrisseaton_ has joined #ruby
<c-c_>
Scratch yaml and json, marshal it is
aurelien` has joined #ruby
JJonah_ has joined #ruby
Lloyd__ has joined #ruby
gmcintire_ has joined #ruby
rann_ has joined #ruby
hsiktas_ has joined #ruby
<RickHull>
yaml and json are specifically meant for human readable text and interop
auv_ has joined #ruby
cstrahan_ has joined #ruby
kireevco_ has joined #ruby
<RickHull>
Marshal.load(Marshal.dump(some_obj_from_somewhere)) may fail
boxrick_ has joined #ruby
milardovich has quit [Ping timeout: 240 seconds]
<RickHull>
er, that's not quite right
rikai_ has joined #ruby
contradictioned_ has joined #ruby
<RickHull>
but if you have a dumped object from Tuesday, you may not be able to load it on Wednesday with v2 of the class
<adaedra>
Are we still inventing complicated ways of doing simple things in here?
harmaahy1je has joined #ruby
<c-c_>
yes
hutch34 has joined #ruby
Rush has joined #ruby
tcopeland has joined #ruby
<adaedra>
I see
freeze_ has joined #ruby
cdg has joined #ruby
kaspergr1bbe has joined #ruby
<RickHull>
a JSON payload from last year and last year's version of the lib is not useless
<RickHull>
a marshal dump probably is useless
<c-c_>
Next I'm going to have to implement async request-reply handling
jenrzzz has joined #ruby
jenrzzz has quit [Changing host]
jenrzzz has joined #ruby
<RickHull>
even tougher with marshal is when you release a new version and pipe the objdump to the old version
cdg has quit [Remote host closed the connection]
<RickHull>
it's a form of tight coupling
ggherdov has quit [Ping timeout: 255 seconds]
headius has quit [Ping timeout: 255 seconds]
Zimsky has quit [Ping timeout: 255 seconds]
rann has quit [Ping timeout: 255 seconds]
FifthWall has quit [Ping timeout: 255 seconds]
err_ok has quit [Ping timeout: 255 seconds]
cstrahan has quit [Ping timeout: 255 seconds]
auv has quit [Ping timeout: 255 seconds]
JJonah has quit [Ping timeout: 255 seconds]
galeido has quit [Ping timeout: 255 seconds]
haylon has quit [Ping timeout: 255 seconds]
harmaahylje has quit [Ping timeout: 255 seconds]
tessi_zz has quit [Ping timeout: 255 seconds]
inukshuk has quit [Ping timeout: 255 seconds]
Hanma[m] has quit [Ping timeout: 255 seconds]
velu_aon[m] has quit [Ping timeout: 255 seconds]
Tagami[m] has quit [Ping timeout: 255 seconds]
beccamorgan has quit [Ping timeout: 255 seconds]
EvilJStoker has quit [Ping timeout: 255 seconds]
freeze has quit [Ping timeout: 255 seconds]
kireevco has quit [Ping timeout: 255 seconds]
chrisseaton has quit [Ping timeout: 255 seconds]
gsingh93 has quit [Ping timeout: 255 seconds]
torarne has quit [Ping timeout: 255 seconds]
rideh has quit [Ping timeout: 255 seconds]
sundhell_away has quit [Ping timeout: 255 seconds]
contradictioned has quit [Ping timeout: 255 seconds]
RushPL has quit [Ping timeout: 255 seconds]
ablackack has quit [Ping timeout: 255 seconds]
aurelien has quit [Ping timeout: 255 seconds]
bazzy has quit [Ping timeout: 255 seconds]
kaspergrubbe has quit [Ping timeout: 255 seconds]
rikai has quit [Ping timeout: 255 seconds]
woodruffw has quit [Ping timeout: 255 seconds]
hsiktas has quit [Ping timeout: 255 seconds]
knight_ has quit [Ping timeout: 255 seconds]
boxrick has quit [Ping timeout: 255 seconds]
<RickHull>
and good luck reimplementing one side of the pipe in Crystal
Lloyd has quit [Ping timeout: 255 seconds]
gmcintire has quit [Ping timeout: 255 seconds]
darthThorik has quit [Ping timeout: 255 seconds]
rann_ is now known as rann
JJonah_ is now known as JJonah
auv_ is now known as auv
cstrahan_ is now known as cstrahan
err_ok_ is now known as err_ok
gmcintire_ is now known as gmcintire
chrisseaton_ is now known as chrisseaton
Lloyd__ is now known as Lloyd
hsiktas_ is now known as hsiktas
kireevco_ is now known as kireevco
FifthWall has joined #ruby
boxrick_ is now known as boxrick
knight- has joined #ruby
headius has joined #ruby
7GHAA6UVM has joined #ruby
synthroi_ has quit []
Zimsky has joined #ruby
tessi_zz has joined #ruby
<c-c_>
And FWIW, theres an ui process that asks for data from state server. State server returns 1) n*n map squares 2) objects with properties, but I don't see how the classes would get obsolete for a game. Of course between versions but not one game.
inukshuk has joined #ruby
bazzy has joined #ruby
gsingh93 has joined #ruby
sundhell_away has joined #ruby
woodruffw has joined #ruby
woodruffw has joined #ruby
woodruffw has quit [Changing host]
EvilJStoker has joined #ruby
ablackack has joined #ruby
<c-c_>
(also, engine puts objects to the state server)
rideh has joined #ruby
<RickHull>
i'm just pointing out potential pitfalls -- if you can avoid them, then all to the good
hutch34 has quit [Ping timeout: 240 seconds]
<c-c_>
Its simple arrays or hashes.
<c-c_>
Also, why would opening a pipe be diff in crystal?
tcopeland has quit [Client Quit]
<c-c_>
- its the kernel that handles the pipe
wolfshappen has quit [Ping timeout: 240 seconds]
* c-c_
concerned
troys is now known as troys_
<RickHull>
are you planning to Marshal.dump a crystal object?
tomphp has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kryptoz has joined #ruby
David_H__ has joined #ruby
hutch34 has joined #ruby
yqt has joined #ruby
itmerc[m] has quit [Ping timeout: 246 seconds]
yana[m] has quit [Ping timeout: 246 seconds]
gokul_mr[m] has quit [Ping timeout: 240 seconds]
aviraldg has quit [Ping timeout: 252 seconds]
<adaedra>
ada?
Giphy[m] has quit [Ping timeout: 240 seconds]
turt2live has quit [Ping timeout: 240 seconds]
zalipuha[m] has quit [Ping timeout: 255 seconds]
lasenna[m] has quit [Ping timeout: 250 seconds]
jonjits[m] has quit [Ping timeout: 250 seconds]
erciccione_[m] has quit [Ping timeout: 246 seconds]
Matt[m]2 has quit [Ping timeout: 246 seconds]
<adaedra>
>_>
aagdbl[m] has quit [Ping timeout: 264 seconds]
M107262[m] has quit [Ping timeout: 240 seconds]
kua[m] has quit [Ping timeout: 248 seconds]
watzon has quit [Ping timeout: 248 seconds]
<RickHull>
on the shoulders of giants we stand
dman[m] has quit [Ping timeout: 252 seconds]
dtcristo has quit [Ping timeout: 250 seconds]
KevinMGranger has quit [Ping timeout: 264 seconds]
astronavt[m] has quit [Ping timeout: 264 seconds]
<c-c_>
adaedra: yes you thanks
David_H_Smith has quit [Ping timeout: 240 seconds]
bokayio has quit [Ping timeout: 240 seconds]
* c-c_
is more like climbing on their shoes
<adaedra>
c-c_: this is a ruby channel. We don't do ada in here.
iNs has quit [Ping timeout: 260 seconds]
* c-c_
would really like to do Ada sometimes
<adaedra>
/nick rubyedra
kryptoz has quit [Ping timeout: 240 seconds]
<kyle__>
x+=['a']
<kyle__>
adaedra: There. I add a.
jrafanie has quit [Ping timeout: 248 seconds]
<adaedra>
aah?
<kyle__>
add a. ada. It's pun. Not a very good one, but it's been that sort of day.
milardov_ has quit [Remote host closed the connection]
c-c_ is now known as c-c-zZ
bokayio has joined #ruby
<adaedra>
oh ok.
iNs has joined #ruby
postmodern has joined #ruby
krawchyk has quit [Ping timeout: 248 seconds]
marxarelli is now known as marxarelli|afk
<eam>
21:39 < c-c_> looks like the linux kernel has a 4 kb buffer for the named pipes that ruby opens
mahlon__ is now known as mahlon
Tagami[m] has joined #ruby
<eam>
c-c-zZ: not 4kb necessarily, though 4k is still relevant to I think something around atomic read/writes
<eam>
it's been 64k for a while now
hutch34 has quit [Ping timeout: 240 seconds]
<eam>
and I think it's configurable
tcopeland has joined #ruby
<eam>
but the internal buffer in a pipe() is different from the stdio buffering which happens in puts/write vs syswrite
<eam>
stdio buffering happens in an in-process buffer
impermanence has joined #ruby
marxarelli|afk is now known as marxarelli
troys_ is now known as troys
<c-c-zZ>
hm. yeah that was kinda brainfart from me - what I was trying to communicate, is the named pipe seems to flush/sync, once ~4000 chars have been written to it. I didn't realize I don't even know how many bytes ruby utf char is (not constant)
<eam>
the mechanism is a bit different than what you're imagining, I think
minimalism has joined #ruby
<c-c-zZ>
yeah, that was with IO#puts so it might be ruby buffer as well
<eam>
the stdio buffer is a chunk of memory in the process, and when you call puts() it just copies memory to that buffer - no write, no system/linux interaction at all
<eam>
#flush forces that buffer into a syswrite
G66K has quit [Quit: leaving]
<eam>
there's a memory buffer in a pipe() pair, however there's no need to flush it because as soon as there's a single byte in it, a select() on the other end will return ready
<c-c-zZ>
wow cool
reber has quit [Remote host closed the connection]
<c-c-zZ>
B)
<eam>
the pipe buffer is mostly relevant to how much the writer can write before it blocks on needing hte reader to read -- but it's not really relevant to flushing
Aech has quit [Ping timeout: 240 seconds]
tristanp has quit [Remote host closed the connection]
<eam>
(it can't be flushed)
tristanp has joined #ruby
<RickHull>
does flush block? and if so, is it nontrivial in that respect?
blackmesa has joined #ruby
<eam>
yes, flush performs a blocking write
apofis has joined #ruby
hutch34 has joined #ruby
<eam>
well, it performs a write
<RickHull>
in C, I imagine you check for an error code. in ruby as well?
<eam>
if the descriptor is nonblocking I imagine it might return without flushing? I'm not sure
<eam>
I suspect mixing nonblocking i/o with stdio is a recipe for disaster
<c-c-zZ>
hehe I try not to check
<RickHull>
it's possible ruby throws an exception
<eam>
I suspect some of the methods do not check error codes, and some raise
<RickHull>
s/throw/raise/ :)
<eam>
puts does NOT raise
<eam>
ruby -e'f = open "/dev/full", "w"; f.puts "hi"'
<eam>
contrast with ruby -e'f = open "/dev/full", "w"; f.syswrite "hi"'
<c-c-zZ>
yep, it just makes the thing sit there and lets you wonder where the hell did it stop
tristanp has quit [Ping timeout: 240 seconds]
<eam>
I believe the way the stdio layer (which puts uses) works is that it masks the error and copies the buffer to the stdio buffer
<eam>
and once that's full, it'll raise
hutch34 has quit [Ping timeout: 240 seconds]
<eam>
but you don't really have good locality between when writes started to fail, and when the raise eventually (if ever) occurs
<eam>
ruby can exit with a dirty buffer, without passing anything up
<eam>
generally, if you care, avoid stdio
<eam>
especially anything doing ipc, sockets, etc, you don't want that stdio layer between you and your reads and writes
<c-c-zZ>
I use it for this ui process atm. I guess the raw input will make stdio go away.
<c-c-zZ>
(from curses)
<c-c-zZ>
ok, time for theta and delta brainwave cycles
<RickHull>
i bet you there is a simple scan impl but I can never remember quite how scan works
hutch34 has joined #ruby
bhaak has quit [Ping timeout: 248 seconds]
ogres has joined #ruby
cagomez has quit [Remote host closed the connection]
hutch34 has quit [Ping timeout: 240 seconds]
cdg has joined #ruby
exhiled has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
imode has quit [Ping timeout: 240 seconds]
eckhardt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
eckhardt has joined #ruby
cdg has quit [Ping timeout: 260 seconds]
hutch34 has joined #ruby
enterprisey has quit [Remote host closed the connection]
kitsunenokenja has quit [Ping timeout: 252 seconds]
charliesome has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
eckhardt has quit [Client Quit]
tristanp has quit []
hutch34 has quit [Ping timeout: 264 seconds]
nehero has joined #ruby
<nehero>
Hola. Can anyone tell me why just a raw string ("\xAE\xA4=\x01\xC1\x9B\xF69\xFB\x9B\xCAt\xCD\x808\x91\x85\x15\x84-\x17\xC3\f\x14lO\\\xAA\x13\xD1\xE2,") would have a bytesize of 32, but when I access it through Rails.application.secrets.encryption_key it would have a bytesize of 49?
<RickHull>
I would compare the raw bytes from Rails to the original string
impermanence has quit [Ping timeout: 250 seconds]
<apeiros>
if it was 99 instead of 49, I'd go with "wrong quotes"
<apeiros>
but 49? yeah, compare :)
<nehero>
How do you mean? When I do "the above string".bytesize i get 32, but when i do Rails.application.secrets.encryption_key.bytesize i get 49
<RickHull>
so look at e.g. the first 5 bytes of each
<RickHull>
are they identical?
hutch34 has joined #ruby
<apeiros>
.bytes to not be confused by inspect & encodings
<nehero>
Ah gotcha
paulr has joined #ruby
galeido has joined #ruby
darthThorik has joined #ruby
<nehero>
The first 5 are indeed different
<nehero>
could there be a problem with encoding?
airdisa has quit []
ggherdov has joined #ruby
nadir has quit [Quit: Connection closed for inactivity]
<RickHull>
how does the original string get into rails' clutches?
<nehero>
via config/secrets.yml
<nehero>
I have it stored under development -> encryption_key
<nehero>
then stored in double quotes
<RickHull>
try reading it from Yaml on your own
<RickHull>
and then keep reverse engineering the rails process
hutch34 has quit [Ping timeout: 264 seconds]
<apeiros>
are you actually looking at the right file?
<apeiros>
as in: if you change the value in the file, does the (wrong) value change too?
uneeb has joined #ruby
charliesome has joined #ruby
cadillac_ has joined #ruby
exhiled has joined #ruby
uneeb has quit [Read error: Connection reset by peer]
<nehero>
yup yup
<RickHull>
also, try putting e.g. "\x00\x01\x02" in there
aroaminggeek has joined #ruby
<nehero>
Yeah even loading the file manually via yaml i get 49 in bytesize :(
<nehero>
Another weird observation is that when I dump the raw string in rails.console It spits it back nice
vipaca has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<nehero>
but when i do the Rails.application.secret.encryption_key it spits out weird UTF-8 chars
jenrzzz_ has quit [Ping timeout: 248 seconds]
hutch34 has joined #ruby
cdg has joined #ruby
mikecmpbll has joined #ruby
uZiel has quit [Remote host closed the connection]
cdg has quit [Remote host closed the connection]
<apeiros>
nehero: uh, how do you write it in the yaml?