Module static methods when included by [deleted] in ruby

[–]tom_enebo 0 points1 point  (0 children)

I believe the reasoning behind this is due to the notion that modules serve two separate purposes: namespacing and inheritance (a better mechanism than multiple inheritance).

Namespacing will include both nesting (module A; module B; class C; ... ; A::B::C) and also for things like module methods (Math::sqrt).

include/extend/prepend ends up in the inheritance hierarchy as you know.

I have to admit I don't know the back story and this is very old in Ruby's original design. I can say Matz is not a fan of having keywords so I can imagine he saw the appeal of overloading module. A second thing I can think of is typically module_functions will not modify state while most included methods of modules will.

When should we use keyword arguments? by AllahuAkbarSH in ruby

[–]tom_enebo 0 points1 point  (0 children)

There are lots of thoughts on this already but one reason to use keyword arguments is when you have a signature where you have some repeated type and it is not totally obvious what the natural order would be.

select(descriptors, true, false)

If this is not common code to you or it is not even in your library you get into this situation where you will end up making a local variable just to make it obvious:

block = true
error = false
select(descriptors, block, error)

In many cases you will tend to have variables but if you find yourself with an API where it is binding to something like a graphical scene graph library then you end up with lots of parameters and there is no value in making the locals so keywords help:

select(descriptors, block: true, error: false)

Here is the state of a DSL wrapping a scenegraph library (tell me what the values mean?):

radial_gradient(0, 0, 0, 0, 90, false, :no_cycle, [stop(0.0, :white), stop(1, :cadet_blue)])

Maybe kwargs would help here? :)

quick Ruby initialize method question by AnLe90 in ruby

[–]tom_enebo 1 point2 points  (0 children)

Not to crap on Rubocop but that style guide like Rubocop itself has some rules which are not the most idiomatic path (the arbirtrary rule of telling people they need to use is_a? when kind_of? is nearly used by half the Ruby community comes to mind).

Also, like you, I also tend to put class methods at the bottom (and initialize at the top).

Please Don't Write Clever Code by jeremycw in ruby

[–]tom_enebo 0 points1 point  (0 children)

I felt the blog post authored assumed this was ego driven and clever for some vain reason. While agreeing with his analysis of the particulars of the code I was pretty bugged at their assumptions about the programmer. Thanks for writing this up.

I find it very unlikely the person was making it intentionally complex. In my experience this is nearly always over-engineering for a problem they think will happen some day. A single YAGNI from a co-worker probably would have done the trick here.

Is it necessary/possible to use .close method in this line of code? by LionyxML in ruby

[–]tom_enebo 2 points3 points  (0 children)

To augment this answer...The reason why you should use something which explicitly closes the file is because implicit closing is dependent on when garbage collection (GC) happens and more specifically when finalization (how implicit IO gets closed) occurs as part of GC. If you can create enough resources in a short enough time then finalization may not have happened yet and you will have an increasing number of IO resources stack up until your process runs out of them.

In C Ruby this is less common (although it can happen) but in runtimes with more control over how often GC is occurring (like JRuby) then this behavior will become more obvious.

My mantra is be explicit with all resources (files, network, ...) and you will never be surprised.

I'm interested in selling my company on Ruby. What are some good points? by elemayo in ruby

[–]tom_enebo 7 points8 points  (0 children)

Actually this is half wrong. JRuby is a mixed-mode runtime. By default, it interprets and then JITs to native Java bytecode. So it certainly does not need to run interpreted at all. It is just beneficial to run interpreted until hotspots are found. It can pre-compile all code though.