Skip to main content
20 votes

C# - Standard 52 card deck

class Card { readonly Ranks rank; readonly Suits suit; // ... } In this type definition, there is a grammatical mismatch: ...
Roland Illig's user avatar
  • 21.9k
19 votes
Accepted

C# - Standard 52 card deck

You have nicely read the rank count into the variable rankCount, but later, you are writing index % 13. It is not immediately ...
Olivier Jacot-Descombes's user avatar
17 votes

Can I lessen the use of boolean flag variables in this snippet?

Can I lessen the use of boolean flag variables in this snippet? Consider 1st comparing. ...
chux's user avatar
  • 36.4k
12 votes

C# - Standard 52 card deck

It always seems odd in code to see a constant whose name is a number and for it to have a value different to that number. You can set a value on an enum and the later ones automatically increment ...
Pete Kirkham's user avatar
10 votes
Accepted

Bouncing map back into its bounds, after user dragged it out

Readability Mainly looking for readability improvements/getting rid of those double ifs. Since you are considered about readability, I will focus on that part. Declare a flags enum on multiple lines ...
dfhwze's user avatar
  • 14.2k
10 votes

Can I lessen the use of boolean flag variables in this snippet?

I'm not familiar with unity so, I can't review your code from that perspective. But we can certainly make this code more concise. Let me show you how to get started with refactor this code. 1. Get rid ...
Peter Csala's user avatar
  • 10.8k
10 votes

Can I lessen the use of boolean flag variables in this snippet?

Each call to handleInputEvents() can set bShow to a new boolean value. We could approach the display update task by making a truth table. ...
J_H's user avatar
  • 42.3k
8 votes
Accepted

A* Algorithm in C# for pathfinding 2D tile grid

There is a lot of code here, so there is a lot to say; no way I'll covered everything! I'll do the easy things first, and then assume lots of them before we look at the algorithm. Style Usually C#ers ...
VisualMelon's user avatar
  • 7,591
7 votes

Can I lessen the use of boolean flag variables in this snippet?

Why don't you make button.show() simply do an early exit if the visibility state being passed in is already the same? I'm surprised it doesn't already work this ...
selbie's user avatar
  • 195
6 votes
Accepted

Ability System Implementation

Glad you took my suggestion and posted over here. I'm going to start from the most important (but also high-level) bits, and work my way towards specifics and code here. DESIGN ISSUES The main issue ...
Adam Brown's user avatar
6 votes

Sims-style walls part 2: Flood fill

I happen to like the way I've lined stuff up since it helps with debugging and spotting patterns I do not necessarily reflect this opinion. You use a lot of very short variable names for parameters ...
t3chb0t's user avatar
  • 44.7k
6 votes

World resource system for Adventure Game/RPG

A few notes: All IResource properties have public setters. Are you absolutely certain that other code should be able to modify those? I'd recommend making these ...
Pieter Witvoet's user avatar
6 votes

Rock Paper Scissors coding challenge

... "too mathematical" and "lacking object oriented principles" These go hand in hand. An algorithm is what it is. Not that it is or is not too mathematical but that necessarily busy, complex, or ...
radarbob's user avatar
  • 8,249
6 votes

Quaternion and Vector3 transfomation Math

If you want DRY the KISS way, I suggest substituting the if-chain.. ...
dfhwze's user avatar
  • 14.2k
6 votes
Accepted

Averaging quaternions

Below you can find some of my reflections. Method InputTracking.GetLocalRotation(XRNode.Head) is obsolete as DOCS says. There is a lot calculations per one frame indeed, but Quaternions are structs ...
Karol Miszczyk's user avatar
6 votes
Accepted

Generate Unique ID in C#

...
Jeff's user avatar
  • 860
6 votes

Can I lessen the use of boolean flag variables in this snippet?

Since this is tagged unity3d, rather than setting a flag somewhere else in the script, you can just do the following: ...
crass_sandwich's user avatar
5 votes

BestHTTP asset download

Instead of using a foreach here, you need to use a for-loop, since you have to know the index of the image to assign it to the correct texture. ...
Vogel612's user avatar
  • 25.5k
5 votes

Ability System Implementation

Ability You have some properties and some public fields. In general you should not have public uncontrolled fields. As first step let's make them properties, for example: ...
Adriano Repetti's user avatar
5 votes
Accepted

Slot Machine game

Your code is a mess on all levels. Sometimes you write Method () with a space, sometimes you write Method() without the space. ...
Roland Illig's user avatar
  • 21.9k
5 votes

Unity surface shader to blend between adjacent tiles

(Self-answer, and not comprehensive by any measure) After some consideration and more experimenting, I can offer one insight to this approach. It does not relate to shader code in any way but rather ...
Misza's user avatar
  • 231
5 votes
Accepted

Unity animations code

That moment when you know Unity better than C#. I'm on other side: I know nothing about Unity (except docs that I've read while writing this review) but know C# well. Let's merge our knowledge. ...
aepot's user avatar
  • 2,119
5 votes

C# - Standard 52 card deck

Note: The traditional order of suits is (highest to lowest) Spades, Hearts, Diamonds, Clubs. While this order does not matter for many games, there are also many games for which it does matter. ...
RBarryYoung's user avatar
5 votes
Accepted

Code to determine move position in a hex grid when the user moves the stick on the gamepad

My main concern with this code is its repetition: you're making the same checks over and over, and performing very similar actions over and over. This gives lots of space for bugs to hide in, and ...
Malacandrian's user avatar
5 votes

C# items that don't follow rest of interface

With pattern matching you can avoid explicit casting: ...
Peter Csala's user avatar
  • 10.8k
5 votes
Accepted

C# items that don't follow rest of interface

If you have to cast to concrete type then that is a code smell. Why have the state managers in a dictionary? Instead of a dictionary you can create another class to hold the state objects ...
CharlesNRice's user avatar
  • 4,438
5 votes
Accepted

Service Locator C#

Pattern or Anti-pattern Generally speaking Dependency Injection is preferred over Service Locator. SL is considered anti-pattern sometimes because it makes unit testing harder and tightly couples all ...
Peter Csala's user avatar
  • 10.8k
4 votes

Slot Machine game

You said you comment code poorly, which isn't exactly true, you don't comment. I can't be bothered to read all that code and try and actually understand what it is doing, I just scanned it looking ...
Code Gorilla's user avatar
  • 1,622

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