DEV Community

Ben Halpern
Ben Halpern

Posted on

What do you think about the idea that "there should be only one way of doing a thing" in programming languages?

Top comments (60)

Collapse
 
taillogs profile image
Ryland G

The idea of "one way to do things" originated from the Zen of Python. This quote has been taken out of context and distorted, here is the original

There should be one-- and preferably only one --obvious way to do it.

I think the rule makes sense as it was originally stated. Strive for one way, make it obvious, don't beat yourself up if it's not possible.

Collapse
 
jacoby profile image
Dave Jacoby

Snipe: if only they kept that philosophy to package management.

::ducks::

Collapse
 
taillogs profile image
Ryland G

That shit is a disaster. I don’t really use python and that’s definitely a contributing factor. Why should I have to use venv?

Collapse
 
autoferrit profile image
Shawn McElroy

Totally agree. I love python and is often my goto. But its been so bad for so long. It IS getting better. pyenv/pipenv make it way better for one. pipenv still isn't what you need if you are publishing libraries on pypi, but I think its a good start in the right direction.

The packaging should be built in. To me, Rust/Cargo so far has some of the best packaging around.

Collapse
 
pulljosh profile image
Josh Pullen • Edited

Creating one obvious way to succeed sounds an awful lot like designing a Pit of Success:

I've often said that a well-designed system makes it easy to do the right things and annoying (but not impossible) to do the wrong things.

Collapse
 
renegadecoder94 profile image
Jeremy Grifski

What a great link! I had never heard of a pit of success before, but I’m on board. In terms of pits of despair, C++ was the exact language that came to mind when I jumped in on this thread.

Thread Thread
 
jhuebel profile image
Jason Huebel

I personally would give C/C++ a pass. It's a foundational/architectural language, so it should be flexible and shouldn't hold the programmer's hand. I don't think C++ is a language that needs to be fixed. But I do think it's a language that not just anyone should use.

But for higher-level languages like Python, Ruby, PHP and the .NET variants, I would agree that having one obvious way to do things is the best policy.

Thread Thread
 
renegadecoder94 profile image
Jeremy Grifski

I’d definitely give C a pass! I feel like it’s a pretty straightforward language. You just have to do everything yourself. Haha

Collapse
 
joelnet profile image
JavaScript Joel

Part of the success of React is they didn't dictate how anything should be done. They made a few recommendations, like FLUX and instead the people chose Redux.

This flexibility, while being chaotic, allowed a survival-of-the-fittest design to grow naturally.

This is also the reason I abandoned Angular 1 for React.

Collapse
 
okbrown profile image
Orlando Brown

Hahaha it's not just me then!!
That said I'm always curious to see how Angular is progressed since I used Angular 1. But when I look, I get distracted by Vue's similar yet simpler API.

Collapse
 
steveblue profile image
Stephen Belovarich • Edited

🤮

The “way of working” is whatever a team decides is the way to work (well-informed or not). A programming language is usually flexible enough to allow for multiple ways of working. It doesn’t have to dictate solely how we work.

Collapse
 
andrewbrooks profile image
Andrew Brooks 👨‍💻

I like a balance. Too many options makes it hard to define best practices but too few doesn't allow breathing room for edge cases.

Collapse
 
cathodion profile image
Dustin King

I think there's a benefit to there being one obvious way to do something. However this can become restrictive, and programming languages should also support doing things a different way when you want to. Just like natural languages, programming languages are means of expression, and they do have conventions, but should also allow for a lot of flexibility in how ideas are expressed.

Collapse
 
renegadecoder94 profile image
Jeremy Grifski

Personally, I love it. Ever since I picked up Python, I've been thankful for this idea since it makes the language so much easier to work with. After all, once you know the idioms, solutions to common problems start to feel obvious.

Of course, idioms can act as a barrier to entry, and some people can leverage that fact as a form of gatekeeping. In addition, I think the lack of flexibility can work to the languages detriment in some cases.

That said, in a language like C++, the lack of "there should only be one way of doing a thing" makes the language ridiculously complex. If you asked two people to solve the same problem, you can end up with wildly different solutions. To me, that's a problem because there's no unity in problem solving. In other words, good luck getting help from your favorite search engine.

In addition, without a "one way to do it" mindset, people are free to mix and match syntax which I find to be error prone. Of course, some people prefer the flexibility, and that may pay off from an optimization point of view.

Collapse
 
scott_yeatts profile image
Scott Yeatts

To expand a little bit on this/slight counterpoint: We should all be pushing to make programming less elitist and more accepting (We have to... there aren't enough of us to go around). Also, I think Python is a great and flexible language, no hate from that end... I just feel the quote gets misused haha!

Insisting on one way, or writing a language/framework that only accepts one way to do something is harmful. It restricts expression at the cost of standardization, and increases the likelihood of bugs when someone doesn't have all the rules memorized. It also means it's harder to get that ONE answer in the sea of possible answers. All of these things prevent new engineers from succeeding.

Repetitive failure is demoralizing. Eventually you just give up. Programmers in the 70's and 80's weren't inherently smarter or better than today's programmers, they were just the last people standing after attrition took the ones that couldn't memorize all the commandments inherent in bare-metal and low-level instruction sets.

There's a reason we developed C++, then Java, then Python, then Node, then X. There's a reason the JavaScript frameworks keep changing. There's a reason that when you convert from Java 1.3 to 12 you remove a ton of code (I think that was what I was seeing in the GIF from that tweet today :D).

That reason for all this change is developer quality of life and accessibility for incoming users. When we start saying (or designing languages and frameworks to follow) "there should be only one way of doing a thing" we're stepping back, not forward.

Are there objectively "wrong" ways of doing something? Of course... but we need to make sure we have concrete reasons (code smells, side-effects, design patterns, common algorithms, Big-O etc) to explain it, or it's really just personal opinion.

When we start running teams with that expectation, or writing new languages that way, our opinionated product is now less accessible to the guy who just took his first programming course and just wants to solve problems using the magic mystery box running at his desk :D

(Additional disclaimer.... it IS also possible to go too far in the other direction... Andrew is right about that!)

Collapse
 
renegadecoder94 profile image
Jeremy Grifski • Edited

I think everything you've mentioned is on point! That said, I would like to clarify exactly what I was imagining when Ben used the phrase: "there should be only one way of doing a thing."

In language design, we should try to avoid bloat whenever possible. When I think of bloated languages, I think of languages that have been around for awhile that never really deprecated anything (C++ comes to mind). As a result, these bloated languages have a certain amount of complexity that has to be reigned in by people—instead of by the languages. Setting up standards and whatnot take time, and it would be nice if the languages themselves stuck to a niche.

To your point, I wouldn't advocate for telling people in general that there's only one way to do things. That's textbook elitism. But from a language design standpoint, I think it makes sense to limit language complexity.

Thread Thread
 
scott_yeatts profile image
Scott Yeatts

Absolutely! I actually think we're in complete agreement and just approaching it from two different angles. I just got inspired to throw my angle in there to keep discussion alive/offer a different perspective.

It started as a standalone post, but I saw you'd touched on it and figured it was better as a reply/part of a discussion than a standalone haha!

Thread Thread
 
renegadecoder94 profile image
Jeremy Grifski

Great stuff, Scott! Happy to chat with you.

Collapse
 
tducasse profile image
Thibaud Ducasse

In some languages (I'd say python), the most idiomatic way of doing things will also be the best for performance. And understanding the way the language expects you to write code is a big part of writing good code.

But sometimes, because they optimise the language for the most common 99% of the use cases, you end up having to write something else, more convoluted, but more performant.

I think it's not so much about having just one way, but more about teaching people that this should be the way unless you need X or Y.

Reminds of when eslint starts yelling at you but you add //eslint-disable to the line because "yes I know but in this case I need to".

Collapse
 
vonheikemen profile image
Heiker • Edited

Is not a terrible idea.

In PHP you can append an item to an array in two ways

$arr = [];

// like this
array_push($arr, 1);

// or this
$arr[] = 2;

// PHP, why would you do that to yourself?
Enter fullscreen mode Exit fullscreen mode

It certainly could help avoid meaningless discussions. Not so long ago the javascript twitterverse got mad because apparently reduce is like 500 times slower than a for loop, and of course the performance people was all over the place saying: stop using reduce, your killing your app. Think about the children!!

Might also lead to less bugs, because there are less "tricky parts." Consider this javascript object:

const shape = {
  radius: 10,
  diameter() {
    return this.radius * 2;
  },
  perimeter: () => 2 * Math.PI * this.radius
};

shape.diameter();
shape.perimeter();
Enter fullscreen mode Exit fullscreen mode

Even though diameter and perimeter are "methods" one of them raises an error.

Collapse
 
aryamaan08 profile image
Aryamaan08

Apparently, they like to do things in 2 ways, because they have 2 ways of adding a single-line comment.

Collapse
 
prahladyeri profile image
Prahlad Yeri • Edited

Its a good thing actually because it makes a coder's life easier. A hundred ways of defining a classes can easily drive you mad, the loathsome attitude of several JavaScript developers is the blessed proof of that!

But having said that, there could be some benefit in having two or more ways if they achieve some purpose like both targeting catering to different levels of coding expertise. You can use express.js for handling web requests, for instance, or you can do the whole thing purely in node.js by doing the hard work. But that's more like creating abstraction of an existing thing than creating another way of doing the same thing.

Collapse
 
saraahmed626 profile image
Sara °°°

Programming is about solving problems, people solve problems based on the way they think and the way their minds operate, and people minds operate differently.
So the "one way" is not so preferable for me in programming.
As long as the problem is solved, and functioning well; then i think we will be good.

But in the case of a team, some broad line should be followed just to make sure everyone are on the same page.

For me i find a great pleasure when checking different solutions for one problem, it's so fascinating, and that what makes programming fun.

Collapse
 
andyrosenberg profile image
AndyRosenberg • Edited

I understand why others might enjoy a highly opinionated language, but to me, this would suck all the joy and creativity out of programming.

My way of thinking about a problem may not be the same as yours. I should have the freedom of expression to carry out the implementation unique to my thought process, so long as it’s clean and understandable.

Collapse
 
kspeakman profile image
Kasey Speakman

It intuitively seems like a good idea. But as time marches on, you realize that there are nuances to "doing a thing" that make a second (or 3rd or 4th) way preferable under certain circumstances. The real challenge is making it obvious which to use in the right circumstance.

Collapse
 
yechielk profile image
Yechiel Kalmenson

One of the things I loved most when I was learning Ruby was how many ways there are to solve each problem.

When I would complete labs at Flatiron my favorite thing to do was to go to look at other people's solutions. I would always learn new things!

Collapse
 
jaakidup profile image
Jaaki

If there is only one way of doing something and it's the right way to do something, then it's "problem solved" and you can move on to the next issue.

Like when you learn to walk, once you've mastered it, you've got it forever right. Then you can move on to running or jumping etc.

So I supposed when standards are formed, your tool-sets or ides etc. can also take advantage of the fact that it's a proven solution.

Collapse
 
conw_y profile image
Jonathan

You could quit your job by saying "I quit", or you could say something a bit more lengthy and nuanced, like "All good things must come to an end. I feel like it's time for me to move on." They both basically say the same thing, but the second one carries a more information and conveys some depth and emotion.

In their expressive capacity I think programming languages are similar to human languages. That they are ways of expressing intent, not merely ways of getting the computer to do X or Y. For that expressiveness to be possible, it's necessary for there to be more than one way of doing something in a language.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.