Reputation
Top tag
Next privilege 125 Rep.
Vote down
Badges
4
Newest
 Scholar
Impact
~36 people reached

  • 0 posts edited
  • 0 helpful flags
  • 53 votes cast
Feb
16
awarded  Scholar
Feb
16
comment Usage of “bugfix” to refer to UI changes in branch names
Thanks for the input.
Feb
16
accepted Usage of “bugfix” to refer to UI changes in branch names
Feb
13
asked Usage of “bugfix” to refer to UI changes in branch names
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.)