Hot answers tagged

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.3k
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.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
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,374
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
  • 50.5k
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
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
  • 50.5k
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
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,544
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
  • 94.3k
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.5k
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
  • 50.5k
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,887
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,367
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
  • 9,989
5 votes

Blackjack with card representation visuals

system() replace os.system with a call to subprocess, which for all intents and purposes replaces the former. Type hints ...
Reinderien's user avatar
5 votes

Simple Multiclass C++ Project

Code structure The code in the file main.cpp only operates on FDeepDishPizza class, so the name sounds misleading to me. It ...
aki's user avatar
  • 824
5 votes
Accepted

Undirected graph data structure in C#

Naming Renaming your instance variable _V and _E to nbVertices and ...
cliesens's user avatar
  • 558
5 votes

Generic Two Dimensional Data Plane with Manipulation Methods For C#

Welcome to Code Review! I don't have much time to write a full review right now, but I'll give you a concise list of things you could do to improve your code (in my opinion). Naming Use ...
cliesens's user avatar
  • 558
5 votes

Address class in PHP 7.4 with types

I was able to come up with two suggestions so far Using a generic exception is definitely not the way to go. Ask yourself a question, what your code is supposed to do when such an exception is thrown? ...
Your Common Sense's user avatar

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