Skip to main content
36 votes

Really simple immutable class

Make it simpler, you can use read-only properties: ...
Adriano Repetti's user avatar
12 votes
Accepted

Simple builder pattern implementation for building immutable objects

First of all, very good job. Now I will point out a few things that I think can be improved on. Code Duplication You have copied over all the private fields from ...
Thijs Riezebeek's user avatar
10 votes
Accepted

Selective updates to immutable types

You should be able to cut the code length and improve performance, by simplifying the algorithm. Here are some of the problems I've noticed in your implementation: You're currently processing all of ...
Denis's user avatar
  • 8,508
9 votes
Accepted

My attempt at an immutable container view in C++

Your view isn't immutable, though immutability might be a property of the underlying object. It's a constant view, meaning the underlying object might change, but not from that view. The canonical way ...
Deduplicator's user avatar
  • 19.3k
9 votes

Immutable Object class in VBA – Creatable only through constructor and not via “New” keyword

Indentation The non-standard end-of-block token indentation is off-putting; this is the first time I see VB code that doesn't align the start and end token columns of code blocks: ...
Mathieu Guindon's user avatar
8 votes
Accepted

Generic immutable object builder

I would prefer the following syntax for its compile-time type-checking: ...
Blorgbeard's user avatar
7 votes
Accepted

Initializing immutable objects with a nested builder

When I think of immutable object I think of get only properties backed with readonly fields. ...
Denis's user avatar
  • 8,508
7 votes
Accepted

Immutable builder and updater

You use IList<> where you should use ICollection<>. I've rarely encountered a scenario where ...
IEatBagels's user avatar
  • 12.4k
6 votes
Accepted

Cat fight (with rockets)

First, let me get out of the way that I'm not a "Functional Programmer", and I probably won't ever be. I'm also not an "Object-Oriented Programmer", or any other paradigm. I tend to use whatever the ...
CAD97's user avatar
  • 1,944
6 votes
Accepted

Stack as a Persistent Data Structure Implementation

In this implementation, null entries are problematic. From the public interface, it is impossible to tell if the stack has a null entry, or has reached the bottom: ...
Benjamin Kuykendall's user avatar
5 votes

Generic immutable object builder

I'm afraid a builder such as this is a dangerous thing. Field and property names are case sensitive. Changing their casing like the below extension could result in setting the wrong field or in case ...
t3chb0t's user avatar
  • 44.3k
5 votes

Immutable Object class in VBA – Creatable only through constructor and not via “New” keyword

EDIT Mat's Mug has the best approach in going for an Interface and an add-in, but if you constrain the requirements to a self-contained solution, and you assume the user of the class is unfamiliar ...
ThunderFrame's user avatar
  • 1,959
5 votes

Implement array element swap in a functional language

First and foremost: while mutation may be generally frowned upon in F#, in some cases (like this one) it's acceptable to make a tradeoff of immutability vs. performance or maintainability. In this ...
Der Kommissar's user avatar
5 votes

Implement Immutable Collection in C#

Abstractness To be precise, this class is meant to be inherited by multiple derived classes, which actually define the constants. Do you mean there will be many classes each of which contain a ...
VisualMelon's user avatar
  • 7,431
5 votes

An immutable C++ string with ref-counting

Possible memory leak On the deallocate() method, counter is decremented in two phases. In the first phase you read the current counter value. In the second one you ...
Gerard Torrent's user avatar
5 votes
Accepted

An immutable C++ string with ref-counting

In no particular order. NUL-termination The ASCII character with a value of 0 is the NUL character. C Strings are thus NUL-terminated strings. I would advise changing the comment ...
Matthieu M.'s user avatar
  • 5,277
4 votes

Really simple immutable class

I would like only to show other possibility how "lock" a variable, but Adriano Repetti shows a really nice work in the other post. So, you also might consider using ...
Rao's user avatar
  • 193
4 votes

Immutable Object class in VBA – Creatable only through constructor and not via “New” keyword

Naming I'll start off with a small style gripe (the indentation is the big one, but that's already been covered). Your naming convention for your private instance members is confusing. This... <...
Comintern's user avatar
  • 4,192
4 votes

Simple builder pattern implementation for building immutable objects

You can simplify your builder by removing the final specifiers from the fields of Person. Don't worry, unless you add setters ...
coderodde's user avatar
  • 28.7k
4 votes

Simple builder pattern implementation for building immutable objects

If you would use Lombok, you can get the same classes with less code: ...
Roel Spilker's user avatar
4 votes
Accepted

Immutable File Upload Server Configuration Class (FTP or Network Drive)

The huge constructore is the result that the SaveDirectory class is doing too much. It has to know everything about the ftp server as well as about the network ...
t3chb0t's user avatar
  • 44.3k
4 votes

Implementation of a Location object, to be used in building a text-based adventure game

The circular references are made possible via lazy evaluation The evaluation is not really lazy yet. To make it truly lazy you need to use the Lazy<T> Class...
t3chb0t's user avatar
  • 44.3k
4 votes
Accepted

Quicksort in JavaScript assuming an immutable array

Your code looks quite good. It is easy to read and understand. I don't know how efficient it is, though. The reorder function creates lots of objects (3 arrays, ...
Roland Illig's user avatar
  • 21.3k
4 votes
Accepted

Implement a Python frozenmap

Library code cannot resort to global variable hacks. You are attempting to implement a data structure. That's a bedrock kind of library code. As such, it cannot resort to crazy mechanisms like setting ...
FMc's user avatar
  • 12.8k
3 votes
Accepted

Implementation of a Location object, to be used in building a text-based adventure game

It's been since awhile I've done .NET dev but I'll take a stab at it. Style Line length. Some of the lines are over 150 characters in length. While I can't find a concrete guideline in Microsoft's ...
jsuth's user avatar
  • 857
3 votes

Simple builder pattern implementation for building immutable objects

Several people are recommending to remove the final keyword from the private fields. I would strongly recommend against doing that. The whole point of the final keyword is to prevent accidental re-...
Jilles van Gurp's user avatar
3 votes

Creating Immutable Student Object

There are many code smells: You create a single Student class, and differentiate students by an explicit type. This is a bit sad in an object-oriented language, where one should rather attempt to use ...
Elegie's user avatar
  • 541
3 votes

Immutable Object Patterns for Domain Models

A few suggestions in the code. Use Dependency Injection for better test-ability In Controller ...
vishnu vardhan's user avatar

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