A best practice is a method or technique that is generally considered to be superior to other methods in achieving the same result.

learn more… | top users | synonyms

1
vote
0answers
14 views

How could this new approach to my deck of cards project be improved?

Previous review of this project: Final review of my deck of cards program Based on the previous feedback I've received, my program could become more flexible (it formerly created a standard 52-card ...
0
votes
0answers
43 views

Building 30 day alarm

I'm building an alarm set to reoccur every 30 days - I was wondering if I could get a few extra sets of eyes to look things over and see if you can notice anything I may have done wrong. Any/all ...
2
votes
1answer
75 views

Is this nested class design ineffective for my Deck class?

Previous review of this project: Proper use of multiple classes and member-accessing with one header? I'm nearly finished with my deck of cards project, and this time I made changes to hide the Card ...
3
votes
2answers
58 views

refactor Python code with lots of None type checks

When I wrote this it just felt messy due to the null checks. Any good ideas on how to clean it up would be most appreciated. def getItemsInStock(self): itemsInStock = [] items = ...
1
vote
2answers
40 views

What Data Annotations need to be shared/different between my Model & ViewModel to keep seperation of concerns?

I read this question and answers, about if Display Annotations on model properties violates the separation of concerns between view and model. And my interpretation of their answer was "No, not if ...
2
votes
1answer
32 views

Review a simple sprite sheet animation script

This is just a simple script for testing sprite sheet animations. I'm trying to improve my code style, so I'm curious about suggestions anyone might have about best practices or readability. ...
1
vote
2answers
41 views

Proper use of multiple classes and member-accessing with one header?

Previous review of this project: Am I following any bad practices in my updated Card and Deck classes? This time, I considered combining both classes into one header file so that I can reduce my use ...
8
votes
4answers
566 views

Repetitive code driving me crazy!

Ok, So first I must say that everything I know about coding I have learned on my own in my spare time so bear with me if my code is primitive, but please, I am open to any comments to make me ...
1
vote
1answer
65 views

Am I following any bad practices in my updated Card and Deck classes?

This code was first critiqued here (without the Card class): Please critique my C++ Deck class After learning more about data structures both online and in class, I wanted to revisit my Card and Deck ...
-1
votes
0answers
17 views

Using a url has to load dynamic content while still being SEO optimized [closed]

Please let me know if I should have posted this elsewhere.... I have a corporate website that loads dynamic content into a div when clicking links on the page. The url gets updated with a hashtag ...
1
vote
3answers
61 views

Learning C, basic string reversal function

I am starting to write some functions while studying how to program in C. In this small function I take a string as an argument and print it out in reverse order. #include <stdio.h> #include ...
2
votes
1answer
59 views

What is the best practice for working with a project as nested modules?

I come from the world of Python, so I'm used to every file representing their own enclosed module, never polluting the global environment. Up until now (I've worked with Ruby for a week) I've created ...
3
votes
1answer
92 views

Creating my own flow control statements in C++. Is that acceptable?

I always considered switch statement as somehow defective: works only on integral types and enumerations. isn't an readability improvement over traditional if/else chain. forget a break - you have a ...
3
votes
0answers
26 views

Using DOMDocument, really hesitant of this approach. Tips? Suggestions? Tear it apart and make me cry please?

I've tried to write an "OOP" approach to printing a website using the DOMDocument class. I'm kind of stuck here because I feel like I am blundering in how I am passing and using the DOMDocument. I ...
2
votes
1answer
65 views

Decreasing the running time

What is the best practice to output a list of prime numbers between two numbers? How can i achieve a better running time for this java code? This is a solution to a SPOJ problem which is getting time ...
0
votes
2answers
42 views

Setting element attributes via JavaScript as opposed to in HTML code itself [closed]

While code reading I came across a piece of code in JavaScript which set the placeholder attribute for an input element ($("#el").attr("placeholder", "I am Input");). I myself have always set such ...
1
vote
0answers
55 views

When is (if ever) monkey-patching acceptable? Is there a better solution to this?

I am working on a project that involves xml parsing, and for the job I am using xml.dom.minidom. During development I identified several patterns of processing that I refactored into discrete methods. ...
3
votes
1answer
75 views

Looking for advice on how to make my code better

I have to make project for school in C# which has to use database and web service. I have made program which starts web service and gets function from web service which is used for connecting to ...
0
votes
0answers
30 views

What is the difference of Code Review (beta) with StackOverflow? [migrated]

I know StackOverflow and Code Review are sites intended for two separate purposes, as the names suggest. However, I don't see any difference on how people ask and answer here compared to ...
1
vote
1answer
41 views

Is this an effective use of std::map and std::array for this type of program?

Some time ago, I've written a modulus-type program (using std::vector), inspired by a former professor of mine. The user inputs a number, and the program displays a modulus grid pertaining to that ...
0
votes
1answer
37 views

Is this the correct approach to animation in Java

I was fiddling with animation in Java and wrote this: import java.awt.Graphics; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import ...
1
vote
1answer
62 views

First time using std::map — am I developing any bad habits here?

This is from an older question of mine that I decided to revisit: Simple and efficient code for finding factors and prime factorization? In that question, someone suggested I use an std::map to hold ...
3
votes
1answer
112 views

How can I improve this C++ 'genetic algorithm' implementation?

now that I am almost done with my uni studies, I'm about to start jobhunting (aiming mostly for a Gameplay Programmer), and so I've created a code sample that I will link with my applications. ...
4
votes
1answer
40 views

Optional argument for which None is a valid value

I have the following function: def item_by_index(iterable, index, default=Ellipsis): """Return the item of <iterable> with the given index. Can be used even if <iterable> is not ...
2
votes
1answer
55 views

JSON AsyncTask refactoring to improve quality?

I'm new to Android. I was wondering if anyone had any suggestions. It's basically an AsyncTask to get a remote JSON array and put it into a native array. Would be very grateful for suggestions. ...
2
votes
2answers
77 views

Best coding practice for classes

I just have a somewhat simple question on coding practices. I have never written a large application before and I am currently working on building a game engine in Javascript. The part that confuses ...
2
votes
1answer
52 views

Unable to understand seniors review comment.

I wrote the following code to read a config file line by line and split each line into 2 parts and store them separately. The split is done on the basis of a delimeter '=' : std::ifstream ...
3
votes
2answers
45 views

Default value or conditional?

Which of the following two is preferred: var somevar = valueA; if(condition) { somevar = valueB; } or: var somevar; if(condition) { somevar = valueB; } else { somevar = valueA; } ? ...
2
votes
0answers
68 views

Models in .NET: separate settings?

For my models for a certain section I thought it would be better to have a base class model for both "view" and "edit" models, like so: public abstract class Setting { [Required] public int ...
0
votes
1answer
48 views

Box(x,y,X,Y), box(x,X,y,Y), box(x,w,y,h), box(x,y,w,h) or box(fromPos,toPos)?

Say you are representing a box, or creating a function that slices a 2d array, or whatever. How do you represent it?
1
vote
1answer
33 views

when we need to add some javascript code to html, where we have to put it?

when we need to add some javascript code to html, where we have to put it? What is the best practice: in line: <script type="text/javascript">document.write(new ...
-1
votes
1answer
37 views

What's Haskell's way to do this: “fn object target” or “fn target object”? [closed]

For example, ends_width str prefix or ends_width prefix str? I think one is better for partial, other is better for infix. What's the preferred style in a FP perspective?
1
vote
1answer
85 views

Elegantly check for null before method call

How do I elegantly check for null before calling a method on an object? This is how I do it right now: var title = document.querySelector('title'); title = title ? title.text : ''; Null Object ...
5
votes
3answers
506 views

Is it wrong to write an entire program under one class/method in Java?

I'm new to programming an created a simple rock, paper, scissors game. The entire program is under a single class and the main method, i hear that's probably not the best way to code. How should i ...
2
votes
0answers
45 views

Practical advise for CMS

I'm working on a CMS system. The basis is pretty much done but before going any further I would like to know if there are things I really should change in the way I code things. I am pretty sure ...
2
votes
2answers
93 views

Guess my Number in Java

I have just started learning Java, and don't want to start any bad habits, so please can I have a review on my latest game code: import java.util.Random; import java.util.Scanner; class GuessMyNumber ...
2
votes
0answers
183 views

Cleaning and/or best-practice for floating-point binary/decimal/octal/hex converter

This new code comes from my original converter (without floating-point support): Cleaner and/or more practical code for decimal/binary/hex converter I've had some trouble implementing floating-point ...
1
vote
0answers
52 views

Best practices in implementing service methods

Consider the following architecture: ASP.NET MVC Application having controllers which depend on service classes (MembershipService, EmailService etc.) which in turn depend on data access context ...
1
vote
0answers
50 views

Changing states of a game character and constructor signature

I have an Actor class who represents the player and the NPCs of an game. The Actor have an StateMachine object who manages the push and the pop of the states of the Actor object. The Actor have only ...
1
vote
2answers
48 views

Changing the state of another entity into the constructor method

I have a Clock class who inherites from pyglet.clock.Clock and behaves like a Singleton. Into the constructor method I have the following line: pyglet.clock.set_default(self) Who changes the state ...
3
votes
4answers
419 views

Best practices in PHP

I've posted here before and got pretty helpful reviews. So, how does my code look now. To keep it really helpful, I just copied this from the middle of one of my projects. Review please? <?php ...
4
votes
3answers
157 views

Using ref for value types - Is this the right usage or is it weird at multiple levels

I chanced upon this code written by the Solution Architect for a MS CRM project and I am lost for words. Am I going crazy or is this code OK? string returnedOptionSetStringValue=string.Empty; int ...
1
vote
2answers
79 views

Encapsulating logging and throwing exceptions into a method. Bad practice?

original code example if (var1 == null) { String msg = "var 1 is null"; logger.log(msg); throw new CustomException(msg); } if (var2 == null) { String msg = "var 2 is null"; ...
1
vote
1answer
67 views

Is there a better way to make a function silent on need?

I got a piece of code I'm not pleased with; Does anyone would have a better idea? def myFunc(verbose=True): if not verbose: print = functools.partial(globals()['print'], ...
0
votes
2answers
64 views

Structuring Events in JavaScript

Below is the basic shell of an application I am working on that is part of a Webhosting Control Panel. This part is for the DNS records management. So in my code below, I have taken away all the main ...
1
vote
1answer
75 views

Accumulating inner exception messages

Say, there is a class with some methods, that have try catch blocks. I need to accumulate messages from all inner exceptions of generated exception and use throw new Exception(exceptionMessages). I ...
2
votes
3answers
149 views

Cleaner and/or more practical code for decimal/binary/hex converter

I've finally finished my converter and have determined that it works, but I'm trying to make it cleaner and/or more practical (primarily with the switch statements). I could probably put more things ...
0
votes
1answer
72 views

I've finally found a satisfactory way to create classes on JavaScript. Are there any cons to it?

Depending on external OO libraries is really bad, using prototypes/new has some limitations, using only hashes has others. Dealing with classes was always a pain in JavaScript and it didn't help that ...
2
votes
1answer
118 views

Collision detection implementation

I'm working on a clone of Hunter Story. You shoot monsters with your bow. Recently I implemented collision detection, this is all working correctly, and I don't think the code needs any dramatic ...
3
votes
1answer
283 views

Which is better: the short, clever way, or the long, ctrl+c way?

The code below is equivalent. I can see pros and cons for both versions. Which one is better? Short version: character.on("key",function(key){ var action = ({ ...

1 2 3 4 5 7