Top tag
Next privilege 2,000 Rep.
Edit questions and answers
8 16
~90k people reached

comment Why not have a High Level Language based OS? Are Low Level Languages more efficient?
@JörgWMittag - I agree that any language can be compiled or interpreted (compile a bash script; use interpreted C++ (CINT/Cling)), but many decisions in language design are based on will this be interpreted, compiled, or both. A language that makes you manually declare/initialize statically-typed variables, manually allocate/free memory, do pointer arithmetic, remember to check array bounds will be less convenient in an interpreter (versus a language that garbage-collects memory, infers dynamic type, checks array bounds). Is this line 100% clear? No, but the difference exists in practice.
comment Is every number in the code considered a “magic number”?
@RossPatterson - This is not C where we constantly compare against a global var MAX_ARRAY_SIZE, but a decent web framework. The only place that the magic number comes up is where you declare the database model; everything else is compared against this value (e.g., 40 appears nowhere else in the code). Also note, you can't change this variable easily without doing schema migrations as its tied to a DB. If I wanted to change to say 1 character middle names its immediately obvious the one place to change in the code 40 to 1. You have to think of context.
comment How does learning assembly aid in programming?
@StriplingWarrior - that seems more for learning about how compilers work to optimize your code than learning assembly. E.g., you could learn assembly and end up writing much slower code than if you wrote straightforward C that your compiler was able to better optimize your code than you and there also are the rare cases where assembly will be faster as you can't access the specific assembly calls you need in C.
comment Which hashing algorithm is best for uniqueness and speed?
For random input and an ideal hashing function, you expect 5.5 collisions with N=216553 and a 32-bit word size (d=2^32) by N-d-d*((d-1)/d)^N. The probability of no collisions in this ideal case is p ≃ ((d-1)/d)^(N*(N-1)/2) ≃ 0.00426 (0.426%). Sheer luck that CRC32 had low collisions. So when collisions aren't significantly above 5.5 and input is sufficiently random, only speed matters. (For consecutive integers; low collisions are desired).
comment Is it bad practice to name an unused variable with a single underscore?
Also, using _ for dummy variables in python will clash with _ for last returned value. E.g., in the interpreter, if you do 5*5 on line 1; then on line 2 _ will have the value 25. However if you then set x,_ = (3,'not used'), you will find that _ is now not used instead of the last returned value until you del _. You probably shouldn't be using _ for last returned value in real code; but its often handy in the interpreter when trying new stuff out.
comment Completion time on a company where the supervisors don't know programming
It's also reasonable to give a generous initial estimate due to Hofstadter's law: It always takes longer than you expect, even when you take into account Hofstdter's Law. If you finish early, great, there's always the next project/feature. If you finish late, you will have untold levels of stress and misery.
comment Is a company order to switch to a certain IDE a red flag?
Depends on what "without discussion" means. If the head boss just decided all devs must use eclipse, no exceptions for no reason and the devs are upset, that seems like a red flag. If a policy was set for standardization (saying we won't pay for VisualStudio, etc) don't want to maintain instructions for how to set up build environments for other IDEs, or it resolves other issues (have eclipse in multiple VMs for testing), that's great. I wouldn't start applying elsewhere over this trivial issue -- but if the 4-12 devs are upset at arbitrary orders coming from above, talk to your boss.
comment Best Version Control Habits For Solo Developer?
I did look at Version control for independent developers? (among other questions), but my question wasn't whether to use VCS or not as a solo dev; but what kind of habits are typical/best practice. (Most questions/guides for distributed VCS start from the perspective of multiple devs working on a project where I see bigger need to branch & commit often.)
comment Best Version Control Habits For Solo Developer?
"what if your computer crashes" - files are saved to disk quite frequently and backups made nightly (if you meant if the hard disk breaks). However +1 for the binary search for bugs could come in handy. I'm pretty good at quickly finding 95% of my bugs; but every now and then there is the truly bizarre bug arising from a seemingly inconsequential change in another part of the program.
comment Form screenshot for legal proof of clicking one of the checkboxes?
Exactly. Verification email to ensure that the person requesting the emails has control of the email address in question. I'd also add that rather than having a legal record of people requested promotional materials, that you are just compliant with the CAN SPAM Act and make it very easy to unsubscribe to your promotional material. (Every email that sends promotional material even if its by a third party has a link to unsubscribe to all the lists you put them on.)
comment How can I inspire engineers to positively conduct telephone interviews
@maple_shaft - Agree, Future_proof's SO profile says he's from India. A key may be to get a set of engineers to come up with a set of 1000 simple weed-out questions, so HR can pre-screen candidates. "Your resume says you know C++, say you have a class called Shape, how would you declare the constructor; how would Triangle inherit from Shape". I'd also mention there's a similar pre-screening test when they come in for the actual interview. Also count interview time as equal to a billable hour.
comment Is there a term used when internal variables are declared public and accessible?
@SLott - I do not think we disagree. Public means poor encapsulation only if the variable should be accessed by a class's functions (e.g., getters and setters are keeping something invariant). In python you should use the private access specifier by the _ or __ prefix in the name for encapsulation. If your code frequently uses internal variables marked private when better alternatives exist, that's poor encapsulation. I do agree that's its a waste to write trivial getters/setters for every member variable when they aren't needed (no side effects from accessing/modifying).
comment Is there a term used when internal variables are declared public and accessible?
@S Lott ; Oded - Encapsulation is good and relying on code where private variables are frequently directly accessed from other classes is poor encapsulation. In python, you do this by accessing name-mangled private variables of another class or ignoring conventions of a single underscore prefix (though if your getter is doing other behavior; really should use __ for name mangling). Other languages can have poor encapsulation too, e.g., reflection in Java and pointer arithmetic in C++ to get at private variables. Python just doesn't make the syntax to do it that cumbersome.
comment Why do iterators in Python raise an exception?
@Yam: I agree. Its not pythonic to take an existing sequence and convert it into an iterator just to apply a for loop to it; the sequence is already an iterable, so the conversion of a list to a listiterator is pointless. I kept the first line only to follow NullUserException's starting point, to explain how you should loop over an iterator, which is the same way you should loop over any iterable (list, set, str, tuple, dict, file, generator, etc.). I could have done something like it = itertools.combinations("ABCDE", 2) to get a better example of a meaningful iterator.
comment Is it true that once you learn one language most of the rest come easy?
@gd1: Haskell is a lazy language, python is not. (Sure you can do some lazy evaluation with generators/itertools in python, but I wouldn't say that's the default paradigm).
comment Do the young minds need to learn the pointer concepts?
Nowadays you need to know just the basic concept of references, not pointer syntax/math. I learned pointers (with arithmetic&syntax) in C back in the day. The languages I now program in don't deal with C-style pointers that let you do unsafe things. One can understand why in python a=[1,2]; b=a; a.append(3) that both a and b are going to both reference the same object [1,2,3] without knowing stuff like in C the ith element of an array can be referenced by arr[i] or i[arr] as both are *(arr+i). I prefer when the language doesn't let i[arr] be used.
comment Should developers accept overtime/weekend work/denied bonus payments?
I wouldn't say never. There are at least two reasons for it. (1) you are just an employee, but a very well compensated employee (above ~$200k) and were hired with the expectation that you will work extraordinary hours and be the person everyone can rely on. (2) On rare occasions, your work is needed off-hours and not doing the work ASAP will lose money/business for the company that can't afford to lose it. E.g., you're at a startup and a major security hole was found after release that needs to be fixed ASAP--that's not the time to try saying you'll only work for $500/weekend day.
comment Is micro-optimisation important when coding?
Sure, you should consider it (in the back of your head) and typically reject it, unless its shown to be worth it. You need to consider that optimizations usually lower code readability and can increase the time taken to code and maintain by a factor of 10 or so. If the program isn't CPU intensive, its often not needed. Recognize that your compiler is usually much better at optimizing than you are, and that many of your optimizations will actually hurt performance. If its not worth your time to test your optimizations and profile, its not worth your time to optimize.
comment My Dad is impatient with the pace of my learning to program. What do I do?
Agree, python's a better choice as a first language. C++ is great but its very powerful and difficult to use--its like learning to fly a plane before learning to walk. With python you can use libraries right off the bat and do fun things. Your string_add function is 5 lines of readable code. E.g., def string_add(a_string): \n\t sum = 0 \n\t for letter in a_string:\n\t\t sum += ord(letter) - ord('a')+1 \n\t return sum (the \n - new line \t -tab) or using more advanced functional programming its a one liner. string_add = lambda a_string: sum(map(lambda ch: ord(ch)-ord('a')+1, a_string))
comment Why do people use programming books?
Having a book as a reference is very useful--you gain from the experience of others. The "book" could even be extensive online documentation/tutorials like django or jquery. But trial & error + reading source alone will leave major gaps in your knowledge. Now if you only need a few lines of jQuery, your method works but you didn't learn the language. But if you want to learn C, I'd recommend having K&R as a reference. Sure most info is online somewhere, but scattered throughout many blog posts.