Tag Info

Hot answers tagged

6

Interestingly, refactoring is the most efficient way I've found to understand code like this. You don't have to do it cleanly at first. You can do a quick and dirty analysis refactoring pass, then revert and do it more carefully with unit tests. The reason this works is because refactoring done properly is a series of small, almost mechanical changes, ...


4

First, a word of caution (even though it isn't what you're asking) before answering your question: A tremendously important question to ask is why are you wanting to refactor something? The fact that you mention "coworker" begs the question: Is there a business reason for the change? Especially in a corporate environment, there will always be both legacy and ...


3

The requirement for an error code arises from the fact the new function now can have 3 outcomes instead of 2: the time struct is ok, it is not ok, or the passed argument is NULL. The contract you have in mind for your function is "do not pass a NULL value in, otherwise the program will crash or show some undefined behaviour", whilst your coworkers believe ...


2

There is no general recipe, but some rules of thumb (supposing a statically typed language but that shouldn't really matter): 1) Take a look a the method signature. It tells you what goes in and hopefully comes out. From the overall state of this god-class, I suppose this to be a first pain point. I suppose, that more than one parameter is used. 2) Use the ...


2

Why is the tight coupling an issue? If I create a class containing two integer fields or properties, it is tightly coupled to the implementation of integers. Is this a problem? Only if you need to change the integer to a different type, selecting that type at run time. The premise behind the question (tight coupling is a problem) seems flawed. We can always ...


2

You mention a 2000 lines update method. I'd start to read this method top to bottom. When you find a set of statements which belong to each other, i.e. share one responsibility (e.g. create a user), extract these statements into a function. This way, you don't change how the code works but you shorten this huge method gain a better, higher level ...


2

There is no real best way. There are some options: Create an exception hierarchy with a class for each specific exception that all inherit from a common base class (the exception class you are using now for example). Each specific exception class then carries the details of the encountered error and can produce a human-readable message when the what() ...


1

Whats wrong with: // ... do some stuff inside a function if (errorCondition1) { sprintf(gmsg,"Invalid character %c at %d",echar,epos) throw_general_exception(gmsg); } else if (errorCondition2) { sprintf(gmsg,"Wrong length record position %d length %d",position,length) throw_general_exception(gmsg); } // etcetera Unless you want to handle ...


1

Looks like classic polymorphism. Could you create an exception object that you can inherit variations like this from?



Only top voted, non community-wiki answers of a minimum length are eligible