Skip to main content
Share Your Experience: Take the 2024 Developer Survey
22 votes

Small functions vs. keeping dependent functionality in same function

The problem you're dealing with is called temporal coupling You're right to be concerned about how understandable this code is: private func setupNodes() { createNodes(); connectNodes(); } ...
candied_orange's user avatar
10 votes

How can I effectively use one file per class in C++?

In C++ you have full flexibility how you want to organize your files. But you have to get accustomed to this freedom to make the good choices: A first practice is to have include guards in headers, ...
Christophe's user avatar
10 votes

Small functions vs. keeping dependent functionality in same function

Separate functions, for two reasons: 1. Private functions are private for exactly this situation. Your init function is public, and it's interface, behavior, and return value is what you need to worry ...
Jen's user avatar
  • 693
9 votes
Accepted

Should parameters of a method be in the same namespace as the class?

Should I move ClientQueryBuilder class to Service namespace? No. You will end up with one giant namespace. But I think the flaw in the logic goes deeper. You say that namespaces are a way of ...
Ewan's user avatar
  • 76.4k
8 votes

How can I effectively use one file per class in C++?

Say I have some kind of game where there is a class representing the game world and a class to represent the units. If the game world class has a method to get the unit at a location, that's all well ...
Doc Brown's user avatar
  • 209k
8 votes

How to best to organize class and interface files?

Since an interface is abstractly similar to a base class, use the same logic you would use for a base class. Classes implementing an interface are closely related to the interface. I doubt you would ...
Frank Hileman's user avatar
7 votes
Accepted

How can I cleanly handle deeply nested namespaces in C++?

this creates an entirely new issue where there are two separate hierarchies — one for namespaces, and another for the file system. That's not an issue at all though, it's perfectly normal. ...
Useless's user avatar
  • 12.6k
7 votes
Accepted

C++ Is it okay to use nested classes as a way to namespace derived classes?

This is a very bad idea, because it breaks the Open/Closed Principle: Classes should be open for extension, but closed for modification. This means that it should be easy to "extend" your ...
Christophe's user avatar
6 votes
Accepted

Writing quality code

Software patterns are mostly about vocabulary. They give software developers a language by which they can communicate high-level design concepts. But patterns are not a design methodology; if you'...
Robert Harvey's user avatar
6 votes

How can I effectively use one file per class in C++?

Your options for resolving circular dependencies are: forward declaration Yes, this really is commonly used and isn't considered a hack. Note that only the public interfaces of your two ...
Useless's user avatar
  • 12.6k
5 votes

Which is a good way of separating and organizing layers and subdomains code, one that highlights and facilitates a clean architecture?

If your goal is to keep related things together, here is an article of mine about packaging. In short: Packages should never depend on sub-packages. Sub-packages should never introduce new concepts, ...
Robert Bräutigam's user avatar
5 votes
Accepted

"Hard coded" vs. configuration files for values in libraries? (code organization question)

There is no best practice or general rule. It is situational and depends on how often this data needs to change, how difficult it is to change, and team preferences. Keeping this information in config ...
Greg Burghardt's user avatar
4 votes

Small functions vs. keeping dependent functionality in same function

You may also find (depending on how complex each of these tasks are) that this is a good seam for splitting out another class. (Not sure if Swift works this way but pseudo-code:) class YourClass { ...
willoller's user avatar
  • 141
4 votes
Accepted

How I can organise a project in more programming languages in Git repos?

This is very personal and depends on your style of maintaining your code and how you work with code repositories. Then again there are recommended "best practices", that are there for a pretty good ...
Todor Todorov's user avatar
4 votes
Accepted

Is it a bad practice to use external files for storing SQL templates?

This might depend on the database system in question, but usually such parameterized query logic would be in a stored procedure or view on the database. If multiple clients are performing similar ...
JacquesB's user avatar
  • 59.7k
4 votes
Accepted

Folder structure for a C project

Both is possible, so if you find any reason to use one approach instead of the other, go ahead. I would use the second approach (top level directories are core, module1, module2, etc.) if the ...
Michael's user avatar
  • 289
4 votes
Accepted

Managing error code and error message mapping

Should error codes be named per-struct The granularity of error codes should fit to the existing requirements of the system. Make them as granular as needed to display meaningful error messages, or ...
Doc Brown's user avatar
  • 209k
4 votes

How can I cleanly handle deeply nested namespaces in C++?

One way to handle it: Don't do it. In your example, you could have a namespace game_name::server and leave it at that. Don't reuse names for top level objects obviously. But they are confusing ...
gnasher729's user avatar
  • 45.7k
4 votes
Accepted

Where to put interface files for mocking aka what are best practices for organizing interfaces in a C#/.NET Core project with NSubstitute, Moq etc.?

Decisions like this are usually best guided by the Principle of Least Astonishment: What pattern will other developers recognize and understand quickly? First, C# projects have a very common ...
Stephen Jennings's user avatar
3 votes

How to best to organize class and interface files?

As always with any design question, the first thing to do is determine who are your users. How are they going to use your organization? Are they coders who will be using your classes? Then separating ...
shawnhcorey's user avatar
3 votes
Accepted

Relative merits of monolithic repository over multiple smaller ones

There are two questions in your post, and they should IMHO be answered separately. Assumed one is going to create a somewhat "large" software system using C++, should one create different, ...
Doc Brown's user avatar
  • 209k
3 votes

Writing quality code

Each discipline, would it be accounting, archeology or brain surgery, has numerous books and numerous things to remember. Yes, you have to read a lot of books in order to acquire the minimum knowledge ...
Arseni Mourzenko's user avatar
3 votes

Using git on a project with different areas

The usage of the term "area" is a little unclear to me, but I'm understanding that you have multiple applications and webpages that share the same back-end code. If they all depend on the same back-...
Kyle A's user avatar
  • 164
3 votes

Mixing JavaScript and server-side scripting

The question here is "why" is this a bad practice. The number one reason is the empirical observation over many years that it leads to software that is difficult to understand, maintain and change. ...
John Scattergood's user avatar
3 votes

Writing quality code

Hopefully learning is an iterative process. There are things that are not useful at the moment, but you'll remember some. Problems come up that you'll research. You will misapply them, but that's part ...
JeffO's user avatar
  • 36.8k
3 votes

How should I organize my source tree?

My recommendation is to download a variety of frameworks or engines and see how huge development teams handled their folders layout. There are so many ways to organize files that it's better to ...
Heroselohim's user avatar
3 votes

How can I effectively use one file per class in C++?

In C++11 (and other dialects of C++, and in C) you can have several translation units for a given program. So your program could be made of foo.cc, bar.cc, gee.cc C++ source files compiled separately ...
Basile Starynkevitch's user avatar
3 votes

When it isn't right to add types to a well known namespace?

If you have enough code that you want to re-use, create a company namespace. You can organize diffrent code into different libraries as well so that you don't need to include all your company's shared ...
fstam's user avatar
  • 212
3 votes

Separating Plotting and Computation Logic in Scientific Computing MVC App

I would go for solution #5 - standard Dependency Injection: Either at construction time (in case the computation is implemented in a class), or when calling the function, the computation logic takes ...
Doc Brown's user avatar
  • 209k
3 votes

In C#, is it reasonable to use a #region when I need several members to implement a common interface?

I know that lots of people hate #regions in C# Whenever #region gets mentioned, people immediately jump on the bad practice bandwagon. And it's true that #region can be abused to hide monolithic code....
Flater's user avatar
  • 51.7k

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