How to use the if-else statement with the function returns?

I always try to avoid nested statements. They lead me into putting code into a long curly braces. It becomes hard to follow the code when the amount of code with in each condition becomes larger. if(condtion) { } else if(condition2) { } else { } So i

Why is this loop bad?

The following loop is not good practice. Is it due to a String being the main condition of the for loop rather than an int variable, meaning the for loop is infinite? Also, is it due to there being no instance to enter 'end' to stop the loop? Scanner

How can I do this JavaScript Timer function properly?

I am trying to make a timer using JavaScript. The problem is, I can't get the timer to stop when it reaches 0. I have tried using return and if statements, but nothing seems to be working. Am I on the right track, or is there a better way to do this?

Build an object with many private collection fields

What is the most efficient and clean way to create an object of a class that has like 10 private fields that are collections (eg. HashMap, LinkedHashMap, ArrayList etc). If I put a constructor with 10 fields in it it would look like nightmare.You can

How can I get data of different types from an anonymous class

I have an object that delegates some work to another object which is implementing an interface. Then, I am creating anonymous classes implementing this interface and I would like to get information from these. Is it okay to use a final array with a s

avoid the rafters in the default template

if i have a template class with a default template type, however i have to write the template angle brackets. is it possible to avoid this? example: template <typename T=int> class tt { public: T get() { return 5; } }; ... tt<> t; // how to av

Automatically check Java files to code for compliance

I'm working in Java development. I have recently come into a situation where I have to comply to coding standards: member and method ordering, naming conventions, modifier sequence. I am thinking about methods to either automate checking for complian

& ldquo; bytes & rdquo; vs & ldquo; in bytes & rdquo;

template<class CharType> struct StringWithLength { size_t length; CharType* str_buf; }; I want to add some comments on the field length. I have two choices: #1. "The field length is the size of str_buf by the byte" (Consider "The work

Is it wrong to use CSS this way?

Lately I'm using a CSS structure that makes HTML much cleaner but I don't know if there's something wrong with this. Instead of using: .top { //properties } .top-wrapper { //properties } .top-logo { //properties } And for HTML: <div class="top&quo

Using the namespace and abuse in a large library

I'm currently pondering what could be a way to make my (reasonably) big library look not too fat, and some contributor suggested using several namespaces to categorize things. Whilst I understand the need to make things clear for users of this lib, I

Should Constancy Spread to Member Pointer Tips?

I have a member function which is declared const and modifies data via a pointer. This seems misleading. Should I remove the const keyword? I would like to know how others handle this situation in their code. Do people just add a comment to clarify w

Why the Android convention does not follow Java

So I've been around android for about two years now, and around 6 with java, something that I liked from the very start that i discover them where the Java Convetion, this guide that help me wrote more understandable code you know the typical CalmelC

Is it bad practice to use #ifdef in the code?

I have to use lot of #ifdef i386 and x86_64 for architecture specific code and some times #ifdef MAC or #ifdef WIN32... so on for platform specific code. We have to keep the common code base and portable. But we have to follow the guideline that use

Questions about simple operations of C ++?

I just have a few general questions about keeping code clean and readable. 1) Should functions have separate files from main (prototypes and initialization) ? (the functions are long) 2) If functions do have separate files, in Main do I include the f

Prerequisite for TreeMap

Like for a object to be inserted into a HashMap the object should implement the equals() and the hashcode() method(not necessarily). Are there any special conditions for an object to be inserted in a TreeMap ?Unless a Comparator which mutually compar

Should class members be sorted?

On a new project with a new team, should we enforce to sort the members of the classes automatically in a specific order (e.g. by modifier and alphabet) prior to check-in? The alternative is to let each developer group the members as he thinks. And s

CERN ROOT Chart Style Issues

Is there a way to center the titles of a graph along the length of the axis they describe? I am using C Scripting with the root command line to create a graph from a TNtuple and I have formatted everything else properly by using the TStyle and TGaxis

C ++ #include style differences

So the other day, I was looking through some old C++ books and noticed a way of creating a C++ class I had never seen before. Everything I have seen up to that point had always used the #include "header.h" and compiled the implementation files s

What is the best way to structure this kind of code?

I have a function that need to analyze packet after packet and decide what to do. For each packet the code must: Read a packet, on timeout return an error code. Check for corruption, if positive log it and and go to 1. Check for an abort packet, if p

Private Class Functions vs. Functions in an Unnamed Namespace

I've found myself that I tend not to have private class functions. If possible, all candidates to private class function rather I put in to unnamed namespace and pass all necessary information as function parameters. I don't have a sound explanation

Android dynamically change style

I've describef properties of my objects (nevermind what the object is) in styles.xml. I would like to change these properties dynamically in styles.xml. Does anybody know how can I do that?I am seeing contradicting answers to this question. This says

A better way to clean up this bool method

I'm reading Fowler Clean Code book and I think that my code is a little messy, I want some suggestions: I have a simple business requirement that is return the date of new execution of my Thread. I've two class fields: _hour and _day. If actual day i

Best practices for formatting code on large projects

I maintain the build for a large Java EE/Maven/Hudson/Perforce project with about 20 developers spread across the world. The solution in-place for code formatting is to format the codebase using Jalopy when the developer runs the build, thereby ensur