3 ms·
> .methods, "the Ruby equivalent of 'dir'" doesn't present the results as a sorted list This seems like an odd complaint: Both languages use hash maps to look
by ben-schaaf 6y ago
> .methods, "the Ruby equivalent of 'dir'" doesn't present the results as a sorted list
This seems like an odd complaint: Both languages use hash maps to look up methods/attributes, which aren't inherently sorted. Looking at the implementation `dir` in python does an explicit sort, which just seems like arbitrary behaviour.
- raverbashing 6y agoIt's not an arbitrary behaviour if you want a well behaved result from it. Same with Python dictionary keys which used to have no intrinsic ordering. Especially when dir() is more used in interactive applications (and sure, sometimes programatically like in plugin architectures, etc)
- dragonwriter 6y agoBecause Ruby uses fairly deep metaprogramming much more, idiomatically, than does Python, while “dir() is more used in interactive applications” may be true, that does not imply that “#methods is more used in interactive applications”. And, anyhow, an interactive application that wants the information it asks for will quite often wan’t to impose an organization other than alphabetic ordering.