A coding style is a set of conventions and practices used in software, such as naming classes, variables, and files.
2
votes
0answers
23 views
Color fading function
I found this old color fading function in my snippets folder and would like to implement it to one of my projects. It can be used to fade one color to another. It's a very long one-liner:
D3DCOLOR ...
5
votes
2answers
85 views
Are these good examples of functions that do one thing only or am I getting a little carried away?
I'm reading Robert C. Martin's "Clean Code" and for the past few days I've been fiddling with its function writing guidelines. At first I thought the idea of functions being two/three lines long to be ...
5
votes
6answers
97 views
How to get rid of semantic duplication
I am breaking my head with how to get rid of semantic duplication(Code that is syntactically the same but does different things).
I can't find anywhere a post or something that mentions a bit how to ...
3
votes
1answer
88 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.
...
3
votes
1answer
88 views
C++ Linked List: Would This Code be Considered Clean If written in an Hour Long Interview
If you were interviewing me, and saw this code written in a little under an hour would you consider me as a candidate for a position at your company if you knew I had 2 years of C++ experience.
...
1
vote
1answer
49 views
Anyone have some ideas about my code?
I have this class that pulls people out of a database. I want it to be a little prettier and function better. Anone got ideas? Feel free to ask questions :)
<?php
class comps extends db_config {
...
2
votes
2answers
91 views
Trying to get better at Ruby and programming in general- here's a simple TopCoder question in Ruby
I want to get general feedback and feedback about if I can make this more Ruby-like, if there are any obvious inefficiencies, and if I need to organize my class differently. The topcoder question is ...
0
votes
1answer
59 views
Is there a better way to count seconds in python
def stopWatchSeconds(secondCnt) :
""" counts second for secondCnt seconds """
# is there a better way to do this?
startTime = time.clock()
ellapsed = 0
for x in range(0, ...
5
votes
1answer
99 views
Recommended Naming for function that tests and mutates
I am a huge proponent of self-documenting code (when at all possible). I prefer to have code be self evident by the very nature of the names of the variables, methods, etc.. For instance:
if ...
-1
votes
0answers
35 views
Checklist for coding MVVM web application [closed]
We are a small team working on a web application using MVVM design pattern using technologies like .NET, Knockout and HTML. I am trying to come up with a code review process and as a first step trying ...
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
2answers
52 views
Global variables in python, bottle microframework
I'm sort of at a loss for what to do with webapps and whether what I'm doing is actually allowed or not. Here is a sample of the type of thing i'm doing at the moment. I need a list that is accessible ...
1
vote
2answers
93 views
Email report generation from database
I have written a small batch job which will collect data from db and send mail to user. Can you please do a review of the code with design prinicples in mind and also with best practices for Db and ...
-1
votes
1answer
54 views
Java Question for An Absolute Beginner [closed]
This is for a beginning Java course that poses the problem:
Write a class named Employee that has the following fields:
name. The name field references a String object that holds the employee's ...
2
votes
1answer
71 views
Can I make a regex array to iterate through in C++?
I have to check a string to various regular expressions in C++. Up to now, I've done this using something similar to this:
regex regex_a (".."); string rewrite_a = "($1/$2)";
regex regex_b (".."); ...
2
votes
0answers
151 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
1answer
66 views
Create palindrome by rearranging letters of a word
Inspired by a recent question that caught my interest, I wrote a function in Python 3.3 to rearrange the letters of a given string to create a (any!) palindrome:
Count the occurrences of each letter ...
2
votes
1answer
37 views
Scheme/Racket: idiomatic infix math evaluator
Inspired by xkcd and a couple of praising blog posts, I decided to try out Lisp. It seemed that the best-supported dialect was Racket, itself a variant of Scheme, so I went with that and wrote an ...
1
vote
1answer
51 views
Recursive Determinant
The following code I devised to compute a determinant:
module MatrixOps where
determinant :: (Num a, Fractional a) => [[a]] -> a
determinant [[x]] = x
determinant mat =
sum [s*x*(determinant ...
2
votes
3answers
145 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 ...
1
vote
0answers
68 views
Vaadin web application
I am creating a web application for an enterprise and I would like to improve my way of coding, know what I do wrong and what I do well. I'll leave the main class' code here:
package com.puntobile;
...
3
votes
1answer
280 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
vote
1answer
104 views
Playing Card Class - is this right?
The Art and Science of Java, a course book that uses the ACM library has an exercise that reads like this.
Implement a new class called Card that includes the following entries:
• Named ...
1
vote
1answer
117 views
Code review for an abstract repository implementation
I have a repository abstract class that encapsulates pretty much all of the CRUD functionality:
public abstract class DataRepository<T> : IRepository<T>
where T : class
{
public ...
1
vote
1answer
130 views
Which code is better? And why?
I found two ways of writing the same program (one that only uses local variables, but no methods other than the main one) and other that uses one instance variable that is used in two methods.
This ...
2
votes
2answers
113 views
How can I improve this coin flipping code?
I am doing exercises for the Art and Science of Java textbook. I had an exercise that required me to program the simulation of flipping a coin until 3 consecutive "Heads" result appeared.
I did it, ...
2
votes
1answer
99 views
What steps to turn python code into python zen code
My python code is ugly and I'm having difficulty improving it. What kind of steps could be done here to make it. This is an example function that comes from time to time and I can't seem to have a ...
0
votes
1answer
55 views
How to make proper code out of this function
public function getStuff($brand)
{
$web=FALSE;
if($this->getWebcorners()):
foreach ($this->getWebcorners() as $webcorner):
...
4
votes
1answer
152 views
How do I make this code unit-testable?
I have a functionality that imports data into a database, based on an Excel workbook and some meta data (both user-supplied). The functionality implements interface IFunctionality which essentially ...
0
votes
0answers
77 views
Hanoi Towers - need help with the code
I made an algorithm solving Hanoi Tower puzzles, for n disks and m pegs.
It uses lists as pegs, each list's element contains disks array - {0, 0, 0} means the peg is empty, {1, 2, 0} means the peg ...
1
vote
2answers
67 views
Looking for Python code review of database abstraction class
I'd be very thankful if some Python masters would take a look over the following class and review the code. There is no bug(not as far as I know anyway), the code is working as intended. But, since ...
0
votes
0answers
24 views
First time writing MIPS code and was hoping somebody could look at it and help me clean it up (Prime Factors)
The goal of this was to be able to enter any number and print out the prime factors of that number. Are there any shorter ways of writing this code? I'm not very familiar with low-level syntax and was ...
2
votes
2answers
248 views
Haskell markov text generator
I'm new to Haskell, and here is my first not-totally-trivial program. It's the first program I tend to write in any language -- a Markov text generator. I'm wondering what I can change to make it more ...
1
vote
0answers
51 views
Reviewing javascript and tidying up?
This is a follow up to this question my code has evolved since so I'm reposting my question, What is the best way to tidy this up? how can this be refined? I am finding it's thrasing the layout quite ...
2
votes
1answer
86 views
A complex string splitter- How do I make this working code better?
I have the below program
class Program
{
static void Main(string[] args)
{
List<Assembly> failedAssemblies = LoadAssembly();
string batchFile = ...
1
vote
2answers
135 views
How can I refactor this code in order to not repeat code?
I have this code:
private eFileStatus CheckConfigSettings()
{
mFileStatus = mXMLHelper.CheckElement(eElementName.StartLanguage.ToString(), out mContent);
if (eFileStatus.OK != ...
7
votes
2answers
233 views
What could I have done better?
This is my first real program, though it has gone through a few major revisions. Anyhow, I am sure that there is a lot I could have done better, cleaner or safer.
Can anyone see anything I really ...
3
votes
1answer
98 views
The eternal dilemma: bar.foo() or foo(bar)?
I was using foo(bar) as it's adopted for functional programming.
console.log(
join(
map(function(row){ return row.join(" "); },
tablify(
...
1
vote
3answers
93 views
Could I possibly shorten / clean this up
I'm new to Python, and I'm wondering how I could possibly shorten / clean this up?
def userAnswer(letters):
print("Can you make a word from these letters? "+str(letters)+" :")
x = ...
4
votes
3answers
138 views
Code Tidying up?
What is the best way to tidy up JavaScript code I have written. It seems very long winded, any suggestions to shorten it?
note: I'm running it on Wordpress which runs jQuery in nonconflict mode. ...
-1
votes
1answer
94 views
How to apply Sieve of Eratosthenes test into my code [closed]
I have this code that tests prime numbers and I'm trying to make it fast as possible. I know a way but I just can't find how to execute it in to my code. Does any one know how to input in to the code ...
2
votes
1answer
106 views
Simple and efficient code for finding factors and prime factorization?
I've modified this program many times, but I want to know if this is a good way to perform this task. My first algorithm for finding the factors of a number was pretty slow and horrible (started at ...
3
votes
2answers
134 views
Palindrome test in Haskell
I am new to Haskell and, coming from a OO/procedural programming background, I want to make sure my code follows the functional way of doing things. I built this short module to test if a given string ...
1
vote
1answer
101 views
General feedback for my GCD/LCM x86 Intel NASM assembly program
I've already created a similar program in C++ first, and then I decided to try to write it in x86 assembly language (the type of assembly I was taught in college). I've already completed the C++ ...
1
vote
3answers
91 views
Improving Javascript code of a failed test
I just failed in a JavaScript test and I would really appreciate some comments of how I can improve so I can keep learning.
The test was about making a form interactive, where the code should do ...
4
votes
2answers
69 views
Improving Code pointers
I'm new to jQuery and I've been messing about with this code, It works but I want to learn how to shorten the code by the eliminating unnecessary repeated code.
Below is a link to jsFiddle
...
1
vote
0answers
44 views
Hardware resource Open/Close methods
So I'm making a program that is a serial port wedge. In other words I want it to listen to a serial port. If data comes in, wait a given amount of time, then play a sound and finally send the data ...
3
votes
2answers
86 views
improve the design of class “accuracy” in Python
I am learning about the class and methods in Python.
The class Accuracy is a class of several (13 in total) statistic values between a reference polygon and one or more segmented polygons based on ...
3
votes
2answers
116 views
How can this this URL Checker be made cleaner?
I have a table full of URLs, some of which will occasionally become invalid. As part of a system I'm writing to go through the links periodically, and test if they are valid (or redirect to valid ...