Skip to main content
162 votes
Accepted

Why do many software developers violate the open/closed principle?

IMHO JacquesB's answer, though containing a lot of truth, shows a fundamental misunderstanding of the OCP. To be fair, your question already expresses this misunderstanding, too - renaming functions ...
Doc Brown's user avatar
  • 218k
71 votes

Why do many software developers violate the open/closed principle?

Edit: There seem to be some disagreement about what the open-closed principle actually entails. Luckily Bertrand Meyer, who defined the principle, have put his book online, so you can read it yourself ...
JacquesB's user avatar
  • 61.6k
52 votes

Ways to explain code when told it doesn't make sense

Personally, I have encountered multiple variants of code-that-is-hard-to-understand, and each needs a different way to cope with: Simply messy. Formatting is off, variable names are not clear, ...
mtj's user avatar
  • 2,360
21 votes

Why do many software developers violate the open/closed principle?

I would call the open/closed principle an ideal. Like all ideals, it gives little consideration to the realities of software development. Also like all ideals, it is impossible to actually attain it ...
Cort Ammon's user avatar
  • 11.9k
21 votes

Ways to explain code when told it doesn't make sense

The original code is extremely obvious, that is a very good thing. It is boring in the best way, there are no suprises there and you can very quickly see what it is doing. Your code is very abstract ...
Mad Scientist's user avatar
14 votes

Ways to explain code when told it doesn't make sense

With out wishing to be rude, if you find that other experienced engineers are regularly struggling to understand your code, then your actual problem is how to make the code simpler, not how to explain ...
Stormcloud's user avatar
13 votes

Why do many software developers violate the open/closed principle?

Doc Brown's answer is closest to accurate, the other answers illustrate misunderstandings of the Open Closed Principle. To explicitly articulate the misunderstanding, there seems to be a belief that ...
Derek Elkins left SE's user avatar
13 votes
Accepted

Ways to explain code when told it doesn't make sense

Siloed Framework and Infrastructure code is tricky. It is the dark and messy parts of the code base that hit actual walls, and the worst part is that often the solutions are counter-intuitive, as they ...
Kain0_0's user avatar
  • 16.5k
12 votes

Ways to explain code when told it doesn't make sense

Get people to look at your code sooner. Every code base I've ever touched conveys a mindset. A way of looking at things. A big part of my job is molding my brain into something that can work with this ...
candied_orange's user avatar
11 votes

Ways to explain code when told it doesn't make sense

For what its worth, I also find your changed code quite confusing compared to the original code. The original code is beautifully simple. Apart from the interface declaration it is basically a three-...
JacquesB's user avatar
  • 61.6k
7 votes
Accepted

What is the Advantage of React JS over Pure Javascript + PHP?

React competes with Vanilla Javascript, not with server-side functionality¹. Example scenario Consider a simple interactive web application consisting of a slider. When we move the slider, we want ...
amon's user avatar
  • 136k
6 votes

New components that implement an abstract component, vs variants on a single component.

In the clean code book, there is a passage that goes something like: Data structures makes it easy to add new functions without changing the existing data structures. OO code(using objects), makes ...
Shiyason's user avatar
  • 206
6 votes

Why are React keys limited to strings?

Up-to-date as of 2021 They're not, but the React docs encourage the use of strings over any other type. Any data type will "work" (except undefined as @theHutt points out). This is because ...
thebearingedge's user avatar
6 votes

Ways to explain code when told it doesn't make sense

I believe this is a problem with my code, as I cannot recall the last time some else's code has taken an hour of explanation to understand. I'm happy to see this conclusion. Most commonly, people ...
Flater's user avatar
  • 58.1k
5 votes
Accepted

Is undo and redo possible/feasible with two-way data binding (vs uni-directional data flow)?

Typically you implement an undo/redo feature using a command history. Your UI generates commands with execute and unexecute actions, and the underlying model is changed by playing the command's ...
Joeri Sebrechts's user avatar
5 votes

Benefits of using a JS Framework

As with any other question to adopt a technology - it depends on the technology. It depends on your requirements. It depends on any future requirements/the roadmap for the product. It somewhat depends ...
JᴀʏMᴇᴇ's user avatar
5 votes
Accepted

Why are React keys limited to strings?

React writes the key to the HTML and reads it back when parsing the DOM. Since the HTML attribute is a string, whatever value you give it must be serialised to a string. If you wanted to use non ...
Ewan's user avatar
  • 81.9k
4 votes
Accepted

How do functional programming advocates use a framework like React or Angular?

In my previous role we were using mostly pure functions in React. Remember that React is a "library for building user interfaces". Often I see React projects where components are very object-oriented ...
Samuel's user avatar
  • 9,237
4 votes
Accepted

React - When is a backend necessary?

From my understanding, the front end is the UI that the client interacts with, and the back end is the server itself. This is essentially correct. The front end commonly refers to the code that is ...
Vincent's user avatar
  • 544
4 votes

What pattern is a function that returns a component?

"when I look up component factory on Google" This is your problem. "Component" (as well as "pattern") is a extremely generic term, which (even when restricted to the ...
Doc Brown's user avatar
  • 218k
4 votes

What is the Advantage of React JS over Pure Javascript + PHP?

React, Vue, Angular etc provide a MVC style UI framework which HTML + JS doesn't have. I guess the benefits are that by using the framework you get a whole load of common functionality that you would ...
Ewan's user avatar
  • 81.9k
4 votes
Accepted

Monorepo dilemma: Where do you store your common business logics?

When I understand this correctly, you have two different apps, and all shared code betwen them needs to be located in one of the packages. Currently, all of the shared code can be classified as "...
Doc Brown's user avatar
  • 218k
3 votes
Accepted

When does it make sense to make an individual React component?

Had exactly the same question when I started working on rebuilding a new landing page, using Vue. I have gone through several stages of refactoring all the codes, and the rule of thumb is readability ...
Alan Shum's user avatar
3 votes
Accepted

REST: How to deal with relative resources?

Reading resources online, one can get the idea that the REST API is seen kind of like an adapter to the database. That's true, you can get that idea. It's not quite right. The REST API could be an ...
VoiceOfUnreason's user avatar
3 votes

Why is JSX good, when JSP scriptlets are bad?

In short: Front-end developers are expected to know scripting and templating JSX and JSP are both templating languages JavaScript is a scripting language Java is not a scripting language References Is ...
3 votes
Accepted

How to store blog post in database - React & GraphQL

I typically use markdown for blog posts' main content. This sits alongside the blog post's other columns (title, slug, categories, etc). The perks of using markdown is that it can be considered a ...
Daniel's user avatar
  • 148
3 votes
Accepted

How to manage chaotic code explosion in React application

As a relatively senior guy in my org, I just plainly reject PRs that have insane code structure, like 30k lines in a single file (I bet much of that is copy-paste). My suggestion would be to talk to ...
9000's user avatar
  • 24.3k
3 votes

Ways to explain code when told it doesn't make sense

Two suggestions come to my mind: Use models/diagrams to represent the different aspects of your solution/implementation. You can use a paper or a dashboard just to simply draw the ideas/concepts and ...
CicheR's user avatar
  • 139
3 votes
Accepted

Anyone have data on impact on UX of shipping profiling build in production to users?

First and foremost, before you deliver anything with telemetry (and performance monitoring uses telemetry) to send the results to your servers, check with your legal team. Many countries have very ...
Berin Loritsch's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible