643 questions
1
vote
2
answers
50
views
Link simillary name classes so that when one is clicked the other is given a class
Basically, I'm asking for a way to optimize this code. I'd like to cut it down to a few lines because it does the same thing for every click bind.
$("#arch-of-triumph-button").click(function(){
...
5
votes
1
answer
5k
views
How to name the domain services in DDD
I'm new in DDD and I am getting an issue while writing a new project using DDD principles and it's about creating domain services. I always named my services with the corresponding domain object name ...
2
votes
2
answers
4k
views
Haskell - Elegant code for detecting if number is in range
I'm writing my homework and I found piece of code I don't think is elegant enought..
Exactly :
if n >= min && n <= max
then ...
else ...
I want to ask if there is any more ...
-2
votes
2
answers
52
views
Speed over style in C? [closed]
What is more important readability or speed?
Example:
Say you create a lot of resources in one method and if some operation fails you have to free the ones which were successfully created. Would you ...
0
votes
3
answers
1k
views
Pattern for cleaning up event handlers automatically, similar to subscriptions deterministically
I'm familiar with the patterns that are used to clean up subscriptions on observables as outlined here: Angular/RxJs When should I unsubscribe from Subscription
But is there a similar pattern for ...
1
vote
0
answers
58
views
Is there a way to improve the code quality by injecting/importing a service into a class that is not a component/service/repository?
In this example, I will be using 2 files ( LogService and LoggedConflictException ).
I would like to inject LogService into LoggedConflictException class, instead of passing it via the constructor or ...
1
vote
3
answers
511
views
Difference between creating a dictionary by reduce on an array vs by assigning each item on iteration
I came across a question on StackOverflow: Swift - Convert Array to Dictionary
where the user wants to take the elements of an array and wants to put them in a dictionary and assign 0 to each of them. ...
4
votes
0
answers
849
views
Automatic refactor of sonar qube rule Private fields only used as local variables in methods should become local variables
We are using SonarQube Server for a big java application. (IDE = Eclipse + SonarLint plugin). Rule Private fields only used as local variables in methods should become local variables is violated in ...
0
votes
0
answers
291
views
Ignore camelcase check for particular variable in jshint
We have used few global variables which are not camel case. Ex. lang_code.
We can not make this variable camel case.
I know there are ways to avoid checking camel case at file level and function ...
0
votes
2
answers
142
views
How do I make VBA code cleaner and with less points?
I'm opening a file to read your data, but I think the code is too big, would you have it smaller or cleaner?
Private Function HeaderValidation(workbook As Workbook, nameInstitution As ...
0
votes
2
answers
133
views
Should I call all methods from one main method, or call next method at the end of current?
If I call method makeDinner(), and this method has submethods prepareTomatoes() and prepareMeat(), should I
a) call them both from makeDinner() or
b) call prepareTomatoes() and at the end of that ...
2
votes
0
answers
75
views
How do I make this piece of code clean and fast
I have about 20 lists that I'm appending to in each iteration of a loop if some checks are passed. The appended values come from a nested dictionary and as you can imagine, writing these one by one ...
1
vote
0
answers
1k
views
How to properly clean up a Windows Service and its account?
We have this service that needs some special file permissions and we are therefor running the service within his own virtual service account:
The service exe is installed using installutil.exe c:\...
0
votes
1
answer
55
views
How can I write this code to be more efficient
I am learning Vue.js and I am setting up a website where I am using LocalStorage to store data.
I wrote some code, which is a little clunky and very repetitive:
<script>
const app = new Vue({
...
-1
votes
2
answers
44
views
How can I turn the reverseString function into a variable like sum. Is there a difference?
I want to learn how to clean my code up and I feel like the reverse string function can be turned into a variable. Is this possible?
function reverseString(str) {
return str.split('').reduce((...
1
vote
1
answer
854
views
Python multiprocessing: How to shutdown a long running process that is a sequence of actions
I want to use multiprocessing to run simultaneously several processes of a series of lengthy actions (e.g. clicking through programs simultaneously using computer vision). I want to implement a stop ...
1
vote
2
answers
1k
views
Clean code -- Java static functions and variable reuse
I am trying to clean up a static function. Let me provide a template of this function here. It is a static function and is used only in two places in the code base one where the isClient is true and ...
1
vote
1
answer
686
views
Sanitizing the code as per wpcs for yoda condition checks
i am trying to cleanup the file with phpcs --standard=Wordpress ../filename.php . But it seems phpcbf is unable to perform the action. So, can anyone share some help as how can i manually fix these ...
-1
votes
2
answers
1k
views
C#- Using IClientChannel interface without implementing all methods, and/or without casting in a messy manner
Software Environment Details:
Visual Studio 2017
.NET Framework 4.5
We have a WCF Service and WCF Client Library C# library.
In order to adhere to proper coding practices, I want the WCFService that ...
0
votes
2
answers
543
views
Need help Improving Basic C# Calculator [closed]
I made this Basic C# Calculator to reflect on what I've learned these past few days. I'm an absolute beginner and I wanted to get suggestions on improving and shortening it.
I've tried to add switch ...
0
votes
4
answers
88
views
How can I simplify this expression?
I want to check whether some strings and their lowercase variants can be found inside another,but my code seems pointlessly complex.
this works, but I want to know whether a cleaner variant exists:
...
0
votes
1
answer
110
views
I Need Assistance With Data Sorting In Python Code
In my Python Code, I would also like Dakota with Hurricane, display appearances to show, in the Data Table, when run in Jupyter Notebook.
I typed the following modification to the Code, aiming to ...
0
votes
2
answers
2k
views
How to check if object is of any of given types in C#
I am working with Unity Engine where there is a base class Component and multiple classes deriving from it, including Transform, MeshRenderer and many classes created by me.
I want to execute an ...
1
vote
2
answers
855
views
How to eliminate method side effects?
I try to be careful about SOLID and clean code principles. I think I fall into side effect error. When I trigger a method it must get data from another service and insert to database:
//when I call ...
0
votes
0
answers
35
views
How to optimaly merge two arrays of different objects based on an attribute?
First question here (I mean like ever), so sorry if I posted at the wrong section or haven't found an already given answer.
I have 2 arrays of objects. The first one, lets call it oldArray has 1000 ...
2
votes
5
answers
255
views
How to replace many if's statements in java?
I am trying to make my code "cleaner". I have many functions with a lot of if-statements. How can I replace them?
I'm using 4 differents Hashtables that's why I have those ifs. The only thing ...
0
votes
2
answers
797
views
Python Repo Cleanup
I have a script that I have almost 100% complete however there is just one more step that I can not figure out. My script currently checks the destination to see if the file already exists and if it ...
3
votes
1
answer
2k
views
Visual Studio code cleanup - where is configuration?
When I open Configure Code Cleanup in VS 2019, there are entries like "Apply expression/block body preferences".
Where are those "preferences"? How can I configure this tool?
0
votes
1
answer
183
views
How to cleanup long if else statements that do almost the same thing
So I have this long stretch of c# code (forgive me im a beginner and its messy) but I basically want to repeat all the steps but also output the text to result to a file if "-o" & a filename (...
-1
votes
1
answer
904
views
Private methods in amongst Public methods [closed]
Suffering insomnia at 5am & so reading Clean Code (by Robert Martin). This book is often seen as a Bible for coding structure and so I was interested to see he suggests the 'Newspaper' analogy ...
2
votes
0
answers
101
views
Clean memory on multiple returns - Function C++
I am using a function with multiple return paths. But on every one of them I need to clean the memory,release some objects,etc. I have seen on the internet some methods but I don't think they are "...
4
votes
2
answers
820
views
How to clean code too much if else with enum
I have the below code to write. It is taking one kind of enum type and return other enum value. How to remove the too much if else condition in the code and make it clean?
private static QuestionType ...
4
votes
2
answers
5k
views
RxJava Conditional FlatMap Cleaner Way
I'm looking for a cleaner way on how to create a conditional flatMap(), I've read this but I'm having trouble applying it on my code:
// given variables for the sake of simplicity
val stringSingle = ...
2
votes
1
answer
94
views
TypeScript Interface Templating
I'm not too sure one correct terms for using TypeScript. But I feel like I'm repeating myself and would like to template my interface better so be less confusing.
I've got a type which is basically a ...
0
votes
2
answers
2k
views
Kotlin nested for loops to asSequence
I'm trying to convert my nested for loop to asSequence in Kotlin. Here, my goal is to get and update the value of all my object array from another object array with the same key.
nested for loop:
...
2
votes
1
answer
326
views
Which design pattern solve the multiple rules checking?
I want to save some files of an article which are posted to an ASP.NET MVC Core action. Then i have them as IFormFile in HttpContext. These files can be image, video, and document. Each of these file ...
19
votes
2
answers
7k
views
Setting up C# editorconfig Code Cleanup on build/save and commit
Our team want to enforce styling rules in our C# project. I read somewhere some time that Microsoft said that ".editorconfig is the future" so we want to use this. NOTE: We don't want to use ReSharper....
0
votes
1
answer
248
views
which one is good way to implement Switch Case for below code?
Most of the place I found use polymorphism instead of Switch case statement. I know it is better to use polymorphism if all the case are different in switch case.
what happen if few cases have same ...
1
vote
0
answers
84
views
Best practice for handling an args dictionary: unpack into individual variables or pass dictionary around?
For example, the following code gets very lengthy. I then have to pass these each into their relevant functions. The benefit here is that I can easily specify defaults all in one place (for me the ...
1
vote
2
answers
1k
views
Can I force PHP 7.1 syntax to require type hinting in return types?
From PHP 7.0 it is possible to set the return type in the functions.
But you cannot force it as the void return type is not supported by the language and it would be difficult by the static analysis ...
3
votes
1
answer
4k
views
Scala - Try transform vs match vs map method
I have read about transform method on Try and compare this method with other methods to figure out which one will be more clear for coding. I show you the code below
val value: Try[Int] = Try("1"....
0
votes
1
answer
218
views
How to remove multi line code in java / netbeans?
I've got a lot of code that is segmented into separate lines in netbeans. I believe it's auto formatting it and when I change any formatting in the editor options it seems to not like it.
An example ...
0
votes
0
answers
87
views
How to use single responsibility with functions
I've just read the book called clean code. The author Uncle Bob talks about a single responsibility that a function should have in a program. It should only do one thing.
Now, I would like to ...
-1
votes
1
answer
186
views
Single responsibility and methods
I think I might answer my own question here but lets say I understand the SRP on the method level to mean that a method serves one role. If I have methods that each individually cover one specific ...
0
votes
1
answer
34
views
Identifying color properties from CSS and combine selectors?
I'm looking for a tool that helps me to identify CSS color properties (color, background-color, border-color etc.) and combined the selectors instead of repeating the color property over and over.
so ...
2
votes
3
answers
134
views
Rewriting an if statement which throws an exception in a cleaner way
Let's suppose we have an if statement like this:
public A save(A a) {
if (isValid.test(a)) {
return aRepository.save(a);
}
throw new ANotValidException("A is not valid");
}
...
-2
votes
3
answers
64
views
Improve Python if conditional [closed]
How to improve the following if conditional in Python 3.6 to one line.
def run_cmd(beta: bool): {
cmd = "cloud create {}".format(self.name)
if beta:
cmd = "cloud beta create {}".format(self....
2
votes
0
answers
45
views
Is it legit or bad practice to move utility methods into abstract superclass?
I have an interface with its implementation. The public interface methods are using many private methods for doing calculations:
public class FooServiceImpl implements FooService {
@Override
...
0
votes
1
answer
259
views
Monitoring of .net applications at runtime [duplicate]
There is a system composed of an ASP.NET web application, .NET windows services and shared .NET libraries. It has large number of classes, each containing multiple methods.
How to conveniently ...
0
votes
2
answers
4k
views
Elegant way to set values in a nested json in python
I am setting up some values in a nested JSON. In the JSON, it is not necessary that the keys would always be present.
My sample code looks like below.
if 'key' not in data:
data['key'] = {}
if '...