4 ms·
I wish I could merge the parts of Ruby and Python I like while discarding the parts I don't. Mutable strings by default was a huge mistake in Ruby and so was al
by 3pt14159 5y ago
I wish I could merge the parts of Ruby and Python I like while discarding the parts I don't. Mutable strings by default was a huge mistake in Ruby and so was allowing non-self calls to methods from another method of the same class. Within the class scope, it's great, but it just leads to bugs in the method scope. The things I love most about Ruby over Python is I don't have to memorize as many things. With Python I'm never sure if it is isinstance or is_instance or DefautlDict or default_dict. It's annoying having to constantly lookup things. Oh and how I miss one line if statements and conditional assignment when I'm in Python.
One thing I like about both languages is how nice it is to write tests. The patching and the assertions are great.
- throw_m239339 5y ago> I wish I could merge the parts of Ruby and Python I Crystal lang does a bunch of great thing but the poor support on Windows (having to install some Linux subsystem to compile stuff) is a non starter for many companies. I personnally never liked Python's syntax, or OOP, it feels tacked on. However Python's ecosystem is just too huge to be ignored.
- strzibny 5y agoI have the same feeling. Chaining is so much more intuitive in Ruby.
- derac 5y agoYou can write one line if statements in Python. You can also do conditional assignment with the ternary operator. i.e. if True: a = 1 if True else 0
- adamrt 5y ago> a = 1 if True else 0
- 3pt14159 5y agoWhy should I need an else statement to use an if statement?
- Jtsummers 5y agoYou said you missed two things in Python: > Oh and how I miss one line if statements and conditional assignment when I'm in Python. derac provided an example exercising both. To separate them: One line if statements: if predicate: expression Conditional assignment: a = 1 if predicate else 0 The else is to permit the conditional assignment, it's a ternary operation, it is not for the if statement.
- 3pt14159 5y agoWell, sorta. In practice people don't use one line statements and it's considered unpythonic. So much so I forgot it was even possible, so you're right, I was wrong. Black converts it to a multiline statement. Also, the Ruby syntax for them is better because it makes it clear it isn't a mistake. launch_nuclear_weapons if at_total_war Just reads better because it doesn't look like a mistaken if statement. By conditional assignment, I meant more something like this: some_var ||= 45 And I know I can do either: some_var = some_var or 45 some_var = some_var if some_var else 45 But it just looks stupid and it is such a frequent need due to the way default args work for things like dicts, that it gets annoying.
- derac 5y agocheck out defaultdict :D https://docs.python.org/3/library/collections.html https://docs.python.org/3/library/collections.html
- cortesoft 5y agoWhat is your issue with mutable strings? I've been a heavy Ruby user for 16 years and have never really thought about strings being mutable... what negative effect does it have?
- 3pt14159 5y agoIt allows for certain classes of exploit and is not worth the cost for the negligible performance gain in 99.99% of the situations. Before there was a comment to disable them I would see codebases littered with .dup or .freeze.
- lovegoblin 5y ago> Mutable strings by default was a huge mistake in Ruby This was changed in 3.0. String literals are now frozen/immutable by default.
- jrochkind1 5y agoI don't believe this is correct. There was a plan to do that at some point, but it was pulled back from for backwards compat reasons. You can opt-in to string literals being frozen by default on a per-source-file basis with a magic pragma comment, and this has existed for several ruby 2.x versions and is unchanged in the released ruby 3.0.
- lovegoblin 5y agoOh, huh. Yeah, you're right. Really showed my whole still-on-2.7 ass here haha