All Questions
172
questions
2
votes
1answer
151 views
GetOrCreate method for a database operation
I have read this thread: Is it bad coding practice to create something in a get if it does not exist?
But, my question involve a method which gets a record from a database or creates it if it doesn't ...
1
vote
2answers
311 views
Are experienced developers and software architects able to describe an entire software application in terms of design patterns?
Do experienced developers and software architects see entire application in terms of design patterns?
In other words experienced developers and software architects able to describe an entire software ...
-2
votes
1answer
150 views
Why aren't constructors atomic? [closed]
If thrown exceptions in constructors can lead to memory leaks or partially-constructed objects, then why we don't make them atomic? so neither an object nor it's local variables will get created/...
1
vote
1answer
2k views
Any OOP design pattern that is somewhat representative of all of the SOLID OOP design principles at play?
I'm trying to teach an object oriented design principles course (on SOLID) at a training institute. I also want to teach the students a few OOP design patterns such as factory, singleton and one other....
60
votes
4answers
62k views
Why do C# developers newline opening brackets?
I've spent most of the last several years working mainly with C# and SQL. Every programmer I've worked with over that time was in the habit of placing the opening brace of a function or control flow ...
0
votes
3answers
379 views
What arguments are there to use a coding style for each distinct language? [duplicate]
I recently had a discussion about our coding style for C# projects. Two things in particular were very hard to agree upon.
Method Naming
C# has the de-facto standard of naming (at least public, not ...
4
votes
7answers
499 views
When to use a class with a constructor vs using a method returning an object
I've been working in a rather large codebase filled to the brim with small classes such as
class Person
{
public string name;
public int age;
public int height;
}
As a mainly front-end ...
-4
votes
1answer
59 views
Calculate math function depend on N value [closed]
I have method with the following prototype :
R[] = method(k,n)
which :
n = ordinal value 0 <n <10^9
k = math function depend on n value : i.e n^6
R = array of computed values
For example :
n = ...
86
votes
11answers
12k views
Did the developers of Java consciously abandon RAII?
As a long-time C# programmer, I have recently come to learn more about the advantages of Resource Acquisition Is Initialization (RAII). In particular, I have discovered that the C# idiom:
using (var ...
0
votes
2answers
111 views
Where should I put the initialization validation of a Value Object?
Hi I am making a Value Object.
public class Age
{
public Age(int age)
{
Value = age
}
public int Value { get; private set; }
}
I want to check ...
0
votes
3answers
131 views
Solutions for polyadic functions/methods
In the book Clean Code, Robert C. Martin says that we should avoid polyadic functions (functions that contain four or more arguments).
One of the solutions presented by him is the use of objects as ...
62
votes
6answers
27k views
Why was C# made with “new” and “virtual+override” keywords unlike Java?
In Java there are no virtual, new, override keywords for method definition. So the working of a method is easy to understand. Cause if DerivedClass extends BaseClass and has a method with same name ...
1
vote
1answer
139 views
How significant is the speed of native code for back end tasks?
Going native is extremely good for front end development. Whether its using android vs ionics, c++ vs dotnet/java, the benefits to GUI are significant.
I was wondering if the same had significant ...
82
votes
12answers
25k views
What is the utility and advantage of getters & setters especially when they are merely used to read and assign values to properties of an object? [closed]
I’m still really new to learning to program. Just learning the syntax for a few programming languages at the moment.
The courses I viewed for C# and Java touched only very briefly on getters & ...
-4
votes
4answers
344 views
C# Why should i limit myself to List or Stack ? ( instead of having both)
List is implemented in C# exactly as Stack, see:
https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.stack-1.push?view=netframework-4.8#remarks
https://docs.microsoft.com/en-us/...
32
votes
5answers
9k views
Why can't Java/C# implement RAII?
Question:
Why can't Java/C# implement RAII?
Clarification:
I am aware the garbage collector is not deterministic. So with the current language features it is not possible for an object's Dispose() ...
1
vote
1answer
138 views
How do Java's proposed Inline Classes compared to Value Types in C#
There is talk once again about Inline Classes being added to Java.
As someone who understands C#, what is the best ways to think about them?
As a C# program what am I likely to misunderstand about ...
-5
votes
1answer
623 views
Use Case Diagram for Vending machine
I want to create a use case diagram for a vending machine which has the following states:
Accepts coins of 1,5,10,25 Cents
Allow user to select products Coke(25), Pepsi(35), Soda(45)
Allow user to ...
69
votes
7answers
18k views
How do you encode Algebraic Data Types in a C#- or Java-like language?
There are some problems which are easily solved by Algebraic Data Types, for example a List type can be very succinctly expressed as:
data ConsList a = Empty | ConsCell a (ConsList a)
consmap f ...
-4
votes
2answers
203 views
What is the benefit of Java collection streams over C# or Scala collections?
Java collection streams were introduced in Java 8, which came out in March of 2014.
By that time, we already had well-established mechanisms for manipulating collections in several other languages, ...
41
votes
3answers
58k views
What is message passing in OO?
I've been studying OO programming, primarily in C++, C# and Java. I thought I had a good grasp on it with my understanding of encapsulation, inheritance and polymorphism.
One frequently referenced ...
-3
votes
1answer
342 views
C# is fantastic, if only List 'd respect Remove&Return [closed]
In the domain of system-modeling (e, systemVerilog, matlab, phyton), lists are obsoleting arrays, stacks and queues(*) altogether. Other domains that use python, perl and ruby have that same mindset, ...
2
votes
4answers
1k views
Why doesn't C++ support covariance in STL containers like C# or Java?
The Covariance and Contravariance feature is well supported in C# and Java collections. However C++ doesn't support them in their STL containers. Why is it so?
For example the below code will ...
42
votes
3answers
15k views
Why is the logical NOT operator in C-style languages “!” and not “~~”?
For binary operators we have both bitwise and logical operators:
& bitwise AND
| bitwise OR
&& logical AND
|| logical OR
NOT (a unary operator) behaves differently though. There is ~ ...
4
votes
2answers
1k views
Is there anything wrong with writing getter/setter methods in C#? [duplicate]
I am a Java dev for almost all of my programming (at least in the workplace) but I do some Unity for fun on the side. I have used C# properties many times and they are convenient to still provide ...
12
votes
8answers
4k views
Object-Oriented Class Design
I was wondering about good object oriented class design. In particular, I have a hard time deciding between these options:
static vs instance method
method with no parameters or return value vs ...
25
votes
5answers
67k views
Best way to load application settings
A simple way to keep the settings of a Java application is represented by a text file with ".properties" extension containing the identifier of each setting associated with a specific value (this ...
3
votes
5answers
581 views
Design pattern for objects in invalid states
General design pattern for object error state
Consider a simple class Wallet that models a wallet. A Wallet contains a certain amount of Wallet.Cash and it is possible to take money out / put money ...
10
votes
1answer
4k views
Is the C# async/Task construct equivalent to Java's Executor/Future?
I'm a long time Java developer, but with so little traffic on SE, I don't limit my viewing to any single tags. I've noticed that C# questions with async/await come up a lot, and as far as I've read it'...
0
votes
1answer
56 views
Objectreference vs Equality [closed]
While coding I stumbled upon something like this (extremely simplified example):
public bool Func()
{
Object[] array = new Object[] {false, false};
return array[0] != array[1];
}
I was ...
92
votes
16answers
20k views
Do the young minds need to learn the pointer concepts?
Why did the C master Dennis Ritchie introduce pointers in C? And why did the other programming languages like VB.NET or Java or C# eliminate them? I have found some points in Google, and I want to ...
0
votes
0answers
234 views
Frontend JSON payload that defines which classes to use in the backend
Payload:
{
"selection": {
"ids": [1,2,3,4,5]
},
"image": {
"backgroundColor": "#FFFFFF",
"headlineColor": "#000000",
"format": "PNG"
},
"processors"...
1
vote
2answers
1k views
WebSockets vs Ajax call for scheduled event?
Intro
I have been weighing the pros and cons of using WebSockets vs. an Ajax call for an event which will happen every x number of seconds (in this case 5). I'll start by explaining the scenario.
...
1
vote
0answers
77 views
Hierarchy of models while designing a client for a RESTful service
I am trying to write a client for a restful service. I am confused in designing the models. Below are the details:
I have a Model named UnicastMessageRequest, it's definition is like this:
...
0
votes
3answers
2k views
Shouldn't cost be good reason to migrate to .Net from Java
I have a RESTful services developed using Java Spring framework. It's not a huge application, around 12K lines of Java code. Front end is in Angular and DB is No-SQL world.
Recently I came to know ...
2
votes
4answers
622 views
What do OOP languages gain from having constructors that always return an object?
In what seems like a deliberate design decision, C++ does not have a null value for objects and references. This makes using objects and references very elegant since we don't have to perform null ...
30
votes
9answers
7k views
Designing a Class to take whole classes as parameters rather than individual properties
Let's say, for example, you have an application with a widely shared class called User. This class exposes all information about the user, their Id, name, levels of access to each module, timezone etc....
-3
votes
1answer
5k views
UML Class Diagram HashMap Data Type
How can I show a Java HashMap data type in UML Class Diagram (or C# dictionary)?
I.E. This class:
public class Test
{
private Map<String, String> map;
private Map<String, int> ...
1
vote
0answers
455 views
Are constructors with complex initialization logic always bad? [duplicate]
I've recently read this blog post regarding what a constructor should do and I am also reading Eric Evans' book on Domain Driven Design.
Both the blog post and the book state that a constructor ...
3
votes
4answers
3k views
Public static method calls private constructor
I'm working in a C# codebase that was largely written by a former developer and this pattern is used extensively...
public class AuditInserter
{
public static void Insert(
DataContext ...
-2
votes
1answer
319 views
Role-based declarative security for C#
According to Domain Driven Design and Development In Practice:
Spring Security (a sub-project in Spring Portfolio) provides a
fine-grained access control in both presentation (URL based) and
...
8
votes
5answers
4k views
Reason for (post/pre) increment operator in Java or C#
Recently, I've stumbled across question about predicting the output of code which heavily uses post/pre increment operators on integers. I am experienced C programmer, so I felt like at home, but ...
10
votes
3answers
2k views
Is it good practice to wrap a related set of properties into its own struct/class?
Writing a User object in Swift, though my question relates to any strongly typed language. A User can have a bunch of links (FacebookProfile, InstagramProfile, etc). A few questions around this.
Is ...
11
votes
5answers
4k views
A reference counting pattern for memory managed languages?
Java and .NET have wonderful garbage collectors that manage memory for you, and convenient patterns for quickly releasing external objects (Closeable, IDisposable), but only if they are owned by a ...
15
votes
7answers
2k views
Primitive vs Class to represent simple domain object?
What are general guidelines or rules of thumb for when to use a domain-speciifc object vs a plain String or number?
Examples:
Age class vs Integer?
FirstName class vs String?
UniqueID vs String
...
6
votes
3answers
1k views
Why is the most common integer number 32 bits, but the most common floating point number 64 bits?
Coming from a Java and C# background, I've learned to use int (32 bits) whenever I need a whole number, and double (64 bits) when dealing with fractional values. Most methods from their respective ...
32
votes
7answers
9k views
What does this statement about C# and Java being half of a language mean? [closed]
In the article: Why POCO, there is this sentence:
Maciej Sobczak puts it well: “I just don’t like when somebody gives me half of the language and tells me that it’s for my own protection”.
I don't ...
0
votes
3answers
675 views
Are objects that can pass more than one IS-A test really polymorphic?
A number of tutorials on polymorphism state that "Any object that can pass more than one IS-A test is considered to be polymorphic." I wonder what they mean by that, and if that's even a true ...
3
votes
1answer
3k views
Which is better of these two class diagrams for calculator project and why?
I'm a novice programmer i draw two class diagrams for calculator Project, i want you to check each one of them and tell me which one is better and also, i would appreciate it if you point out the ...
3
votes
2answers
498 views
Why does C#'s System.Threading.Semaphore implement IDisposable and why doesn't java.util.concurrent.Semaphore implement Closeable?
In .NET framework, System.Threading.Semaphore is an IDisposable that requires manually invoking dispose. However, in JavaSE, java.util.concurrent.Semaphore is not a Closeable nor an AutoCloseable.
...