4 ms·
This is a little bit off topic, but one thing that I wish python used is ruby's indicators for the purpose of a function. i.e. "?" for boolean returns, and "!"
by fhood 9y ago
This is a little bit off topic, but one thing that I wish python used is ruby's indicators for the purpose of a function. i.e. "?" for boolean returns, and "!" for modifying functions in place.
In a language without explicit typing and return values having an instant indicator of the functionality of a function can be a huge help in writing readable code.
- epage 9y agoAs someone who dislikes Ruby, I have holy envy[1] for Ruby's use of ? and ! [1] http://ancienthebrewpoetry.typepad.com/ancient_hebrew_poetry/2010/05/krister-stendahls-three-rules-of-religious-understanding.html http://ancienthebrewpoetry.typepad.com/ancient_hebrew_poetry...
- fhood 9y agoAs someone who thinks they understand both the upsides and downsides of Ruby, you shouldn't write it off. I find ruby to be really unsuited for projects with multiple people, but genuinely fantastic for personal projects or one off scripts.
- actsasbuffoon 9y agoI think this is generally true of languages with powerful metaprogramming facilities. I could be totally happy writing a complex app with Common Lisp, but I probably wouldn't want to debug someone else's code with it.
- mercer 9y agoCan I recommend you look into Elixir? The (possible) downsides are 1) that it's functional programming, and 2) that there might be libraries/gems for Ruby that don't exist for Elixir. But the upsides... It's faster, it's different in a good way, in that it makes you think differently (OTP/processes) without the risk of being unproductive. It's very ruby-like but without the warts (although I'm sure it has a few of its own), and was even specifically designed with Ruby as an inspiration/starting point (AFAIK). So far I've not come across articles that were negative about Elixir in relation to Ruby. So if you do, I'd be curious to hear what you think. And of course if anyone can point out things they feel are better in Ruby, I'd love to hear it.
- cup-of-tea 9y agoIs this enforced in Ruby or just a convention? It's a great convention and is used in Clojure and older Lisps at least with the -p suffix (for predicate). There's no reason you can't use the same convention in Python. I've often wanted to write predicates with the -p suffix but stopped myself becasue I don't think other Python people would understand it. Maybe I should just do it anyway.
- masklinn 9y ago> Is this enforced in Ruby or just a convention? It's just conventional.
- fhood 9y agoBut present in basically all the major libraries which is wonderful.
- ralmidani 9y agoIn Ruby, the "?" is optional and used to indicate you are calling a function/method which returns a boolean. The "!" is actually part of the function/method's name. When you want to sort an array, for example, you can either say "sorted_array = array.sort" or you can sort in-place with "array.sort!". So the exclamation distinguishes between the two methods and warns you are performing a destructive operation.
- brudgers 9y ago{being pedantic} In Python, you can't use the '-p' suffix because Python will treat it as subtraction. {being unPythonic} If it makes you happy to use '_p', do it. Explain it in the documentation if it might cause confusion. Be flexible enough that you'll change before letting yourself be voted off the island because it's not that important. {rabble rousing} I think there is room in the world for an alt-python movement...https://github.com/altpython https://github.com/altpython
- cup-of-tea 9y agoYes, you'd have to use just p. The convention in Lisp is it's just p unless the function name is multiple words anyway in which case the words are separated by hyphens and the suffix is -p. I suppose it is more Pythonic to name predicates like "is_full" or something rather than "fullp". But whatever it is I've found I can't stand not using some kind of naming convention for predicates.
- bakery2k 9y ago> "!" for modifying functions in place I think that consistently using "!" to mean "mutates in-place" would be a good convention for a language to use, but that's not what Ruby does. From Matz himself [1]: The bang (!) does not mean "destructive" nor lack of it mean non destructive either. The bang sign means "the bang version is more dangerous than its non bang counterpart; handle with care". Since Ruby has a lot of "destructive" methods, if bang signs follow your opinion, every Ruby program would be full of bangs, thus ugly. [1] https://www.ruby-forum.com/topic/176830#773946 https://www.ruby-forum.com/topic/176830#773946