Questions for best practices for writing high quality code.

learn more… | top users | synonyms

8
votes
5answers
208 views

Gathering all data in single iteration vs using functions for readable code

Say I have an array of runners with which I need to find the tallest runner, the fastest runner, and the lightest runner. It seems like the most readable solution would be: runners = getRunners(); ...
2
votes
1answer
1k views

Static code analysis for bash scripts

I program CLI utilities in bash to automate much of my work as a DBA. I would like improve my code and make it more robus,t maybe with the help of some static code analysis tool like the one I used ...
45
votes
19answers
3k views

Forcing people to read and understand code instead of using comments, function summaries and debuggers? [duplicate]

I am a young programmer (finished computer science university but still under a year of working in the industry) and I recently got a job working on some C code for a decent size web service. Looking ...
6
votes
5answers
453 views

Why would a developer create a public class that has all static properties?

A previous developer has a couple public classes that do not inherit from any other classes but are filled with static properties. Is this another way of creating a struct or enum? Is this an older or ...
0
votes
3answers
228 views

How do you balance out code structuring (few big functions vs. many small ones)?

The golden rule of code structuring is always said as splitting into many sub functions is a good thing. Though I noticed it becomes a problem in complex applications when a class of e.g. 10 bigger ...
9
votes
5answers
531 views

How to handle flag in multiple if-else's

I seem to see this often enough in my code and others. There's nothing about it that seems horribly wrong, but it annoys me as it looks like it can be done better. I suppose a case statement, might ...
20
votes
9answers
1k views

What exactly makes code “clean”? [duplicate]

I am an intern at a small software company, doing typical grunt work. Many tasks that the actual developers are doing are above my head however I finally got to see some real "action" and write some ...
2
votes
4answers
365 views

Most human-friendly way to order class method definitions?

In any given class definition, I've seen the method definitions ordered in various ways: alphabetical, chronological based on most common usage, alphabetical grouped by visibility, alphabetical with ...
8
votes
4answers
1k views

In MVC is it considered good practice to have private, non-action, functions in a controller class?

Sometimes action functions in the controller class can become huge and nasty, with many-many lines of code to simply control the flow of data from the Model to the View. At some point these huge ...
15
votes
5answers
923 views

Is this pattern bad? [duplicate]

I notice that when I code I often use a pattern that calls a class method and that method will call a number of private functions in the same class to do the work. The private functions do one thing ...
1
vote
2answers
172 views

Private Repository Management for Potential Employers

I have some projects that I do not wish to be viewed publicly (some of them are school course work), but I want to show them to my potential employers. Ideally, I would be able to generate some ...
8
votes
2answers
872 views

What does Uncle Bob mean by 'noun phrase names'?

I am reading Clean Code by Uncle Bob. Because I am not a native-English speaker, I couldn't understand following statement: Classes and objects should have noun or noun phrase names like ...
2
votes
2answers
370 views

Prevent code from getting mess [duplicate]

I am a student and a freelance programmer. These days I am developing a software in VB6 which has recently crossed 100KB of source code. The main problem, I face is, many times I have to refactor my ...
5
votes
4answers
196 views

How can we track how well we're preventing and avoiding security vulnerabilities?

It's pretty easy to track when we fix security vulnerabilities in existing code. But to make sure the whole team is staying on their toes about writing secure code, I'd like to also track how well we ...
4
votes
3answers
2k views

HTML code in Java class

A conceptual question, I tried to google but couldn't find any definitive answers, so here it goes: Is it a good practice to write Java methods to return HTML strings that will be returned to the ...
1
vote
1answer
145 views

Estimated errors in implementation comparison

I've been working on improving an existing library to be more maintainable after trying to implement a feature I wanted and found the code to be hard to alter. The library is a node.js grunt plugin ...
1
vote
1answer
111 views

Maintenance code needs improvements [duplicate]

I am currently maintaining/enhancing a project a bit old speaking of the 1990's. Atleast 15 developers would have worked over it. Going through the code for understanding is bit difficult. No ...
3
votes
3answers
526 views

What feedback is or is not appropriate for a code review? [duplicate]

I am interested in hearing some guidelines as to what feedback is or is not appropriate for a code review. My team has a very unstructured review process and I am trying to suggest some ways to ...
3
votes
1answer
2k views

What does the “4” in LCOM4 mean?

I know that methods in a class should have high cohesion which roughly translates to having all the methods use all the instance variables directly or indirectly. I know that LCOM4 (Lack of ...
3
votes
2answers
176 views

Strategies for using a code metric evaluation tool

Should code quality metric evaluation tools like Sonar be integrated with IDE for running local analysis or should they be a part of the build process (like integrated with maven) for continuous ...
43
votes
8answers
3k views

What's the right balance between code consistency and code improvement?

Recently I had a discussion with a colleague regarding code style. He was arguing that your usage of APIs and the general patterns you are using should be as similar as possible with the surrounding ...
4
votes
2answers
562 views

How do I handle having so many SQL queries?

I have an MVC3 project that uses SQL Server. I use data from the SQL database all the time and I often find that I'm reusing/duplicating some SQL queries. I thought I'd solve this problem by creating ...
3
votes
5answers
478 views

Obsessed with finding most elegant solution [duplicate]

I find that at times I get obsessed with finding the most elegant solution to a problem or task. I'll spend hours trawling the internet/texts for ideas and discussion on the right way to solve a ...
11
votes
1answer
765 views

Is there a modern replacement for a mutation testing tool like Jester for Java?

“Why just think your tests are good when you can know for sure? Sometimes Jester tells me my tests are airtight, but sometimes the changes it finds come as a bolt out of the blue. Highly ...
17
votes
4answers
2k views

Why is test driven development missing from Joel's Test?

I was reading this blog by Joel Spolsky about 12 steps to better code. The absence of Test Driven Development really surprised me. So I want to throw the question to the Gurus. Is TDD not really worth ...
2
votes
1answer
318 views

Understanding high cohesion principle for methods in object oriented design

I know the idea of strong cohesion applies to methods as much it applies to classes. Just to be clear when I say strong cohesion of a method I mean a method which does only one task and does it well. ...
9
votes
2answers
523 views

How to deal with too much pragmatism in the project?

My team and I took over a medium sized codebase over a year ago when the previous tech lead left the company. Originating from the lack of man power I fear we favored pragmatic solutions over best ...
4
votes
4answers
808 views

What can I do to maintain respect for a poorly written codebase? [duplicate]

In my job I have to maintain a poorly written codebase which is both hard to understand, has tons of comments that are just plain wrong, has a bunch of weird decisionmaking going on in it and a whole ...
6
votes
3answers
177 views

Why would each widget need a reference to its parent in a simple widget system?

I'm working on a simple widget system (single window, fixed size). Each widget gets its parent (i.e. the widget containing it) passed into its constructor - except for the root widget, which I called ...
6
votes
3answers
2k views

code review with git-flow and github

With regular git and github I can do a code review by simply creating a pull request of the feature branch I'm working on to the master branch. How would I do code reviews with git-flow? With workflow ...
8
votes
1answer
322 views

Are there any empirical studies about the effects of commenting source code on software quality, maintainability and developer productivity? [closed]

I am an advocate of commenting on source code and documenting software products. It is my personal experience and observation that working on source code that is rigorously commented has helped me in ...
1
vote
4answers
1k views

Legitimate reasons for circular references in C++

I have project written in C++ that I am working on which has a parent-child relationship where each child has only one parent. I had previously decided after looking at this post that I would make the ...
1
vote
2answers
130 views

@Deprecated as of version x.y in JavaDoc

This question & its answers are useful but not sufficient for my problem. My Question is if I want to add a javadoc as @Deprecated As of version x.y, replaced by {@link SomeClass} in my current ...
71
votes
20answers
12k views

How important is it to reduce the number of lines in code?

I am a Software developer who works on J2SE (core java). Often during our code reviews we are asked to reduce the number of lines in our code. It's not about removing redundant code, it's about ...
3
votes
5answers
2k views

Declaring functions in order to avoid explicit nested loops

My programming professor has told me that it is a good programming practice (at least in C/C++) to declare a function with the inner loop when nesting loops (not for loops, since when, i.e. looping ...
6
votes
3answers
565 views

Is 'using' appropriate in a context where there is nothing to dispose?

In C#, using statement is used to dispose in a deterministic manner the resources without waiting for garbage collector. For example, it may be used to: Dispose SQL commands or connections, Close ...
17
votes
5answers
2k views

Descriptive naming vs. 80 character lines [closed]

I frequently hear these two valuable programming practices: (1) lines of code should be 80 characters or less and (2) use descriptive names for variables, methods, classes, etc. I understand the ...
4
votes
7answers
446 views

Should I spend time prettifying unit tests? [closed]

The company I used to work for before we had automated unit tests to test our work. However the coding standards and architecture was not very important for tests. Of course you had to indent code ...
78
votes
8answers
16k views

Recursion or while loops

I was reading about some development interview practices, specifically about the technical questions and tests asked at interviews and I've stumbled quite a few times over sayings of the genre "Ok you ...
8
votes
6answers
357 views

Is looking at random code snippets useful to quickly determine the quality of a project?

To get an idea of the quality of a project that I've never seen before (usually open source projects that I'm considering whether or not to use), I often start by opening random files and eyeballing ...
7
votes
5answers
1k views

Is code duplication a necessary evil in C?

I'm rather new to C, and I'm wondering if code duplication is a necessary evil when it comes to writing common data structures and C in general? I could try to write a generic implementation for a ...
6
votes
5answers
556 views

Is a coder that 'quality checks' bug fixes and bugs raised by testers a recognised role?

I've recently found myself frequently in the position where I'm checking both bug fixes by other programmers, and bugs raised by the QA team. Any bug fixes frequently end up having 'collateral ...
5
votes
2answers
1k views

what tools should I use for quality assurance and testing for front end javascript? [closed]

I am using jquery and HTML 5 techniques (like File API, HistoryAPI) extensively in a project I am working on. I was wondering what tools I can use for quality assurance my javascript and front ...
7
votes
6answers
487 views

what is the best way to ensure accountability in code checkins?

Note: after writing this I realize that this question is perhaps philosophical, but I'm interested in how the industry handles this scenario regardless. I have recently been working with a code base ...
10
votes
5answers
736 views

Is adhering to one assert per test foolish consistency in this case?

I have a class that I'm testing. The class has a function: apply(List<IRule> rules, List<ITarget> targets); In one test I want to ensure that each target has been passed to one rule, a ...
0
votes
2answers
298 views

Store image as logic file (in db by using binary format) or physical file (in the server) [duplicate]

Possible Duplicate: what are the best tips for storing images in a database? In those study cases of image storage, An image that change only once in a while, if it changes at all (like ...
8
votes
8answers
1k views

How to evaluate code quality when you're not familiar with the language?

As a hypothetical, if I were to interview someone for a new PHP developer position when my experience is in .NET, how can I determine if the code sample they've provided me is efficient and of good ...
9
votes
5answers
664 views

Which is more maintainable — boolean assignment via if/else or boolean expression?

Which would be considered more maintainable? if (a == b) c = true; else c = false; or c = (a == b); I've tried looking in Code Complete, but can't find an answer. I think the first is more ...
5
votes
3answers
534 views

At what point/range is a code file too big?

I'm finding lots of 2-3k line files, and it doesn't really feel like they should be that big. What is a good criteria to objectively call a source code file "too big"?, is there such thing as a ...
1
vote
3answers
325 views

Programming language features that help to catch bugs early [closed]

Do you know any programming language features that help to detect bugs early in the software development process - ideally at compile-time or else as early as possible at run-time? Examples of ...