Skip to main content

All Questions

276 votes
14 answers
125k views

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
Slamice's user avatar
  • 2,657
65 votes
10 answers
36k views

Do you generally send objects or their member variables into functions?

Which is generally accepted practice between these two cases: function insertIntoDatabase(Account account, Otherthing thing) { database.insertMethod(account.getId(), thing.getId(), thing....
AJJ's user avatar
  • 3,028
59 votes
9 answers
49k views

Should the methods of a class call its own getters and setters?

Where I work I see lots of classes that do things like this: public class ClassThatCallsItsOwnGettersAndSetters { private String field; public String getField() { return field; }...
Daniel Kaplan's user avatar
56 votes
3 answers
74k views

Which is a better practice - helper methods as instance or static?

This question is subjective but I was just curious how most programmers approach this. The sample below is in pseudo-C# but this should apply to Java, C++, and other OOP languages as well. Anyway, ...
Ilian's user avatar
  • 663
50 votes
5 answers
62k views

When and why to use Nested Classes?

Using Object Oriented Programming we have the power to create a class inside a class (a nested class), but I have never created a nested class in my 4 years of coding experience. What are nested ...
mayur rathi's user avatar
49 votes
1 answer
8k views

Why do programmers use `Acme` as a package, namespace or directory name [closed]

This may or may not be a silly question, but I really would like to know the answer to something which has been bothering me for a while. I quite often see programming examples/conventions where the ...
Gravy's user avatar
  • 1,067
38 votes
5 answers
9k views

When should I extend a Java Swing class?

My current understanding of Inheritance implementation is that one should only extend a class if an IS-A relation is present. If the parent class can further have more specific child types with ...
Paras's user avatar
  • 491
38 votes
7 answers
2k views

How can I get my progress reviewed as a solo junior developer [closed]

I am currently working for a 2 person company, as the solo primary developer. My boss gets the clients, mocks up some png design templates and hands them over to me. This system has been working fine ...
hoppipolla's user avatar
36 votes
13 answers
5k views

Why should a class be anything other than "abstract" or "final/sealed"?

After 10+ years of java/c# programming, I find myself creating either: abstract classes: contract not meant to be instantiated as-is. final/sealed classes: implementation not meant to serve as base ...
Nicolas Repiquet's user avatar
36 votes
5 answers
68k views

Is it a good practice to create a ClassCollection of another Class?

Lets says I have a Carclass: public class Car { public string Engine { get; set; } public string Seat { get; set; } public string Tires { get; set; } } Lets say we're making a system ...
Luis's user avatar
  • 535
25 votes
2 answers
18k views

Exceptions in DDD

I'm learning DDD and I'm thinking about throwing exceptions in certain situations. I understand that an object can not enter to a bad state so here the exceptions are fine, but in many examples ...
yadiv's user avatar
  • 267
21 votes
5 answers
2k views

How to avoid giant glue methods?

In my current job, I've been tasked with cleaning up old code a few times. Often the code is a labyrinth and the data behind it is even more tangled. I find myself combing out things into nice, neat,...
cmhobbs's user avatar
  • 321
17 votes
6 answers
23k views

Maximum nesting for loops and conditionals? [duplicate]

I've written some code that has some fairly deep nests (one time, I wrote something that was a conditional check inside a forloop inside a conditional check inside a forloop inside a forloop). Is ...
Josh Brown's user avatar
16 votes
3 answers
4k views

When is it okay to use Parallel Arrays?

I've been running into code (new code) that uses what I call 'Parallel Arrays' or Lists. Meaning there are 2 arrays that contain related data and are linked by their position (index) in the array. I ...
GER's user avatar
  • 273
16 votes
3 answers
51k views

Should we add constructors to structs?

We often use c++ structs to define data structure as opposed to class which can be a complete module with member methods. Now deep down, we know they both are the same (loosely speaking). The fact ...
zadane's user avatar
  • 397

15 30 50 per page
1
2 3 4 5 6