code-design

Keeping everything loosely coupled and extendable: Too many layers, too small ROI?

Hello, I (now more than ever) see developers write huge amounts of layers such as: implementation PresentationLayer -> interface IMyDTO -> implementation MyDTO -> interface IMyService -> implementation MyService -> interface IMyDomainRepository -> i...

Better code: Extend LINQ class, or create separate helper class?

Hello, I'm trying to figure out what the better/cleaner/more maintainable way is, for the following problem. My "Customer" class is generated via LINQ from the database. The customer has a special activation link which is a URL that needs to be generated from data from both a Customer instance and some static configuration data. Solutio...

Should you avoid static classes?

Hello, are static classes considered bad practice? I read an article about this a couple days ago (can't find it, sorry) which basically said that having static classes (especially those 'helper' classes) are typically a sign of bad code. Is this correct, and if so, for what reasons? ...

Class Vs Pure Array Representation

We need to represent huge numbers in our application. We're doing this using integer arrays. The final production should be maxed for performance. We were thinking about encapsulating our array in a class so we could add properties to be related to the array such as isNegative, numberBase and alike. We're afraid that using classes, howe...

Code infrastructure for accessing different properties of multiple elements (vector graphics editor)

Hi everybody, I am currently working on a small vector graphics editor (sort of) and facing a code design question, wondering how it would be solved in an elegant and straightforward manner. If anyone has a good idea how to solve this, or knows a good link or a piece of open source code dealing with a similar setup, I would be really ...

Is it expensive to create objects in .Net?

I have just refactored a colleague's code that, roughly, looked like this... public class Utility public void AddHistoryEntry(int userID, HistoryType Historytype, int companyID) { // Do something... } public void AddHistoryEntry(int userID, HistoryType historyType, int companyID, string notes) { // Do something... } ...

When is a class too long?

When is a function too long? is a subset of this question, I think. What are a few good metrics for determining that a class is too long? I'm rerevising a set of code acceptance guidelines for a project with external contractors, and realized I haven't covered this in the past, but should cover this in the future. ...

How do i refacter a 100 function class

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...

Refactor/rewrite code or continue?

I just completed a complex piece of code. It works to spec, it meets performance requirements etc etc but I feel a bit anxious about it and am considering rewriting and/or refactoring it. Should I do this (spending time that could otherwise be spent on features that users will actually notice)? The reasons I feel anxious about the code ...

I don't like Python functions that take two or more iterables. Is it a good idea?

This question came from looking at this question on Stackoverflow. def fringe8((px, py), (x1, y1, x2, y2)): Personally, it's been one of my pet peeves to see a function that takes two arguments with fixed-number iterables (like a tuple) or two or more dictionaries (Like in the Shotgun API). It's just hard to use, because of all the ve...

.NET: bool vs enum as a method parameter

Each time I'm writing a method that takes a boolean parameter representing an option, I find myself thinking: "should I replace this by an enum which would make reading the method calls much easier?". Consider the following with an object that takes a parameter telling whether the implementation should use its thread-safe version or not...

Which design pattern is most appropriate?

Hello, I want to create a class that can use one of four algorithms (and the algorithm to use is only known at run-time). I was thinking that the Strategy design pattern sounds appropriate, but my problem is that each algorithm requires slightly different parameters. Would it be a bad design to use strategy, but pass in the relevant par...

Unsure how to come up with a good design

Hello there, I am having trouble coming up with a good design for a group of classes and was hoping that someone could give me some guidance on best practices. I have kept the classes and member functions generic to make the problem simpler. Essentially, I have three classes (lets call them A, B, and C) as follows: class A { public: ...

C++: How to design a utility class?

Hi, The title says it all. But I don't know if I should go for static methods, just a header, a class, or something else? What would be best practice? But, I don't want to have an instance of a utility class. I want to add functions like: Uint32 MapRGB (int r, int g, int b); const char* CopyString(const char* char); // etc. You know:...

Design of LINQ code

What are your suggestions for designing linq code in project? Especially, I`m interesting in code design of big and complex linq queries? For example, you know, that you need to write a lot of huge linq stuff, maybe some of your code will have duplicate parts, maybe not, and you need: Make the code easily supportive - means, if you ne...

One function argument or instance variable [Clean Code book]

Hi everyone, I'm reading Uncle Bob's "Clean Code" book and constantly finding contradictory statements. Here is one of them. Book claims that we should use as few function arguments as possible, so it's more preferably to use function without any arguments to function with one argument and after this claiming there is suggestion how to r...

Does DRY necessarily mean a better performing application?

I've been repeatedly told not repeat myself when programming. I've come across a scenario where I'm wondering whether to write two functions, each for a particular purpose, or a single function that handles both purposes. I'm not sure what is the "best practices" approach: All functions in question deal with allowing a person to change ...