Managing highly repetitive code and documentation in Java

For people that absolutely need performance, boxing and unboxing and generified collections and whatnot are big no-no’s. The same problem happens in performance computing where you need the same complex to work both for float and double (say some of the method shown in Goldberd’s “What every computer scientist should know about floating-point numbers” paper). … Read more

How would you do the equivalent of preprocessor directives in Python?

There’s __debug__, which is a special value that the compiler does preprocess. if __debug__: print “If this prints, you’re not running python -O.” else: print “If this prints, you are running python -O!” __debug__ will be replaced with a constant 0 or 1 by the compiler, and the optimizer will remove any if 0: lines … Read more

#define in Java

No, because there’s no precompiler. However, in your case you could achieve the same thing as follows: class MyClass { private static final int PROTEINS = 0; … MyArray[] foo = new MyArray[PROTEINS]; } The compiler will notice that PROTEINS can never, ever change and so will inline it, which is more or less what … Read more

Xcode 4 can’t locate public header files from static library dependency

Each of the solutions I’ve seen to this problem have either seemed inelegant (copying headers into the application’s project) or overly simplified to the point that they only work in trivial situations. The short answer Add the following path to your User Header Search Paths “$(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts” Why does this work? First, we need to understand … Read more

How to check release / debug builds using cfg in Rust?

You can use debug_assertions as the appropriate configuration flag. It works with both #[cfg(…)] attributes and the cfg! macro: #[cfg(debug_assertions)] fn example() { println!(“Debugging enabled”); } #[cfg(not(debug_assertions))] fn example() { println!(“Debugging disabled”); } fn main() { if cfg!(debug_assertions) { println!(“Debugging enabled”); } else { println!(“Debugging disabled”); } #[cfg(debug_assertions)] println!(“Debugging enabled”); #[cfg(not(debug_assertions))] println!(“Debugging disabled”); example(); } … Read more

Swift: how to use PREPROCESSOR Flags (like `#if DEBUG`) to implement API keys?

Apple included full support for Swift preprocessor flags as of Xcode 8, so it’s no longer necessary to set these values in “Other Swift Flags”. The new setting is called “Active Compilation Conditions”, which provides top-level support for the Swift equivalent of preprocessor flags. You use it in exactly the same way as you would … Read more

How to convert an enum type variable to a string?

The naive solution, of course, is to write a function for each enumeration that performs the conversion to string: enum OS_type { Linux, Apple, Windows }; inline const char* ToString(OS_type v) { switch (v) { case Linux: return “Linux”; case Apple: return “Apple”; case Windows: return “Windows”; default: return “[Unknown OS_type]”; } } This, however, … Read more

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