Skip to main content
Share Your Experience: Take the 2024 Developer Survey
35 votes

Calculate evapotranspiration

I wonder if there is a need for a class here? It seems class Hargreaves has no responsibilities and is solely used to compute the evapotranspiration value based on ...
Peter's user avatar
  • 451
17 votes
Accepted

TString - An implementation of std::string

Justify text. (.rjust, .ljust, center) That is becoming a "fat interface". These functions should be generic algorithms that can work with any string class, including yours, ...
JDługosz's user avatar
  • 11.4k
16 votes

ReversibleList: a list that is "reversed" in O(1) time

Bug You have a bug! a[2:5] = ReversibleList([1, 2, 3]) print(a) # [5, 4, 3, 2, 1, 0] ReversibleList([1, 2, 3]) is constructing ...
AJNeufeld's user avatar
  • 33.7k
16 votes

ReversibleList: a list that is "reversed" in O(1) time

I don't really like the direction toggling stuff. Mostly on the grounds of disliking state if possible. You could end up with the list pointing in the opposite direction to the one intended. What I ...
Att Righ's user avatar
  • 261
12 votes
Accepted

Setters dependent on other instance variables in Java

Allowed? Yes. There seems to be nothing technically wrong with your code. Good practice? No. Specifically, in your example code setPddocument is not actually a ...
Lev M.'s user avatar
  • 1,081
10 votes

Date class in C++

Not bulletproof Maximum amount of days in a month depends on both month and a year. It doesn't seem like the class cares about it. The rest of the answer might not be interesting to you. Operations ...
Incomputable's user avatar
  • 9,504
10 votes

Calculate evapotranspiration

To add to Peter's excellent answer, please also consider the likely audience of your code. I do not know who Hargreaves is, (or even that it's a name, looking only at the source), and practically ...
Adam Barnes's user avatar
10 votes

High performance physics simulation - core class design

Missing #includes You are using std::vector, but did not #include <vector>. The code ...
G. Sliepen's user avatar
10 votes

Using MergeSort to sort data structured in Person class based on object attributes (DRY)

You can reduce the amount of code: Throw away get_ methods, just use .name not .get_name() ...
Peilonrayz's user avatar
  • 43.4k
9 votes
Accepted

Generic Doubly Linked-list implementation in C++

Identifiers that start with a double underscore, or a single underscore followed by a capital letter, are reserved for use by the implementation. Your use of __T ...
1201ProgramAlarm's user avatar
9 votes

A simple Python class designed to facilitate investment portfolio analysis

time representation class Portfolio: ... start_date: str end_date: str I'm sad those aren't datetimes, or at least dates. Then we get validation (no ...
J_H's user avatar
  • 28.1k
8 votes
Accepted

Simple Multiclass C++ Project

Don't use std::endl Use "\n" instead of std::endl. The latter is equivalent to <...
G. Sliepen's user avatar
8 votes
Accepted

File editing class

"<object_name> = EditFile(<file_name>)" is not a particularly useful __repr__. Note the guidance in the data model ...
jonrsharpe's user avatar
  • 13.9k
8 votes
Accepted

Snail matrix in Java

Expose behavior / Don't manipulate the internal state directly Object-orientation is about exposing behavior (not data), defining methods that are tailored for the problem at hand, that are meant to ...
Alexander Ivanchenko's user avatar
7 votes

Date class in C++

Creating a proper date class is actually fairly complicated, and depends how far you're willing to go to make an interface that adheres to the pit of success principle. As Scott Meyers warns, ...
JNS's user avatar
  • 421
7 votes

Classes for the blog (PHP)

I really hope that you are trolling us, but if you are not trolling and this is a real code, then I must say that it should absolutely never be used. This might have been acceptable 25 years ago, but ...
Dharman's user avatar
  • 881
7 votes

Setters dependent on other instance variables in Java

In addition to @notescrew's answer: Look at your Pdf class from a user's point of view. I'd like to write ...
Ralf Kleberhoff's user avatar
7 votes

Calculate evapotranspiration

As someone who has to read/write science code, please please include units in your constants, and in the output from your function. They are in the equations, but not the code. I still wish that we ...
AUnitPerson's user avatar
7 votes
Accepted

PHP HTML form Class - so far so good?

I have not conducted a deep review of your scripting, but I have a few pieces of superficial advice: Study PSR-12 coding standards and obey every rule. This will make your code easier for you and ...
mickmackusa's user avatar
  • 8,674
6 votes

Date class in C++

Design You use three values to represent a date Year/Month/Day. This makes nearly all ...
Martin York's user avatar
  • 95.2k
6 votes
Accepted

chess game Class

General Observations Unlike some more modern languages such as C# and Java, a C++ class is generally implemented as 2 files: a header file generally with the file extension ...
pacmaninbw's user avatar
  • 23.9k
6 votes
Accepted

Address class in PHP 7.4 with types

I saw your post yesterday before it was deleted. I didn’t have much to suggest but after seeing this code there are a few things I would change. The suggestions by YourCommonSense are great: Specific ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
6 votes
Accepted

Cleanly passing in a large number of mutable parameters through a python class

I'm going to address your existing code in a manner that generally goes from most minimal to most significant changes. I'd strongly recommend actually using the solution at the very bottom of this ...
ShadowRanger's user avatar
6 votes

Contact management system

Names, phone numbers and email addresses are not unique A lot of your code hinges on names, phone numbers and email addresses all being unique identifiers for a contact. However, none of these things ...
G. Sliepen's user avatar
6 votes
Accepted

ReversibleList: a list that is "reversed" in O(1) time

Consider composition over inheritance Doing inheritance right is very hard. Keep in mind that subclass coupling (when class A is a subclass of class B) is the strongest type of coupling between two ...
janos's user avatar
  • 111k
6 votes
Accepted

Making a game using python and pygame

It looks like you're actually mixing a few unrelated things here. Consider: how many of these are actually settings? That is, how many of these does it make sense for the end user to modify in some ...
l0b0's user avatar
  • 8,917
6 votes

PHP HTML form Class - so far so good?

You could make it much more simpler to read if you use templating engine. Rendering HTML right inside php is something many experienced developers try to avoid for multitude of reasons. One of them ...
slepic's user avatar
  • 5,477
6 votes
Accepted

Multi-dimensional Image Data Structure with Variadic Template Functions in C++

Allow 1D images One-dimensional images are not that uncommon in computer graphics. There is no reason why your class couldn't be made to support them. Make the constructors generic Instead of having 4 ...
G. Sliepen's user avatar
6 votes

A simple Python class designed to facilitate investment portfolio analysis

You've mixed degrees of freedom by computing some of the stats with Pandas (\$N-1\$) and others with NumPy (\$N\$): pandas.Series.std (default ...
tdy's user avatar
  • 1,420
5 votes

Blackjack with card representation visuals

Deck.reset bug This function has no access to num_decks, so if you decide to call this function it will fail with a syntax error....
Linny's user avatar
  • 10.1k

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