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 ...
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, ...
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 ...
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 ...
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 ...
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 ...
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 ...
10
votes
High performance physics simulation - core class design
Missing #includes
You are using std::vector, but did not #include <vector>. The code ...
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 ...
8
votes
Accepted
Simple Multiclass C++ Project
Don't use std::endl
Use "\n" instead of std::endl. The latter is equivalent to <...
8
votes
Accepted
File editing class
"<object_name> = EditFile(<file_name>)"
is not a particularly useful __repr__. Note the guidance in the data model ...
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, ...
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 ...
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
...
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 ...
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 ...
6
votes
Date class in C++
Design
You use three values to represent a date Year/Month/Day. This makes nearly all ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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....
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
...
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 ...
5
votes
Accepted
Undirected graph data structure in C#
Naming
Renaming your instance variable _V and _E to nbVertices and ...
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 ...
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? ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
classes × 420object-oriented × 133
php × 95
python × 85
c++ × 79
c# × 56
java × 43
beginner × 38
python-3.x × 24
javascript × 21
design-patterns × 19
performance × 16
game × 15
pdo × 15
inheritance × 15
playing-cards × 13
android × 11
php5 × 11
template × 10
ruby × 9
datetime × 8
tkinter × 8
static × 7
strings × 6
c++11 × 6