Skip to main content
13 votes

Supermarket Product Inventory Management with Polymorphic Product Types

First, a Code Review Anti-pattern Please don't do this: record = new String(); This is (barring compiler heroics), creating a brand new empty string literal, ...
AJNeufeld's user avatar
  • 35.3k
12 votes

Function overloading / dynamic dispatch for Python

I will offer some subjective opinions and objective observations. Benefits The main benefit of the overload pattern as I see it (including, but not exclusively, as implemented in your code) is that it ...
Reinderien's user avatar
  • 71.1k
11 votes

Area calculator for shapes as an OOP interview test

I see some things that may help you improve your code. Don't overcomplicate your code The only thing required of the Shape and ...
Edward's user avatar
  • 67.2k
11 votes
Accepted

A tree of polymorphic types (Crafting Interpreters Book)

Unique pointers own objects It's important to realize that std::unique_pointer does not only free memory automatically, it also restricts copying pointers, such ...
G. Sliepen's user avatar
  • 69.3k
9 votes

Adapting a hierarchy of polymorphic classes to std::variant

It won’t work This is a bad idea, on just about every level. Let’s start with something that can’t be argued: it just won’t work. Your example inheritance hierarchy looks like this: ...
indi's user avatar
  • 16.5k
8 votes
Accepted

Area calculator for shapes as an OOP interview test

For a junior hire, I may have accepted the answer, but I would have pointed out the short comings while discussing the answer, and see if the candidate could adjust the code accordingly. I agree with ...
jxh's user avatar
  • 470
8 votes

A tree of polymorphic types (Crafting Interpreters Book)

Enable more warnings so your compiler can help you Many problems can be diagnosed automatically, prior to human review. For example, using GCC: ...
Toby Speight's user avatar
  • 88.4k
8 votes
Accepted

A static version of std::polymorphic

I’m not a fan of deriving from variant for this use case, not least for the fact that it’s mixing metaphors. The point of ...
indi's user avatar
  • 16.5k
7 votes
Accepted

Implementing different types of light sources in a Graphics project

Why is LightSource inheriting from IMovable and IRotatable if not every ...
Cornholio's user avatar
  • 941
7 votes
Accepted

polymorphic message container

Overview Your Holder class is not really useful as everything is public! Overall, there is nothing to really review as you have not built anything. Things you ...
Loki Astari's user avatar
  • 97.7k
7 votes
Accepted

Function overloading / dynamic dispatch for Python

Does the interface seem ergonomic?; Yes. Except having to define MyClass twice for methods. Which you may be able to solve by changing the algorithm to be lazily, ...
Peilonrayz's user avatar
  • 44.6k
7 votes

Adapting a hierarchy of polymorphic classes to std::variant

You virtually never (no pun intended) want to combine std::variant with inheritance. Among other problems, most implementations of multiple inheritance will confuse ...
Davislor's user avatar
  • 9,115
6 votes
Accepted

Simple implementation of signals and slots mechanism using templates

[code] uint64_t It should be std::uint64_t, not uint64_t for key indexes (the latter is the C version). Or better: use ...
user673679's user avatar
  • 12.2k
6 votes

Model animals using inheritance in Java, revised

This is better, but you are still missing a lot of basic ideas. I'm going to continue to approach the code review by looking at concepts and suggesting what you need to consider and what you should ...
Mark Bluemel's user avatar
  • 1,602
5 votes

Implementing different types of light sources in a Graphics project

Overriding RotateX, RotateY and RotateZ to prevent rotation of your point light source is ...
AJNeufeld's user avatar
  • 35.3k
5 votes
Accepted

Polymorphism and inheritance in C99

First of all, the obvious remark is that this needs to be split in multiple files, with a .h/.c pair for each class. Since you haven't done so, you block the possibility to make this truly OO. It is ...
Lundin's user avatar
  • 4,919
5 votes
Accepted

Maze game from book Design Patterns with smart pointers and polymorphism

You follow good practices for inheritance The "example" you show at the beginning uses some bad practices: It doesn't make the destructor of MapSite ...
G. Sliepen's user avatar
  • 69.3k
4 votes

A vector-like polymorphic container to store objects from a type hierarchy in contiguous memory

This is some really nifty code. I'd be curious to see the full implementation and whether there were any improvements since this question was posted. :) [code] make_aligned Is there a reason for ...
user673679's user avatar
  • 12.2k
4 votes
Accepted

Polymorphism with overrides and base calls simulating an employee

There is one thing I don't line about Employee: you are leaking memory. Person super; should be a pointer, not the object. You ...
Pablo's user avatar
  • 201
4 votes
Accepted

CUDA/C++ Host/Device Polymorphic Class Implementation

nice! The code is generally rather good. I don’t have a lot to say about the language usage in the individual lines. The idea of using an abstract base to do different implementations selected at ...
JDługosz's user avatar
  • 11.7k
4 votes
Accepted

A C++17 std::function implementation

Nice, clean and functional. Still, there are a few things: If you don't have to declare a special member-function, just don't: bad_function_call::bad_function_call()...
Deduplicator's user avatar
  • 19.9k
4 votes
Accepted

A polymorphic union in C++

I suggest not codifying the derived types suggested in the type. Only note the ultimate base, size and alignment. Thus you are open to later change. Add a templated alias to get the proper type from ...
Deduplicator's user avatar
  • 19.9k
4 votes

Polymorphic deleter for unique_ptr

This Code Does Not Compile I threw together some boilerplate for Integer and IntegerDeleter. The provided code appears to be ...
Davislor's user avatar
  • 9,115
4 votes

Implementation of tree with different node types and faux-polymorphism in C

Remarks for beginners: Never hide a pointer behind a typedef! Never! It makes the code confusing and very hard to read and maintain. You can't unfortunately use a generic ...
Lundin's user avatar
  • 4,919
4 votes
Accepted

Manage Excel Styles with VBA OOP Approach

Code is generally very clean, although I do have a number of reservations with some of the naming: c prefix for class modules, M ...
Mathieu Guindon's user avatar
4 votes

Supermarket Product Inventory Management with Polymorphic Product Types

Is inheritance really the answer? I think it's been covered that you could dynamically build your product instances, but it's not really clear to me why you'd need to. The object model feels a bit ...
forsvarir's user avatar
  • 11.8k
4 votes
Accepted

Cache for mesh objects

I generally favor readability and maintainability over performance until profiling reveals issues. That's a very good mindset to have. I think the lack of elegance in your code comes from the fact ...
G. Sliepen's user avatar
  • 69.3k
4 votes

Adapting a hierarchy of polymorphic classes to std::variant

Create a stand-alone function instead of a type Creating a type PolymorphicVariant is bad, as explained by indi in great detail. Davislor already hinted at not ...
G. Sliepen's user avatar
  • 69.3k
3 votes

Polymorphic implementation for == with CRTP

First and foremost, I believe that your fundamental concept is flawed. Equality has a well defined meaning between objects of the same type, or between types themselves, but not in this hybrid ...
papagaga's user avatar
  • 5,817

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