101 reputation
3
bio website
location
age 24
visits member for 3 years, 7 months
seen Jun 30 at 14:07

I'm a science fiction & fantasy buff and casual tabletop gamer, recently graduated with bachelor's degrees in Computer Engineering and Computer Science (and a Japanese minor on the side).

Python and C++ are currently my preferred programming languages, but I've done some work with Objective-C (iOS apps) and some projects in Javascript (node.js, jQuery, etc.). I have possibly had more experience with Java than with Python or C++, but I have found that tasks that are comparatively elegant in Python and other languages that share similar design concepts (first-class functions, etc.) often require an annoying amount of boilerplate in Java (thankfully, Java 8's lambdas and method references seem like they'll alleviate a decent amount of my annoyances in that regard); I also wish Java had either reified generics or at least a bit more support for static/compile-time code generation like with C++'s templates (at the very least, method overriding based on runtime type would allow a whole lot of Java code that interfaces with non-generic/primitives-only APIs to be less verbose). I'm also trying out Scala and LISP, though I haven't made much progress on that recently.


Sep
24
awarded  Autobiographer
Jun
23
comment Is it an antipattern, modifying an incoming parameter?
@Phoshi Does that apply to all JVMs, or just HotSpot? Because while HotSpot is probably the most common JVM, it's definitely not the only one in use. (In other words, does the same optimization apply to, say, Dalvik, the VM used on Android devices?)
Jun
23
comment Is it an antipattern, modifying an incoming parameter?
@CsBalazsHungary I believe the issues when object creation is a concern tend to be related to memory allocations and garbage collection, which would probably be the next level of bottlenecks following algorithmic complexity (especially in a limited-memory environment, e.g. smartphones and the like).
Jun
11
comment How to name a method that both performs a task and returns a boolean as a status?
(The main usage for that would be interfacing with some other language that isn't as strictly typed as Java and relies heavily on, say, passing messages as strings for one reason or another.)
Jun
11
comment How to name a method that both performs a task and returns a boolean as a status?
@maaartinus And how would you handle a situation where the exception only has meaning within the method itself, and externally you only care whether or not the procedure succeeded but not about the specifics (assuming the wrapped exceptions are specific to the procedure and not generalized)? For example, with Java reflection, there's no method that checks for the existence of a method on a class, only methods to retrieve a Method object or throw an exception when the requested method does not exist (you could retrieve the list of methods for the class and search that, but it's not one call).
May
20
comment Where did the notion of “one return only” come from?
@user61852 A 100 lines method with deep nested conditions should probably be refactored to begin with.
May
12
comment Should I use initializer blocks in Java?
@dirkk That's true enough, though it's caused by class variables in Java being assigned default values (numerics -> 0, references -> null, etc.) and you'll have the same issue with such assignments in the body of a constructor. Using final for class variables will give you errors if your initializer blocks are out of order, so if you're that worried about it you can just use them for initializing finals as given in the answers. Personally I don't see much use for more than one initializer block anyway, so I only worry about order within the one block when I do use them.
May
12
comment Should I use initializer blocks in Java?
@dirkk Class variable declarations are order-independent, but class variable definitions are not. int x = y + 1; int y = 2; will cause an error when placed in the body of a class ("Cannot reference a field before it is defined"). And while the scattering can be an issue, that's not limited to order-dependent code. Unless you're using a code outliner and some form of quick-linking, determining what code is actually executed in a set of method calls can be difficult when all the methods are scattered throughout the class in an arbitrary manner.
May
12
comment Should I use initializer blocks in Java?
"[S]imply changing the order of code blocks will actually change the code." And how is that any different from changing the ordering of variable initializers or individual lines of code? If there are no dependencies, then no harm occurs, and if there are dependencies, then placing the dependencies out of order is the same as misordering dependencies for individual lines of code. Just because Java lets you refer to methods and classes before they are defined does not mean that order-dependent code is rare in Java.
Mar
10
comment Why are string resources generally kept external to the code and not inside the code?
This question can be generalized to any sort of resource, really, even with ease of localization/internationalization aside. What are the advantages of keeping any sort of resource separate from code? Why aren't images or audio files usually encoded in the source as binary strings? (Data URIs do exist, of course, but are generally impractical for large files). Others have provided some pretty good answers already, but I just wanted to point out that user-readable strings aren't the only resource type that gains a benefit from being externalized.
Mar
6
comment Should I refactor large functions that mostly consist of one regex?
I'd say named capture groups (capture groups in general, really) are most similar to final/write-once variables, or perhaps macros. They allow you to reference specific portions of the match, either from the match object returned from the regex processor or later in the regular expression itself.
Mar
5
comment Why do all <algorithm> functions take only ranges, not containers?
@delnan Saying that Python iterators "don't have most of the power" talked about is a misleading statement. The power of Python iterators lies in their integration with the language, which includes constructs for easy construction of simple to complex iterators (the most powerful of which would probably be generators and generator expressions, though the standard library's itertools module provides a lot of nice convenience functions for common composition patterns too). (This applies to plenty of other languages with similar design principles, of course. diff. iterators != weaker iterators)
Feb
25
comment How to write camel case for words like “phonenumber”, “motorcycle”, “wavelength”, etc
@PeterTurner Some programmers would say that street should be a class and name one of its attributes/data members.
Feb
14
comment What is the benefit of having the assignment operator return a value?
Also note the following: round(2**128 / 2.0) + 1 == round(2**128 / 2) + 1 == round(2**128 // 2.0) + 1 == 2**127 + 1, because the result of the float division is close enough to the correct result to be rounded (though to add more potential confusion, type(round(float_value)) == int while type(round(float_value), 0) == float).
Feb
14
comment What is the benefit of having the assignment operator return a value?
@wberry C also produces an FP result when using division involving a float; a better example of conversion confusion would be the fact that, in Python 3, 2**128 / 2 + 1 != 2**127 + 1 as / always produces a float, but the behavior of // is inconsistent with that as while it acts as as an integer division operator when applied to ints it is a floor-division operator when applied to floats, so 2**128 // 2 + 1 == 2**127 + 1 but 2**128 // 2.0 + 1 != 2**127 + 1. (The behavior of // actually does make sense after a bit of thought, though.)
Feb
14
comment What is the benefit of having the assignment operator return a value?
@wberry However, 2 == 2.0 does return true even though int and float are different types in Python. If anything, JavaScript's === is closest in equivalence to Python's is (you achieve similar loose equality effects with == by adding an __eq__ method to Python classes, it's just that strings and numbers in Python don't have implicit conversion built in; many object-oriented languages that don't support operator overloading usually have an explicit function pattern for that, like Java's Object.equals). (Apparently the recent Object.is seems to act even more like Python's is.)
Jan
30
comment 'import module' vs. 'from module import function'
There is also the situation where you have a package with subpackages or modules that exposes an attribute of one of those subpackages/modules in the top level package. Using from...import allows you to do package.attribute rather than package.subpackage_or_module.attribute, which can be useful if you have logical or conceptual groupings within the package but want to make things a bit more convenient for users of your package. (numpy does something like this, I believe.)
Jan
30
comment Is it acceptable to use lambda functions\methods in business software?
"In the second case, you have to know that doSomething takes an Action." And how is that any different from having to know that functionWithNameThatDoesNotSpecifyItsArgumentTypes takes an ObjectOfSomeType? In fact, in languages where functions are true first-class objects, it isn't any different.
Jan
28
comment Is it a bad idea to return different data types from a single function in a dynamically typed language?
@Aaronaught Relevantly, 1/0 appears to result in Infinity rather than a divide-by-zero error in Firefox's JavaScript implementation (I haven't tested with other browsers). (Versus Python, where any integer/float combination for 1/0 results in a divide-by-zero error.)
Jan
10
comment What is meant by “Now you have two problems”?
This makes me wonder how many people took the floating-point course versus the finite automata one at my university, where you only need one of the two for a CS degree. (I went for automata, though if I'd had time I would have tried to fit in the FP course as well.)