Is using the directory separator constant necessary?

As far as PHP is concerned, you might not need it when constructing a path, but it is important for anything you get from the OS. From http://alanhogan.com/tips/php/directory-separator-not-necessary: In attempting to write cross-platform, portable PHP code, I used PHP’s DIRECTORY_SEPARATOR constant to write path strings, e.g. “..”.DIRECTORY_SEPARATOR.”foo”, because the “proper” way to do it on …

Read more

Shortest distance between two line segments

This is my solution in Python. Works with 3d points and you can simplify for 2d. import numpy as np def closestDistanceBetweenLines(a0,a1,b0,b1,clampAll=False,clampA0=False,clampA1=False,clampB0=False,clampB1=False): ”’ Given two lines defined by numpy.array pairs (a0,a1,b0,b1) Return the closest points on each segment and their distance ”’ # If clampAll=True, set all clamps to True if clampAll: clampA0=True clampA1=True clampB0=True …

Read more

What is the difference between message-passing and method-invocation?

Using Objective-C as an example of messages and Java for methods, the major difference is that when you pass messages, the Object decides how it wants to handle that message (usually results in an instance method in the Object being called). In Java however, method invocation is a more static thing, because you must have …

Read more

What are magic numbers and why do some consider them bad? [closed]

A magic number is a direct usage of a number in the code. For example, if you have (in Java): public class Foo { public void setPassword(String password) { // don’t do this if (password.length() > 7) { throw new InvalidArgumentException(“password”); } } } This should be refactored to: public class Foo { public static …

Read more

Why would a language NOT use Short-circuit evaluation?

Reasons NOT to use short-circuit evaluation: Because it will behave differently and produce different results if your functions, property Gets or operator methods have side-effects. And this may conflict with: A) Language Standards, B) previous versions of your language, or C) the default assumptions of your languages typical users. These are the reasons that VB …

Read more