CleanCode | concepts described in Uncle Bob
kandi X-RAY | CleanCode Summary
kandi X-RAY | CleanCode Summary
An experiment in trying to automate some of concepts described in Uncle Bob's books on Clean Code.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of CleanCode
CleanCode Key Features
CleanCode Examples and Code Snippets
Community Discussions
Trending Discussions on CleanCode
QUESTION
I have an array like this:
...ANSWER
Answered 2021-May-05 at 15:35This is easy enough to do with plain JavaScript (see Array.prototype.reduce
) if you didnt want to use lodash, for example:
QUESTION
I have a new MacBook Air with the M1-CPU. I have installed eclipse and I can code with the IDE, but I can't open a .jar-File because it is grayed out. My target is, to open the file with eclipse, so that i can edit the file.
Eclipse-specifications:
Version: 2020-12 (4.18.0) | Build id: 20201210-1552
When I would try to open the .jar file without a IDE it comes a Error with the massage:
"CleanCode.jar" cannot be opened because it comes from an unverified developer.
Then I opened it with control:
macOS cannot verify the developer of "CleanCode.jar". Do you really want to open the app?
I accepted and then comes this Error:
Failed to launch the Java app.
In the Console I run this command:
java -jar Downloads/CleanCode.jar
And the Output was this:
Error: Invalid or corrupt jarfile Downloads/CleanCode.jar
My Settings:
java --version
Output: java 16 2021-03-16
I have installed Java SE Development Kit 16 for Mac and this Java Version 8 Update 281
...ANSWER
Answered 2021-Mar-26 at 16:08I have solved the problem. I do not have to click on "open", I have to click on Import. After I need to check the "Existing Project into Workspace" under "General". Then I can select the Jar-File as a Archive file and can open it.
QUESTION
In a clean architecture approach to software the entities are the innermost layer and should not depend on something like an ORM.
For convenience I would like to use an ORM in my project and gorm seems to be a popular library. In the gorm docs the recommended way to use it is by having the gorm.Model
struct included in the structs you want to persist in the database.
When trying to use gorm in my project and following clean architecture I thus end up with a mapping layer which maps my entities to and from a persistence model specific to gorm in order to keep the gorm dependency out of my entities. This seems to eradicate all the benefits of using an ORM and in e.g. this blog post is explicitly warned about.
It seems to me avoiding the mapping layer while following clean architecture can only be achieved by using a less invasive ORM or even just a sql extension like e.g. sqlx where I can use my entities directly?
...ANSWER
Answered 2021-Jan-31 at 18:52I have a feeling this question is better suited to Software Engineering SE but I will make an attempt at answering.
The short answer to your question is: Yes.
If you want to follow Clean Architecture to the letter, the thing to do is build domain models that don't depend on your persistence layer at all. With gorm, that necessitates building a domain <-> persistence model mapping layer and all the added complexity that comes from that. Gorm will still make querying and saving that persistence model easier than creating your own queries, and compared to ORMs in other languages that I've experienced, it's still fairly lightweight.
Technically you do not need to have gorm.Model
in the model structs. Having an ID int
field, plus any of the CreatedAt
, UpdatedAt
, DeletedAt
fields that you want is enough (this is what gorm.Model gives you). But invariably you will be adding other artifacts that are to do with how gorm does things, so you do not escape this dependence if the gorm
package isn't present in your model structs.
This begs the question of whether following Clean Arch to the letter is the right decision for your project. Like all design decisions, it bears tradeoffs and makes more or less sense according to the scope and complexity of the system being built. If you foresee challenges that your project will run into that Clean Arch can mitigate then the extra investment now will pay off. If, on the other hand, aspects of the architecture are there to mitigate problems you're unlikely to run into in your particular situation, then you may be more forgiving. The conclusion to the blog post you linked makes an argument along the same lines:
NHibernate provides the best set of trade-offs between the implementation complexity and the overall purity. There still will be ORM concerns leaking into your domain model, however. But I think it’s a low price for all the benefits you’ll get out of it: speed of development, rich functionality, and separation of concerns.
QUESTION
Hi I have a Json api for blog, In which I want to test and return one blog that has the highest likes but I couldn't get that done for two days now and I really made research and I can't solve am using JEST to test. I'll appreciate your help. Here is the api.
...ANSWER
Answered 2020-Nov-23 at 20:36Math.max must take more then one parameters, and it will return the greatest, with one argument it will always return that one immediately.
You need to persist the current greatest between function calls like this
But i would not loop at all and use a one liner
QUESTION
From what I understood in Clean Architecture, the objects in the Interface Adapters layer adapts the application's core to possible different infrastructures. That way the application's core can take input from different sources, like HTTP requests and console commands.
Generally a Controller
takes the input and a Presenter
gives the output, since the Controller is an adapter, it may be required to transform the given input to a different format accepted by the Use Case Interactor
. In this case, what happens when the Controller gets a bad input? How can it tell the client that an error happened, since the output is given by the Presenter?
EDIT:
Thinking better, the Controller
should not care whether the input is valid or not, It should try to always convert the input, even if it's needed to convert an invalid input to another invalid input. The UseCaseInteractor
should always return a meaningful response, it should not propagate exceptions to the caller. So when the Controller
gets bad input, it simply sends bad input to the called interactors, which can then properly handle bad inputs (it's application logic) and present error message through its presenters. For the Controllers input is input, its job is to adapt at best, am I right?
ANSWER
Answered 2020-Sep-14 at 04:06You got it in your "edit". The actual input validation should happen on the business logic, in the use case interactor. The controller does the "simple" data transformation.
Example: The view sends a date string. The controller tries to convert it into a Date object. In case the input string is not a valid date format the controller passes this information to the use case interactor e.g. as null or as option in functional languages or as any other type which makes it clear to the use case interactor that the input date was invalid. The use case interactor then decides how to handle this input.
QUESTION
So I have this data, which contains an array of objects, the objects are blogs info, and they have authors, title, likes, link, etc.
What I wan't to do is get the author with the most likes across this array of data.
...ANSWER
Answered 2020-Jul-16 at 23:15One way to do this a little more cleanly is to create a single object like this:
QUESTION
const mostLikes = (blogs) => {
if (!blogs.length) {
return 0
}
const distinctAuthors = [...new Set(blogs.map((blog) => blog.author))]
const summer = (prev, comp) => prev.likes + comp.likes
console.log(distinctAuthors)
const dummyAuth = {
author: 'hmm',
likes: 0,
}
const authorsWithLikes = distinctAuthors.map((author) => ({
author,
likes: blogs.filter((n) => n.author === author).reduce(summer, dummyAuth),
}))
const reducer = (prev, comp) => (prev[1] > comp[1] ? prev : comp)
return authorsWithLikes.reduce(reducer, authorsWithLikes[0])
}
...ANSWER
Answered 2020-May-07 at 17:34It looks like you have undeclared variable author
:
QUESTION
Well, I have the following flow in my application:
...ANSWER
Answered 2020-Apr-13 at 05:43Gateways/repositories usually work with entities. Gateways create entities from data sources and update data sources from entities.
QUESTION
Ok let me explain my requirement shortly. I have a portal where suppliers can register and add their content to our site. Usually, registration has 5 steps where after the supplier completes the first registration step then the user will be logged into the system and also it also update the registration_step
column in the DB table. After the supplier completes his 1st step he can log out and then once he logged in again then the user will not be able to go another URL till he completes all steps in registration. SO I have tried to accomplish this with middleware like below. Please note there are 3 different types of users in this system.
ANSWER
Answered 2020-Apr-03 at 18:13Your'e getting redirected because it's checking the condition and redirecting to the same route but you don't check if the current route is not the redirecting route. You can add another check to the condition to check if the route isn't the redirecting route.
QUESTION
The following three goals leads to a conflict:
- I've learned, that
std::move
does nothing, but afterstd::move(someDObject)
the ObjectsomeDObject
may be canibalized and you should not accesssomeDObject
- CleanCode-SingleResponsibiliPattern: a class should be responsible for just one Feature
- CodingStyle-DataEncapsulation: a class should not expose implementation details, even not to a derived class
Imagine a (not Copy-constructible) class with two distinct Feature. Cause of SRB one of them is realised in Base
and second realised in Derived : public Base
. Both classes hold their data in a movable Conainer like std::list
, called m_dataDerived
and m_dataBase
respectivly. Cause of DataEncapsulation m_dataBase
should be private:
.
This leads to the problem how to implent the move-Constructor for the derived class. Either:
...ANSWER
Answered 2019-Dec-13 at 13:36Derived::Derived(Derived &&rhs)
: Base(std::move(rhs))
, m_dataDerived(std::move(rhs.m_dataDerived))
{}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CleanCode
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page