Skip to main content
100 votes
Accepted

Is using parameter names that differ from type names only by casing considered a bad practice in C#?

Don't overthink this, Range range is fine. I use such kind of naming for more than 15 years in C#, and probably much longer in C++, and have never experienced any real drawbacks from it, quite the ...
Doc Brown's user avatar
  • 210k
59 votes
Accepted

Is it considered bad software engineering practice to always use "public" methods?

The methods, properties and constructors (i.e. members of a class) that you define using a public accessor determine the surface area that the users of your class will be allowed to interact with. ...
Robert Harvey's user avatar
50 votes

Working through the single responsibility principle (SRP) in Python when calls are expensive

Many potential performance concerns are not really a problem in practice. The issue you raise may be one of them. In the vernacular, we call worrying about those problems without proof that they are ...
Robert Harvey's user avatar
49 votes

Which object should have the method?

A user is someone who is registered and able to use the system. A chat room is a place people can chat. What happens when a user joins a chat room? What is that thing that represents a user who has ...
Greg Burghardt's user avatar
47 votes

Is it a bad idea have make a class method that is passed class variables?

Calling a class method with some class variables is not necessarily bad. But doing so from outside the class is a very bad idea and suggests a fundamental flaw in your OO design, namely the absence ...
Christophe's user avatar
  • 78.6k
44 votes
Accepted

Why is unit testing private methods considered as bad practice?

A couple of reasons: Typically when you're tempted to test a class's private method, it's a design smell (iceberg class, not enough reusable public components, etc). There's almost always some "...
Matt Messersmith's user avatar
42 votes
Accepted

When should a function be given an argument vs getting the data itself?

When should a function be given an argument vs getting the data itself? When it has a job besides getting the data. I can see why you'd be confused about this. None of your functions are named after ...
candied_orange's user avatar
39 votes

Is it considered bad software engineering practice to always use "public" methods?

Short answer: Declaring a method or field "public" translates to a promise: Dear colleages, I invite you to use this method or field wherever you find it appropriate. I have documented ...
Ralf Kleberhoff's user avatar
39 votes
Accepted

Pass object twice to same method or consolidate with combined interface?

No, this is perfectly fine. It merely means that the API is over-engineered with regards to your current application. But that doesn't prove that there will never a use case in which the data source ...
Kilian Foth's user avatar
38 votes
Accepted

What is better IllegalStateException or silent method execution?

There is no rule. It's entirely up to how you want to make your API "feel." Personally, in a music player, I think a transition from the state Stopped to Stopped by means of the method Stop() is a ...
MetaFight's user avatar
  • 11.6k
33 votes
Accepted

Why is cyclomatic complexity that important for a single method?

The core thing here: "brain capacity". You see, one of the main functions of code is ... to be read. And code can be easy to read and understand; or hard. And having a high CC simply implies a lot ...
GhostCat's user avatar
  • 567
33 votes
Accepted

Is it a bad idea have make a class method that is passed class variables?

There are may things with the class that I would do differently, but to answer the direct question, my answer would be yes, it is a bad idea My main reason for this is that you have no control over ...
Peter M's user avatar
  • 2,039
27 votes

Why is unit testing private methods considered as bad practice?

Given that one of the main purposes of unit tests is that you can refactor the internals of your program and then be able to verify that you haven't broken its functionality, it's counterproductive if ...
Pete's user avatar
  • 3,221
26 votes

Which object should have the method?

Rule of thumb: Your methods are probably in the right place if they don't need to pull data out of other objects. This is often called "envy", as in "feature envy". If your method ...
Robert Bräutigam's user avatar
25 votes
Accepted

What does it mean for a method or a function to do one thing?

If I tell you to "take out the trash" I've asked you to do one thing. It's one cohesive idea. Does that mean it can't be decomposed into more things? No. Everything can be decomposed into more ...
candied_orange's user avatar
23 votes
Accepted

Why does Java use :: for method references instead of .?

This is to avoid ambiguity in case if class has (static) member with the same name as method (Java allows that). It is easy to see from code snippet in Java tutorial about method references: ...
gnat's user avatar
  • 21.1k
23 votes
Accepted

Is there a clean way to model methods that only make sense depending on the current state of the object?

What you've done here has a name. This is an internal Domain Specific Language (iDSL). It can be used like this: void execute(PlannedMission plannedMission) { plannedMission .start() ...
candied_orange's user avatar
22 votes
Accepted

Which object should have the method?

In your case, you have users vs. Chatrooms. If you have methods that concern both, you could put them into either class, not much difference. However: You will have not only users vs. Chatrooms, you ...
gnasher729's user avatar
20 votes
Accepted

Is it a good practice to end a function's name with a preposition?

If it adds meaningful clarification or fits the "ethos" ... Yes. .NET's OrderBy() and ElementAt() might be good examples. Personally, I like code that reads pretty much like English. It takes a ton ...
svidgen's user avatar
  • 15.1k
20 votes

How do you honour the principle to only do "one thing" in a method in reactive streams?

What you're asking how to do is called decomposing. "Do one thing" never meant your function couldn't be decomposed into more things. Every function can be decomposed into more things. No, &...
candied_orange's user avatar
19 votes

What is the purpose of enclosing all return values and arguments of a method in separate classes?

Whether it's a widespread convention (I hope it's not), I don't know, but I agree with @Telastyn. Those are the same reason why many people keep naming classes with DTO. I will ignore the DTO thing on ...
Laiv's user avatar
  • 14.7k
18 votes

What is better IllegalStateException or silent method execution?

There are two distinct kinds of actions one may wish to perform: Simultaneously test that something is in one state, and change it to another. Set something to a particular state, without regard for ...
supercat's user avatar
  • 8,583
17 votes
Accepted

Can method names give any implementation details and break encapsulation?

The actual inventory is still hidden from outside classes (i.e., the List<GameItem> inventory is private), so encapsulation is not broken. Whether it makes more sense to name the method has(...
mmathis's user avatar
  • 5,488
17 votes
Accepted

Working through the single responsibility principle (SRP) in Python when calls are expensive

is Python simply poor at handling code breakdown altogether? Unfortunately yes, Python is slow and there are many anecdotes about people drastically increasing performance by inlining functions and ...
Ewan's user avatar
  • 77.4k
17 votes

How do you honour the principle to only do "one thing" in a method in reactive streams?

“Do only one thing” may include “do everything to display the user’s information on the screen and allow editing it”. Taking SRP too literal is a recipe for disaster.
gnasher729's user avatar
16 votes

Is using parameter names that differ from type names only by casing considered a bad practice in C#?

I do this all the time, it is giving me great piece of mind. If it is an argument passed to a constructor that needs to be assigned to a member, my member would be named range as well and the ...
Martin Maat's user avatar
  • 18.5k
16 votes

Why is unit testing private methods considered as bad practice?

Writing unit tests for private methods ties your unit tests to implementation details. Unit tests should test the behavior of a class at the class's outer surface (it's public API). Unit tests ...
Robert Harvey's user avatar
16 votes

What is the purpose of enclosing all return values and arguments of a method in separate classes?

What is the purpose of doing so? Potentially, it allows you to violate the open closed principle and add things to these DTOs without impacting the rest of the code as much. It also potentially ...
Telastyn's user avatar
  • 109k
15 votes

How to name a method which may or may not perform an action depending on a condition?

You're trapped in a structural way of thinking. A name should abstract away implementation details. It shouldn't become a short hand for them. IfBirthdayBuyCake(); is a terrible name. It exposes ...
candied_orange's user avatar
14 votes
Accepted

What's the general option on passing a boolean parameter in a method or constructor in OOP languages?

Enh. It's generally distasteful to pass in a boolean that governs behavior - "If X do this other stuff". The function then tends to not have a single focused responsibility making it harder to test, ...
Telastyn's user avatar
  • 109k

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