Skip to main content
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

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
  • 79.9k
9 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.7k
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
  • 80.6k
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
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

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
  • 47.5k
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
  • 214k
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
  • 299
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

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
  • 214k
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

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
  • 214k
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

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

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
  • 56.3k
3 votes

How to organize top level scripts in Python projects, especially for interactively developing

I am using a similar structure in some of my projects and I prefer to keep these top level scripts in a subfolder so that the project root doesn't get cluttered. This works fairly easy without ...
Soeren D.'s user avatar
  • 145
3 votes

What are some methods of storing personal notes alongside code?

I'll just comment on your comments. foo = get_foo(bar, boom); // Actually returns a proto-foo, not a foo Refactor, rename. foo += 1 // Alice says this is to avoid the lochness bug Perfectly good ...
Theraot's user avatar
  • 9,201
3 votes
Accepted

What are some best practices for team structure around Mobile and Desktop apps?

The decision to use a single repository for both the Mobile and Web versions or to use multiple repositories should depend heavily on the release cadence of the two versions of the product. If it is ...
Bart van Ingen Schenau's user avatar
3 votes
Accepted

How might encapsulated source be broken into into multiple files?

The result of your suggested code organization does logically not differ from a single header file mystruct.h with the struct itself and all function declarations, plus a single code file mystruct....
Doc Brown's user avatar
  • 214k
2 votes

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

It's going to become hard to communicate across namespaces if you do this everywhere. If you're confident it won't cause ambiguous name conflicts you can do this: namespace Project.Services { ...
candied_orange's user avatar

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