26
votes
Accepted
Validating Credit Card Numbers
First of all, you should encapsulate your functionality in a function, unless you really want to use your code only once. At the moment you would have to duplicate your code somewhat just to check a ...
20
votes
Accepted
Financial website scraper
Here a few suggestions (in no particular order) for improvements on your code:
Make variables have locality
The line:
items = 1
is at the top of the method, ...
16
votes
Accepted
Selecting an enum for a payment transaction
You're using the wrong tool for the job.
If there's ever going to be a loan that I will pay an amount to every week for 2 years, you're gonna have to write a script to generate the code for you, ...
16
votes
Accepted
Basic Python OO bank account
Python doesn't have private anything but we still have a need to separate inners of a class from the public interface.
By convention, attributes or methods whose name starts with a single underscore ...
16
votes
Financial website scraper
In addition to what @StephenRauch wrote in his excellent answer, let me add one more comment:
Your class is completely useless. Not its functionality, which is fine, but it being a ...
14
votes
Basic Python OO bank account
In this answer I'm not going to review your code, but instead discuss the design of a book-keeping system. (I know that you're just using a bank account as an exercise, but an important part of ...
12
votes
Safely convert dollars to cents
I don't like the 3 argument return you're doing. You're using status and msg to actually do the same thing. They both return a ...
12
votes
Validating Credit Card Numbers
You can do most of this with regex. Going through your requirements:
It must only consist of digits (0-9).
And so we can use [0-9] for each digit.
It must ...
11
votes
Accepted
Simple budget program
Here are the few things I've noticed after a first glance on the program:
import os is not used, you can remove it
() after the ...
9
votes
Accepted
How to use PHP Visibility method?
Yes, the original code is awful. It is 200 lines of spaghetti code; I have no idea what it does, it is impossible to reuse and extremely difficult to test, debug, or change.
That doesn't necessarily ...
9
votes
Basic Python OO bank account
In Python you can have multiple functions and classes in a single file (module) but is it considered bad practice to do so?
You can write as many functions and classes within a Python module as ...
8
votes
Basic mortgage calculator
"math.h" should be <cmath>. The brackets are for system libraries whereas the quotes are for user-defined headers. The ....
8
votes
Accepted
Convert an amount to Indian Notation
1. Style guides
leave two empty lines before each function (when you're not inside of a class)
Python is not C; don't use ;
put a space before and after operands. <...
8
votes
Financial website scraper
You should also split the code in functional parts, and not mix the IO (print(...)) with generating the result
base_url
First you generate the base_url
...
8
votes
Bank Management System
I see a number of things that may help you improve your program.
Use the required #includes
The code uses std::find which ...
7
votes
Bitcoin trading system
In these screening situations, you only get a few seconds to make a good first impression. Unfortunately, this line already makes a bad impression:
...
7
votes
For a given balance and an annual interest rate, calculate the minimum fixed monthly payment to pay off debt in a year
This is a problem that can be solved exactly with a little math, so there should be no need to program a search.
Suppose that we borrow initial capital \$c\$ at a monthly interest rate \$r\$, paying ...
7
votes
Validating Credit Card Numbers
Your val_rep function can also be simplified with regular expressions by using backreferences (see the \number syntax). Here <...
6
votes
Basic mortgage calculator
Two things I noticed:
It's a good idea to give your variables meaningful names. On a small project this won't be a problem. On a large project when you have hundreds or even thousands of lines of ...
6
votes
Selecting an enum for a payment transaction
There is a better way indeed, which is to have the installments value as an attribute of each enumeration value.
An as example, we can simply consider 2 of those ...
6
votes
Accepted
For a given balance and an annual interest rate, calculate the minimum fixed monthly payment to pay off debt in a year
General comments
use a consistent style: space after a comma, or not; spaces around operators, or not; even two spaces sometimes. Python has an official style guide called PEP 8 which is worth a read,...
6
votes
Banking application for practice
It's not clear what TransactionReport is, but your class creates one and then doesn't do anything to or with it.
If the report is modified through public ...
6
votes
Banking application for practice
You already have a good answer from Scott (I'll add that I've never mocked anything in my life, but DependancyInversion and Injection are valuable design tools even when you ignore testing (which I am ...
5
votes
Calculating the interest on a series of loans
Do not represent monetary amounts as a decimal type; use an integer type instead.
Try to avoid the use of using namespace std.
You could still allow the user to ...
5
votes
Accepted
IRS Tax Calculator in Java
You are right, you over-complicated the code. My comments on it:
Avoid using static state (here's a good explanation on why).
Reuse code. If you start seeing that ...
5
votes
Accepted
App that calculates interest into a monthly payment
My honest opinion would be to make an interest calculator class, but we can work on a single function.
If you do not already have some input validation elsewhere, I would consider the use of Double....
5
votes
Validating Credit Card Numbers
You can massively simplify this by using regular expressions. Python includes an efficient module for that, named re (short for regular expressions).
In this case, ...
5
votes
Simple budget program
The while not x: loop can be replaced with a while True loop and you can break out of it using ...
5
votes
Simple budget program
DRY and Data Structures
Income and expenses are the same thing, just with different signs. You can cut about half your code by more fully leveraging this.
Currently, each of the two have a list of ...
5
votes
Accepted
Bank ATM machine in Ruby
This is my first review, so please bear with me. I'll start with atm.rb:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
finance × 263python × 66
java × 55
beginner × 42
c# × 31
c++ × 28
object-oriented × 23
calculator × 20
performance × 19
javascript × 16
python-3.x × 16
php × 16
validation × 16
homework × 14
sql × 11
algorithm × 10
pandas × 9
python-2.x × 8
ruby × 7
interview-questions × 7
c × 6
programming-challenge × 6
multithreading × 6
unit-testing × 6
web-scraping × 6