643 questions
832
votes
16
answers
419k
views
Order of items in classes: Fields, Properties, Constructors, Methods [closed]
Is there an official C# guideline for the order of items in terms of class structure?
Does it go:
Public Fields
Private Fields
Properties
Constructors
Methods
?
I'm curious if there is a hard and ...
423
votes
3
answers
189k
views
How to identify unused CSS definitions from multiple CSS files in a project
A bunch of CSS files were pulled in and now I'm trying to clean things up a bit.
How can I efficiently identify unused CSS definitions in a whole project?
130
votes
9
answers
106k
views
Is there a script to list git branches created by me?
I'm aware that branches don't really store creator information - and they're just a pointer to a commit.
My goal is to be able to clean out my old branches that have been merged back to the main ...
122
votes
5
answers
127k
views
Sublime Text 2: Trim trailing white space on demand
I know that Sublime Text 2 can delete the trailing white space on files upon saving.
When working in a team and commiting a change to a file this tends to produce huge diffs which make peer code ...
78
votes
7
answers
29k
views
Finding dead code in large python project [closed]
I've seen How can you find unused functions in Python code? but that's really old, and doesn't really answer my question.
I have a large python project with multiple libraries that are shared by ...
73
votes
12
answers
195k
views
Clean react native project
How to clean react native project?
Is there any way to clean react native project as we can clean xcode project?
Any help will be appreciated!
66
votes
5
answers
37k
views
Ignore camelcase variable in JSHint
Having a bit of an issue with JShint and the following line of code.
$location.path('map-' + map.id + '/venue-' + map.attributes.default_venue.value);
I'm getting the error, Identifier 'default_venue'...
51
votes
5
answers
19k
views
Indenting preprocessor directives with clang-format
I am working on a c++ project where I am using a lot of #pragma omp. I use the wonderful clang-format for tidiness but it always deletes the indentation for all preprocessor directives. Is there a way ...
40
votes
3
answers
119k
views
How to project clean in Android Studio?
I am new in Android Studio so I face some problem with it. I am looking for a way how to project clean.
In Eclipse I would do Project -> Clean -> OK but I don't know how it is done with Android ...
39
votes
6
answers
81k
views
How to call a function by its name (std::string) in C++?
I wonder if there is a simple way to call a function from a string. I know a simple way, using 'if' and 'else'.
int function_1(int i, int j) {
return i*j;
}
int function_2(int i, int j) {
...
35
votes
6
answers
25k
views
How do I initialize classes with lots of fields in an elegant way?
In my application, I have to instantiate many different types of objects. Each type contains some fields and needs to be added to a containing type. How can I do this in an elegant way?
My current ...
32
votes
11
answers
11k
views
Formatting Clear and readable SQL queries
I'm writing some SQL queries with several subqueries and lots of joins everywhere, both inside the subquery and the resulting table from the subquery.
We're not using views so that's out of the ...
32
votes
3
answers
54k
views
Removing unused code in Visual Studio [duplicate]
In relation to this question: "Remove unused references (!= "using")", I would like to know if there is a tool for removing unused classes, structs, delegates, etc from a Visual Studio ...
28
votes
4
answers
19k
views
How to find out if certain javascript code is actually used?
I am doing some JavaScript cleanup work on a legacy project, and trying to get rid of redundant JS libraries. I have done all the obvious ones (those that are not references from anywhere at all). But ...
27
votes
2
answers
33k
views
What are VSSVER.SCC files, and can I delete them?
I've inherited a ASP.Net 2.0 (File System) Web Project from a client, where a few different companies have worked on this project in recent years. The project has been handed from one company to the ...
26
votes
5
answers
35k
views
Sort "usings" directive by ReSharper Clean-up
How to setup ReSharper to call "Sort usings" in class?
25
votes
11
answers
58k
views
How to remove extra empty lines from XML file?
In short; i have many empty lines generated in an XML file, and i am looking for a way to remove them as a way of leaning the file. How can i do that ?
For detailed explanation; I currently have this ...
21
votes
9
answers
25k
views
How to prevent null check before equals
I find stuff like this rather annoying and ugly in equals methods:
if (field == null)
{
if (other.field != null)
return false;
}
else if ( ! field.equals(other.field))
return false;
...
21
votes
3
answers
22k
views
Is there any tool / way to detect/remove all unused variables,macros,headers(includes) and functions from c++ code?
I had to customize some projects which have been written for some other purpose but some core functionality is same for my project and works as it is. But There are lots of variables, macros,functions ...
20
votes
5
answers
17k
views
How do I get rid of existing whitespace in my initial commit?
I've accidentally put some whitespace in my initial commit. It shows up red in git diff --color. How do I get rid of the existing whitespace and how can I avoid this from happening again?
20
votes
1
answer
18k
views
"Code Cleanup..." feature of Android Studio v2.2.2
In Android Studio v2.2.2, Code Cleanup feature available under Analyze option.
Analyze >> Code Cleanup
What this option exactly do with code ?
Please explain in details.
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....
18
votes
5
answers
1k
views
Is there any way to find unused CSS in a website?
Is there any way to find unused CSS in a website?
I'm trying to clean up a project I just inherited.
17
votes
1
answer
17k
views
What are the differences between make clean, make clobber, make distclean, make mrproper and make realclean?
I don't always write make files but when I do I like to try and write them well. Trying to make the interface consistent with what other developers might expect is always a struggle. What I am ...
16
votes
3
answers
6k
views
Clean way to return an array from X.times in Ruby
I often want to perform an action on an array X times then return a result other than that number. The code I usually write is the following:
def other_participants
output =[]
...
15
votes
3
answers
2k
views
How to share Visual Studio 2022 Code Cleanup settings with team
Hi I am using Visual Studio 2022. I want to share code cleanup on save setting with my team. How can i do it? I tried to export settings and import it but without success.
14
votes
1
answer
5k
views
Makefile: reuse value of % of a pattern rule inside the recipe
In a Makefile I have:
images/schematic.pdf: images/schematic.svg
inkscape -D -z --file=$^ --export-pdf=$@ --export-latex
sed -i "s:schematic:images/schematic:g" $@_tex
What this ...
14
votes
3
answers
5k
views
Removing unused libraries in R
So I just finished up writing my first script to assemble a Weibull Analysis from a text file. In all of my tinkering I suspect I may have loaded some libraries that aren't used in the final script. ...
12
votes
4
answers
12k
views
Avoid using static access to Exception
I've just fired up PHPMD for the first time and, predictably, I've got an error I can't figure out. The error is
Avoid using static access to class 'InvalidArgumentException' in
method 'setLang'.
...
12
votes
1
answer
4k
views
ReSharper and StyleCop vs. the step-down rule (Clean Code)
I imagine that this may be a bit of a divisive post, but it's something I've been struggling to articulate for a while, and I'd like to put it to the wider development community.
I work in a role ...
12
votes
1
answer
1k
views
How to find unused template variables in Django
I'm doing clean up on django code - my IDE can easily detect unused variables etc in Python code, but I haven't found a way to find unused template variables - it would be much easier to clean up the ...
11
votes
5
answers
2k
views
Is it ok to use lambda just locally? [closed]
Is it alright to define a lambda function to be used only locally, that is in the current block (function/method)? Consider the situation when some code is going to be executed several times (so it'd ...
10
votes
8
answers
9k
views
How to remove System.out.println's from codebase
We have a huge (old legacy java) code-base, where many files (around 5k) have System.out.println's. We are planning to remove them for cleanup/performance reasons. How can we write a script that will ...
10
votes
4
answers
9k
views
How to bulk cleanup imports in Java with Eclipse? [duplicate]
On a generated project I get 100s of warnings caused by unused imports and such things. Can I bulk cleanup those imports for all files?
10
votes
3
answers
7k
views
Is it possible to sort code via Resharper?
CodeRush has this nifty plugin called cr_ClassCleaner that allows me to sort the elements in the class (e.g. methods, private variables, etc...).
Can Resharper 5.x do this, either via the product ...
10
votes
3
answers
988
views
Python: Detect code which gets never executed in production
I need to do refactoring in a big legacy Python code base.
Often I think "these lines don't get executed in production any more".
But I am unsure.
There are some tests which touch these lines. But ...
10
votes
1
answer
2k
views
Code Cleanup doesn't do Format document in Visual Studio 2022
I have the following settings regarding my Tab sizing in Visual Studio 17.4.1:
When I use Edit->Advanced->Format Document, I get this result:
I configured Code Cleanup which allegedly contains ...
9
votes
2
answers
6k
views
Alternatives to -Info class name suffix
I've been reading Clean Code by Robert C. Martin, and came across the infamous statement:
Avoid words like Manager, Processor, Data, or Info in the name of a
class.
So, naturally, I've tried to ...
8
votes
7
answers
4k
views
How to make this C++ code more DRY?
I have these two methods on a class that differ only in one method call. Obviously, this is very un-DRY, especially as both use the same formula.
int PlayerCharacter::getAttack() {
int attack;
...
8
votes
5
answers
6k
views
reducing number of return statements in a method
I have a java code in which there are multiple return statements in a single method. But for code cleaning purpose, I can have only one return statement per method. What can be done to overcome this.
...
8
votes
2
answers
2k
views
Clean code - best way to compact code in Java
I have code that looks like this:
for(int i=0; i < a; i++){
List<Integer> list = elementA.get(i);
SomeClass rg = new SomeClass(list, a, methodA(i));
int result = ...
8
votes
1
answer
3k
views
Can I run EditorConfig over C# Files From the Command Line?
Newer versions of Visual Studio Support EditorConfig within the IDE which is useful, however it would be best if I could run it from the command line (and therefore in automation).
Is there any stand ...
8
votes
1
answer
654
views
How to stop VS from removing "unused" namespaces if they are actually used in preprocessor directives?
I'm using Visual Studios Code Cleanup on Save to automatically clean my code when i save. It also removes unused namespaces. But now i noticed that it even removes namespaces when they are actually in ...
8
votes
3
answers
3k
views
Determining which PHP source files are not used
I have a large web app, and I think there are a bunch of old files that are no longer being used, is there an app which can tell me what these files are?
7
votes
1
answer
19k
views
del self vs self.__del__() - and what is the proper way to cleanup in python?
I have a python script that contains a class.
This class has a __del__ method for usual cleanup. If I delete the class during the normal execution of the script, I want some cleanup to be done.
I ...
7
votes
2
answers
2k
views
Clean code - Dependency injection
I was wondering if there is a "cleaner" solution to using dependency injection with binding to classes with a lot of arguments, since according to Robert C.Martin's Clean Code, it's better not to use ...
7
votes
2
answers
2k
views
Remove unused css from multiple pages at the same time (whole website)
I 've searched on google some online unused css removers that you have to pay. I also checked here on stackoverflow for programs that might do that. I only found an easy way via google chrome.
...
7
votes
3
answers
10k
views
Refactoring exercises in Java
I have just been through the following paper and I found it extremely useful:
http://www.objectmentor.com/resources/articles/Clean_Code_Args.pdf
I am looking for similar papers/books/tutorials/etc. ...
7
votes
3
answers
11k
views
RxJS Refactor nested map statement
I have a service which uses @angular/http to load data from an API.
I want to create a projection of the retrieved data for my Components using this data.
Therefore I wrote the following code:
...
7
votes
3
answers
2k
views
Which is preferred way to use connect() from react-redux, Parent vs Child component?
I am little confuse in the efficient way to use connect() from react-redux library. I have the blow component
class SignUp extends React.Component {
//some functions
render(){
return (
<...