Looping over array values in Lua

The idiomatic way to iterate over an array is: for _, armyName in ipairs(armies) do doStuffWithArmyName(armyName) end Note that: Use ipairs over pairs for arrays If the key isn’t what you are interested, use _ as placeholder. If, for some reason, that _ placeholder still concerns you, make your own iterator. Programming in Lua provides … Read more

Which code is more readable?

I agree with the general consensus that the Foo() && Bar() form is reasonable unless it is the case that Bar() is useful for its side effects as well as its value. If it is the case that Bar() is useful for its side effects as well as it’s value, my first choice would be … Read more

Java try/catch performance, is it recommended to keep what is inside the try clause to a minimum?

Is it recommended to keep the lines inside the try catch to bare minimum? No. Can’t imagine how you could think that the length of a try block or indeed of any block can have any impact on performance. Does the code inside the try clause run slower or cause any performance hit?. No. As … Read more

Eigen: Coding style’s effect on performance

It looks like a problem of GCC. Intel compiler gives the expected result. $ g++ -I ~/program/include/eigen3 -std=c++11 -O3 a.cpp -o a && ./a test1_us: 200087 test2_us: 320033 test3_us: 44539 $ icpc -I ~/program/include/eigen3 -std=c++11 -O3 a.cpp -o a && ./a test1_us: 214537 test2_us: 23022 test3_us: 42099 Compared to the icpc version, gcc seems to … Read more

What’s the cleanest way to write a multiline string in JavaScript? [duplicate]

Almost identical to NickFitz’s answer: var str = [“” ,”line 1″ ,”line 2″ ,”line 3″ ].join(“”); // str will contain “line1line2line3” The difference, the code is slightly more maintainable because the lines can be re-ordered without regard to where the commas are. No syntax errors.

Why STL implementation is so unreadable? How C++ could have been improved here?

Implementations use names starting with an underscore followed by an uppercase letter or two underscores to avoid conflicts with user-defined macros. Such names are reserved in C++. For example, one could define a macro called Type and then #include <vector>. If vector implementations used Type as a template parameter name, it would break. However, one … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)