Hot answers tagged

10

Code Style Use the standard JavaDoc markup when writing comments. You will be able to generate documentation and it allows you to use ready made tools for documenting stuff like method parameters and related classes. Also people expect to see JavaDoc style comments and are used to reading them, so by rolling out your own style you're adding unnecessary ...


4

Let's go through the functions and see what can be improved. main The sorted_vector variable is not used. Remember to enable compiler warnings. You only test the quick_sort function. Consider testing other functions as well. bubble_sort The correct type to index a std::vector<int> is std::vector<int>::size_type. std::size_t (defined in ...


3

In addition to the valuable answer already given: use JavaDoc for comments describing method/class do not use float or double for monetary values (calculation inaccuracies!) use existing collection implementations of Java, as ArrayList or at least wrap them learn the advantages of Single Responsibility Principle (SRP) Here some improvements on modelling ...


3

Thank you for not using using namespace std;. Enclosing all blocks of code in {} is a good practice that I promote, so thank you for that good practice as well. In C and C++ you don't really need that large block of function declarations at the top if all the functions are in the proper order, but in some cases this is a matter of style, in other cases if ...


2

Be explicit about the data structure you're using, and the assumptions. For example, a comment like this would be helpful for any future readers(including yourself): "We represent a graph as adjacency list stored in a Python dictionary. The adjacency list can contain nodes that are not present in the keys of the dictionary, and they should be treated as ...


2

Multi-statement lines This: stack = []; result = [] lowlinks = {}; index = {} # ... if successor == node: break is generally discouraged; just use two lines. snake_case This: lowlinks is usually spelled out, i.e. low_links. Bare except try: successors = graph[node] except: successors = [] has an except statement that's too ...


2

Just like you I am also learning algorithms mostly in python, that I am also using to learn haskell. I am fighting myself not to change variable names to long but readable ones! Here it use not using any folding or anything, just recursion. bubbleSort :: (Ord a) => [a] -> [a] bubbleSort [x] = [x] bubbleSort (x:y:xs) | x < y = x : bubbleSort (y:...


2

In addition to the recommendations by @J_H, you can simplify the function somewhat. Since I only want the indexes, my function returns the index number, or -1 if there is no nearest value in a given direction. # Find nearest number in array and return index def find_nearest(array, number, direction=None): idx = -1 if array.empty: return idx ...


1

Over the years I have seen other students here and they are quite proud of the performance of their code. In some of those past instances I have discovered that they had simply run their code and thought it was fast. They did not compare it to other methods. You don't mention any testing or provide any numbers. If you were to do this, just be sure that (...


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