If two classes both need to know about each other to do their job, i.e. class A must maintain a reference to class B and class B must maintain a reference to class A, is this generally a sign that inheritance would be a better idea than composition, provided you aren't violating the Liskov Substitution principle? My thinking is that thi...
I'm working on a highly-specialized search engine for my database. When the user submits a search request, the engine splits the search terms into an array and loops through. Inside the loop, each search term is examined against several possible scenarios to determine what it could mean. When a search term matches a scenario, a WHERE con...
In the solution I have worked out to this question => General type conversion without risking Exceptions (See the edit at the bottom of the question), I need to cache a method for converting between two types.
So, given Type1 and Type2 I need to retrieve a method.
In the answer to this question => What is the best C# collection with tw...
Do not code like this. Please, read the hints by the accepted answer. I tried to remove the junk but I coundn't.
Code
import sys
a = []
i=0
for line in sys.stdin:
try:
n = float(line)
a.append(n)
i+=1
except ValueError:
print 'Number please!';
...
I don't know why I started thinking about this, but now I can't seem to stop.
In C# - and probably a lot of other languages, I remember that Delphi used to let you do this too - it's legal to write this syntax:
class WeirdClass
{
private void Hello(string name)
{
Console.WriteLine("Hello, {0}!", name);
}
public...
I'm writing a synchronous method that calls an asynchronous method on another server. The server's method calls a callback when it's done, and in case of error one of the callback's arguments contains an exception. I'd like to throw an exception from my method, with the server's exception as its InnerException. However, in order to ca...
I realise this could be "very subjective", but I have asked different people from many work places who are used to different languages and ideologies what a code smell is, and noone can agree what a code smell is. It would be good to get a definition that most people can agree on.
For example, what one developer calls a code smell, anot...
In my mind I think that an anti-pattern is the cause, and a code-smell is just one of man possible symptons. Is this correct?
For example:
God class antipattern -> large class code smell
Not Invented Here Antipattern -> code that should not even be there
Analysis Paralysis anti-pattern -> no code smell results, but leads to bankcruptc...
So, we all strive to reduce duplication (DRY) and other smells, and keep our code as nice and clean as possible. For Ruby code, there are a lot of instruments to detect smells, for example the quite nice Caliber service.
However, it seems that I have a different definition of code duplication than the tools. I think this might be connec...
I don't know much F# and i never used a functional programming language in the past (i was interested in oCaml). I am about to rewrite my entire website and i think i want to do it in F#. I would like to know if there is anything i should know about before starting or development.
NOTE: The site is fairly large and MUST be maintained fo...
I'm writing code like:
class Game
{
int getMouseX()
{
return inputManager.getMouseX() ;
}
} ;
I remember seeing code like this and hating it. One function passes off to another? What is this "pattern" (or, possibly, anti-pattern) called? I don't like it!
On the other hand, it saves exposing the InputManager to ...
I haven't counted but its a lot. How do i refacter a 100 function class?
This is for a website, i use to have a PageView, Backend, DB layer where PageView calls the backend, every backend public function checks if the user meets the required authority then calls the DB or any other code. It wasnt as nice as it may sound, each of them ha...
I'm in a project where it's pretty much my first time doing all the architecture myself, and I'm running into a frustrating situation. My architecture for forms seems to be correct from a heuristic perspective, but I don't think its implementation is correct.
My architecture is thus:
Base Class: OrderForm
Child Classes: PurchaseOrder...
Apologies if this is a bit of a vague question with no proper answer. Please move/close it if it's not in the right place.
I've written a few relatively trivial GUIs in WxWidgets and Qt, and I'm persistently unsure how to architecturally handle the following situations:
You catch a mouse event to do something to a graphical object in...
I'm writing a parser/handler for a network protocol; the protocol is predefined and I am writing an adapter, in python.
In the process of decoding the incoming messages, I've been considering using the idiom I've seen suggested elsewhere for "switch" in python: use a hash table whose keys are the field you want to match on (a string in ...
I'm working on a couple of mac products, and in order to do what I need to do, I'm using some calls to undocumented methods on Mac Classes. Like
IKImageView's
doRotate:(id)
and
PDFDocument's
(NSPrintOperation *)getPrintOperationForPrintInfo:(NSPrintInfo *)printInfo autoRotate:(BOOL)doRotate;
How common is it for Objective C pr...
The idea I'm playing with right now is having a multi-leveled "tier" system of analytical objects which perform a certain computation on a common object and then create a new set of analytical objects depending on their outcome. The newly created analytical objects will then get their own turn to run and optionally create more analytical...
Example:
class MyClass
{
Composition m_Composition;
void MyClass()
{
m_Composition = new Composition( this );
}
}
I am interested in using depenency-injection here. So I will have to refactor the constructor to something like:
void MyClass( Composition composition )
{
m_Composition = composition;
}
Howe...
I have a class that has a method. That class has a child class that overrides that method. The child's method has to call the parent's method. In all OO that I've seen or written calls to the parent's version of the same method were on the first line of the method. On a project that I am working on circumstances call for placing that met...
Does anyone know of an updated list of refactoring support for different IDEs?
How many of Fowler's refactorings have tool support in popular IDEs?
And does any IDE use code smells to any greater extent?
I guess one would have to use addons for some IDEs, so even if I did find an updated list of refactoring support for say Eclipse, tha...