Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

# Tag Info

23

Your mathematical criterion for equality has some issues. One important point to consider is that your "equality" is not transitive. In your code, you use a threshold of $\epsilon$ ($\epsilon = 5\times10^{-16}$ in your code, when the values have type double); you declare $x$ and $y$ to be equal to each other if $|x-y|\leq \epsilon$. Now suppose ...

21

... as I went through others, there is always this voice in head, which says: "Oh, this is a lot of code and functionality. Is that really necessary or would it slow down the performance?" This is a reasonable consideration, but premature optimisation is evil for a reason. It might be a good idea to try to roll out your own solution, but it would be ...

21

IOutput class module (Interface) Looking at how the interface is being used: this.Parent.OutStream.PrintLine output Where output is clearly a String, which makes sense. But the interface's signature doesn't reflect that, and is confusing: Public Sub PrintLine(Optional ByVal object As Variant) Why is the parameter optional? and why is it a Variant? ......

19

I've spent about 20 minutes reading your code and I've identified several issues. Relative paths private function load_template($controllerName,$jQuery = null){ $page_title =$controllerName->get('title') ? $controllerName->get('title') : App::get('DEFAULT_TITLE'); //display output$cwd = dirname(__FILE__); $template_file =$cwd.'/.....

19

Compared to Python's NumPy, my matrix multiplication is quite a bit slower. Can it be made faster without using sophisticated matrix multiplication algorithms like Strassen's? One issue is that you use a vector of vectors - your memory accesses aren't going to be as contiguous. Typically one represents a matrix as a single really long vector, and then ...

17

template <typename Less, typename T, typename... Ts> constexpr const T& min(Less less, const T& a, const T& b, const Ts&... rems) { This function requires a minimum of 2 elements. A minimum element will exist if the user provides a single argument variadic list. Consider handling that. auto& min1 = min(std::less<>{}, 4, 5); ...

16

Use use of a "state" to distinguish between different output formats is very wrong. If you need different formats, use multiple output methods (have toString just for debug output), or even better, write a separate class for converting Points to a string representation. I think you have overdone it with the JavaDoc. IMHO it's neither the place for ...

16

Let me collect a couple of thoughts here. Aggregate initialization currently works like this: array2d<int, 2, 2> a{{1, 2, 3, 4}}; but wouldn't it be favorable to allow for array2d<int, 2, 2> a{{1, 2}, {3, 4}}; std::array::at performs bound checking and throws upon an out of bounds index. When your intention is to stick with the std::array ...

14

I'll take a swing at this: 2) Unified function name based on overloads: ... Also it would be nice to end up with a universal set of functions that select the most efficient method based on input parameter without having a suffix to select between them: ... I am pretty sure that's not completely achievable due to ambiguity. The question is what ...

14

Unless you wish to optimize the code, with specialized swappers for various hosts orders, you are doing it wrong. I invite you to check The Byte Order Fallacy by Rob Pike. The punch line: the byte order of the computer you are executing the code on doesn't matter, because the language abstracts it for you. Thus, only the byte order of the network matters, ...

13

What you did well As far as I can tell, the code produces correct output when given correct input. The functions feel like a coherent library, with consistent function names and logical order of parameters. You use a caller-owns-everything memory management policy, which works well for C. What you could improve on The name json_initJsonParser() is a bit ...

13

1. Why static ? I have a minor issue with the following: private static void initPolar(Point point) { Why do you define a static function when the argument is an instance of a Point and thus could be a method? private void initPolar() { double angle = getAngleRadians(); x = getRadius() * cos(angle); y = getRadius() * sin(angle); } 2. Do ...

13

I don't like the idea of using an all-in-one struct. You will have to do more maintenance: every time you create a function that returns different values, you have to create a new struct. Further, I think the struct return value will confuse the user. Everyone is familiar with the basic types, so they will immediately know how to use a function just from it'...

13

Is it appropriate to require the user to specify argument names with *? Yes! I think this is excellent practice, and in my opinion a far underused feature of Python 3. It greatly enhances the readability of your function when called. Reading just the invocation of play_game() in your simple example, I can immediately work out what all of the arguments mean....

12

Look what I found Dim procedureName As String, lastFound As String Dim procedureBody As String Personally I don't like declaring variables like this, and almost every language allows you to do this in some way or another. I think this is one of those holy war issues though, some programmers like doing this and some programmers say this is bad practice. ...

12

This looks nice! Two issues I see here, When compiling your template with clang, it refuses the if constexpr dispatch for every recursive instantiation with sizeof...(rems) > 1, e.g. error: constexpr if condition evaluates to 2, which cannot be narrowed to type bool [-Wc++11-narrowing] gcc seems to accept this, but the fix is quite simple, just be ...

11

Disclaimer: I am no security guru. So a lot of what I say in regards to security are assumptions. The code review is good, but you should get a second, third, maybe even fourth opinion on my suggestions regarding security. I will denote each "opinion" that way you know to take it with a grain of salt. That being said, on to the review! Session Variables ...

11

I think the code looks pretty tidy. Not sure if you can get a huge speed up - you are effectively tokenizing a string by storing the meta data of the tokens (start/end positions and type). This alleviates the pain of having to copy the data and dealing with the associated memory allocation issue. A few remarks: You could consider changing the token to ...

10

Some words at beginning: I have never used OSGI, so I can't say if the tips below may all work in your context. If they do not, than keep them in the back of your head and use them when you can. One of the most important rules is to avoid mutable state if possible. This will result in more type-safe and easier to read code. This is not always possible but ...

10

The Math.atan2 function is defined rather strangely (not only in Java, but in every programming language I know) and the correct use is atan2(y, x).

10

Design I think you need to break that class in two. Having instance members on a static class is pretty confusing and bug-prone. I'd suggest Enumerable to be the static class, with these members (notice source being preferred over collectionObject, and explicit ByRef modifiers and Variant types): Function Contains(ByRef source As Variant, ByVal value As ...

10

I'm glad to see I'm not the only one who finds "interfaces" in JavaScript useful. Yes, the language doesn't support interfaces, but there is value in defining them anyway if you expect third party code to integrate with it. Interfaces in JavaScript There is no official vehicle for defining interfaces in JavaScript. That being said, when someone sees a ...

10

public S isIn(Range range) This method looks strange to me, because of 2 points It is violating SRP because it is checking if parameter is in range and composing the exception message The composing of the exception message. So let us take a look at message composition, which we can extract to a separate method to solve point one also. private ...

10

I like that the library provides syntactic sugar to make code easy to read in English. Chaining is a nice design. IllegalArgumentException is a non-final class, and by subclassing it, you could probably do better than encoding the validation errors into the message string. I would hope that StringPreconditions.isNotEmpty() also checks that the string is ...

10

Standard doesn't specify the signedness of char. The line swap_table[(int) table[i]] = deletechars[i]; fails on a default-signed-char architecture (table[i] is promoted to negative value). Make it unsigned char * table. Functions which should not be called directly should not be exposed to the client. Make them static. translate_no_table Counting found ...

10

Do you really need a new implementation for floating-point numbers comparison? java.math.BigDecimal may be useful for FP numbers comparison with its compareTo(arg) method. areEqual(args...) overloading seems too repetitive. You may consider redefining them using generics in a single method. An example with minor changes in the original code: public static &...

10

It would be nice to be able to pass an IComparer<TKey> instead of having to make sure TKey implements IComparable<>. It could default to Comparer<TKey>.Default. This provides you with a lot more flexibility in terms of which types can be used as keys. Get can return null . So if you try to access a non-existing key you will get a ...

10

for loops in C++ In C++ you can declare the loop variable in the statement instead, like this: for (long a = 0; a < cols; ++a) { res.M[0][0] += M[0][a] * right.M[a][0]; } This is a very nice feature, because the variable a in this example only exists in the scope of the loop, so it cannot be accidentally misused outside of the loop. So if you only ...

10

Please be consistent: public static double addfunc(double num1, double num2) { return (num1 + num2); } public static double mulfunc(double num1, double num2) { return num1*num2; } In one method, you use parenthesis around the expression, and in another, you don't. In one method, you use spaces around the operator; in the other, you don't. These ...

10

Headers and namespaces The function is missing a definition of map. This is probably what you want: #include <map> using std::map; Similarly, the main() needs: #include <iostream> using std::cout; using std::endl; That said, there's no good reason for std::endl in this code: an ordinary newline is sufficient, and we don't need the extra ...

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