Hot answers tagged

152

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 breaks backwards compatibility, but not the OCP. If breaking compatibility seems necessary (or maintaining two versions of the same component to not break ...


69

The open/closed principle has benefits, but it also has some serious drawbacks. In theory the principle solves the problem of backwards compatibility by creating code which is "open for extension but closed for modification". If a class has some new requirements, you never modify the source code of the class itself but instead creates a subclass ...


54

Inconsistencies make you stop and think why, which and where: When you read part of the code and see that it uses a different style from the rest of the code, it makes you wonder - why is this particular part different? Does it have a special reason that I need to be aware of? This is dangerous, because if there really is a reason for that part to be ...


52

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, convoluted control structures, methods with multiple responsibilities. => Learn cleanliness, use a formatter. Patternitis: applying patterns for each and every ...


49

Code Transfer Advantage Following patterns provided by a library, React in your case, means that the product you deliver will be easily picked up and maintained by other developers who are also familiar with React. Potential Backward Compatibility Issues Some libraries would have a new major version out, and backward compatibility might be compromised if ...


31

This is a valid concern. While I have not measured the memory usage of Redux applications, I think that before committing to use Redux (or any other framework for that matter) you should create stress tests that emulate the data amounts, change frequency, and computation intensity of the application you are going to build. Use these stress tests before ...


26

Stick to the convention of the language and the framework - in your case, React.js seems to be follows the Javascript conventions so there is no conflict. camelCase for variables and functions, PascalCase for types(classes), and UPPERCASE_SNAKE_CASE for constants.


24

Ok let me explain you from Step by Step 1 What is Flux? A pattern Centralized dispatcher Unidirectional data flows List item They call it Flux for a reason too. Flux Implementations Facebook’s Flux Alt Reflux Flummox NuclearJS Fluxible A Chat with Flux React : Hey Action, someone clicked this “Save Course” button. Action: Thanks React! I registered an ...


20

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 in practice -- one merely strives to approach that ideal as best as one can. The other side of the story is known as the Golden Handcuffs. Golden Handcuffs are ...


20

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 and hides what is actually happening in your reducers. If I were entirely new and had to understand the codebase, it would be much harder in your example. And ...


13

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 have to work around the user (aka. programmer), language decisions, and platform idiosyncrasies. What has happened is that you've become an expert, and become ...


13

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 the complexity. If you are working as part of a team your first priority is to make your code as readable as possible. Sooner or later somebody is going to ...


12

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 existing mindset. This can be jarring if the mindset clashes with my personal style. I try to put more effort into being effective with the existing mindset ...


11

Primarily, the people who created JSX disagreed with the people who disliked JSP. See their discussion here: Why did we build React? as well as Displaying Data Templates is based on the idea of creating a division between the logic and presentation of a page. On this theory your javascript (or java) code shouldn't be concerned with what markup gets ...


11

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 the OCP means that you should not make backwards incompatible changes (or even any changes or something along these lines.) The OCP is about designing ...


11

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-way switch. Your code is a lot more complex including a factory, a builder pattern and something called a randomIdentifier (WTF?). Complexity leads to bugs and ...


6

It doesn't matter. All that matters is that you make a choice and stick to it. When you are using a framework, it can be useful to copy its convention to get more consistent code, but when you are using more than one and they follow different conventions, that's futile.


6

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 it easy to add new classes without changing existing functions. I think the biggest difference between the 2 approaches is the first 1st gives you the ability ...


6

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 blame others for not understanding. It shows you can see things from other people's perspective, which is going to help you solve this issue. Specifically, when ...


5

As an outsider to React, I viewed JSX as being yet another "framework smell" in the very crowded zoo of framework stinks. I'm still not convinced that this isn't the case. I think a workable definition of "useful" is that a library/framework/pattern solves more problems than it causes.I'm not yet convinced that JSX fits that definition. It's the ...


5

You're asking the classic multi-tenant question. Personally I would - and have - maintain a single copy of the application. It would look up the subdomain in the db to grab a site id, grab the info about the site, and show the relevant content. Templates and images can be stored by putting them into a directory named the same as their subdomain or site ...


5

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 execute action on it. Then navigating the undo/redo history is just performing execute or unexecute actions on the "current" command and updating the history's ...


5

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 on the various skills in your team too. Broadly speaking (very broadly), JS frameworks will do the heavy lifting when it comes to binding your data to your ...


5

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 strings you would require a de/serialiser and possibly a second attribute in the HTML element to indicate the type of the key value. Also remember this is ...


4

The core problem is communication. Some key developers are located in another state and their input has been difficult to come by. I decided to bring on one of these remote developers to the UI work. Immediately we began to discover holes in the information such as there is a legacy convention to use bootstrap classes to achieve a flow layout (row-fluid). ...


4

There is a github issue in the react project about exactly this. According to this github issue comment: For complex components, defining shouldComponentUpdate (eg. pure render) will generally exceed the performance benefits of stateless components. The sentences in the docs are hinting at some future optimizations that we have planned, whereby we ...


4

The code may be well written yet not perfectly consistent, so some clients won't care. When things start to go bad, do you want to give them another knock against you? If I hired a company to work on a multi-developer project and they didn't indicate to me that they have a coding standard and follow it, I would be skeptical. We need to keep a fast pace ...


4

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 executed in the user's browser, while the back end is the code that is executed on the server. The first approach is to use React to generate a UI, and then ...


3

AngularJS is a full-featured front-end framework. It takes care of the three parts of MVC, plus the structure of the overall application (dependency injection, routing, ajax, etc.). You don't need React for Angular. You actually don't need anything else than Angular. ReactJS is a specific library for the "V" part of MVC. It's only about the view. If you don'...


3

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 adapter for any number of different implementations. That's part of why the REST architectural style was so effective; clients and servers are able to ...


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