Skip to main content
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
24 votes
Accepted

Simple Container Class

Advice for learning Don’t do this. The container you are trying to implement is std::vector. You don’t call it that, and you never say explicitly that ...
indi's user avatar
  • 16.5k
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.7k
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
  • 35.3k
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
11 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
  • 69.2k
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,724
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

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
  • 44.5k
10 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
  • 42.1k
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
Accepted

Creates class and makes animals, then print bios

Thank you for sharing. There's some good things going on in this code. constructor ...
J_H's user avatar
  • 42.1k
9 votes
Accepted

Project Euler #54: class for poker hands

I encourage you to read the other answers, they have good advice. I'll focus on using classes. What is a type? That's a fairly abstract question, I recognize, but it's a crucial part of the ...
Matthieu M.'s user avatar
  • 6,389
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
  • 69.2k
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
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
8 votes

What is the best way to set a class value to a variable in Python if it exists in a dictionary?

Correctness remote_str is defined at wrong indentation level, it will fail with an UnboundLocalError for ...
STerliakov's user avatar
  • 2,034
8 votes

Creates class and makes animals, then print bios

DRY There is a lot of repeated code in the bio function. You repeat the age check twice and the print 4 times with few ...
toolic's user avatar
  • 15.7k
8 votes

Creates class and makes animals, then print bios

In addition to what the others have said, it would make your class more flexible if Animal.bio returns a string rather than printing one itself. You can still: <...
Chris's user avatar
  • 4,329
8 votes

Project Euler #54: class for poker hands

Naming Most of the functions and variables have descriptive, meaningful names. However, the function vals_and_suits is a little vague. It looks like it sets values,...
toolic's user avatar
  • 15.7k
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
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
  • 26.1k
7 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
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

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,802
7 votes
Accepted

What is the best way to set a class value to a variable in Python if it exists in a dictionary?

tl;dr: It should be a @dataclass. code which sets values in a location class from values from JSON data. The vocabulary word you're looking for is "object attribute". The code sets ...
J_H's user avatar
  • 42.1k
7 votes

Simple Container Class

Use std::copy instead You don't need to implement CopyData. You can use std::copy to copy ...
JimmyHu's user avatar
  • 7,535
7 votes

Creates class and makes animals, then print bios

The other answers are fairly complete, but one addition that might be helpful, assuming you don't plan on adding any other descriptions of the animal, would be the ...
XenonPy's user avatar
  • 131

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