top | item 40111431

(no title)

foobarbaz321 | 1 year ago

This is because Ruby inherits it's approach to flow control from Smalltalk, while Python comes from a C/Algol-like heritage.

In fact, Smalltalk takes this much further, such that basically all flow control (including if-then-else) is handled as message sends (e.g. if-then is just a message sent to the Boolean object taking a block as it's argument).

The downside is the syntax can feel a tad clunky. The upside is incredibly simple and consistent language grammar, while making it trivial to create new flow control mechanisms since the language has all the tools baked in (primarily first class blocks).

discuss

order

pjmlp|1 year ago

Just a sidenote that for performance reasons, control flow messages are actually optimized in most implementations, even though they also look like regular messages.

hi-v-rocknroll|1 year ago

Also, Perl's history adds an additional layer of flavor. Ruby started as somewhat "Perl 2.0" where beauty and flexibility > all things and Python started as "anti-Perl" one way to rule them all(tm) where fast and standard > perfection of beauty.

anal_reactor|1 year ago

[deleted]

ivancho|1 year ago

Ah, a brilliant idea, design all languages so people who only know C can make small changes to existing Ruby code without getting confused. Definitely don't want to enable different abstractions or models of computation. Are these core principles in codebases you mentioned mostly "how to write stuff using C paradigms"? After all, "the Real Programmer can write FORTRAN in any language"

devjab|1 year ago

I think you’re mistaking C-style syntax for what modern C languages have adopted and become.

How many C style context even really exist today? The block separation by single characters is ok. Using (), [] and {} to separate things makes things easier on the compiler, but it’s probably down to personal preference whether you like that syntax or not. I certainly vastly prefer the more simplistic approach where you don’t have to wrap everything in brackets. Like a loop… why does it really have to be inside a () denotion? Similarly I prefer Pythons indent to {}’s. Which can technically make your code harder to read, but if your Python code is hard to read it’s likely bad. Not always, but most of the time. I guess {} is better than BEGIN END, but maybe not in terms of readability.

The end of line character, ; is also sort of unnecessary for the most parts. Again it’s mostly a relic which helps the compiler, and some people like it while others don’t.

Modern loops look nothing like they did in C. Neither does variables or properties.

The use of English for a lot of things, or the use of western character sets, is also sort of bad in the modern world. Which is part of the reason behind the huge popularity of Go in Asia. Not that it’s so bad as it’s just how it is and everyone has adopted.

Anyway. Modern C style syntax like you’ll finds in C# or Java is rather cumbersome in my opinion. Rust sort of falls into this category but at least with Rust it’s very easy to define ownership of your stored data as you pass it around in your code. But almost all of it is exactly that… modern. Almost none of it is from C and a lot of it would not have existed without languages like Ruby.

You also have to keep in mind that Ruby predates the modern C syntax. As others have mentioned it’s been influential on the modern C syntax, but it was also made in a world where they modern syntax simply didn’t exist.

saurik|1 year ago

Smalltalk and C both came out in 1972 and it really isn't clear to me that C's crazy for-loop design -- one that actually isn't used by many programming languages -- is somehow better than the one used by Algol, so I am struggling to find even a single thing you said which is making any sense to me :(.

stouset|1 year ago

What exactly do you think the purpose of having different programming languages is?

The popularity and usefulness of Ruby’s block-based control flow, which you seem to take issue with, is almost certainly largely responsible for the adoption of lambdas in… basically every modern language, not to mention being backported to existing languages like C# and Java.

Frankly your hot take is terrible. C was an amazing language, but there are an infinite number of practical and effective ways to improve upon it. Particularly having just admitted that you’ve never actually used the syntax in question it’s honestly astonishing that your first instinct is to jump straight to posting about how much better the C approach is.

Hell, you’d be hard-pressed these days to find a modern language that uses C-style `for` loops. They might say `for` on the tin, but they’re much closer to Ruby-style enumerators than they are to C-style setup-condition-increment control flow. With, of course, the caveat that that’s all they ever can be since they’re keyword syntax rather than just a method.

What a sad world this would be if everything interesting in programming was discovered by K&R in the 1970s.

krainboltgreene|1 year ago

> I feel like each new language absolutely needs to reinvent existing standards that have proven effective, just so that it feels unique. I don't have any experience with Ruby in particular, but every time a tool does some basic thing like a for loop "in a new, innovative way"

You're talking about a 25 year old decision.

bhaak|1 year ago

You don't seem to have any knowledge about the history of programming languages. There have been several lines of PL syntaxes since the 50s.

You are crazy if you think that a C style for loop is good designed. It's way to powerful but terse and obtuse to do correctly beyond the simplest application.

C style syntax as a whole is also nothing special if you mean semicolons and braces.

If you include stupid design decisions like braceless blocks in "C style syntax" I wouldn't even know what to think of that opinion.

jojobas|1 year ago

C syntax for say list iteration would be much more cumbersome than "for a in mylist", so there's benefit in diverging from C sometimes.

Funnily, regardless of deeply different implementations, for loops look almost the same in Python and Ruby.

crabbone|1 year ago

> The upside is incredibly simple and consistent language grammar

I hope you don't mean Ruby (I haven't investigated Smalltalk grammar). Ruby grammar is atrocious due to string interpolation stuff. Nothing to do with handling loops or conditionals, but still... Ruby is not at all an example of a language with good grammar.

Unfortunately, it's surprisingly rare for popular languages to have good grammar. If you look at it from up close, there are lots and lots of really bad decisions in virtually any language in common use today. I think, this is just not a high-priority concern for most users, but still...

Joker_vD|1 year ago

Could you perhaps write a blog post on what you consider bad decisions in a PL grammar? That'd be interesting to read, esp. for all the aspiring PL developers/makers here.