Slashdot is powered by your submissions, so send in your scoop


Forgot your password?

Comment Construct objects and compare them (Score 1) 536

Another way to do it, supported by both existing static languages such as C++ and existing dynamic languages such as Python, involves constructing objects using factory functions and then using the language's facility for making objects comparable. Comparison expressions might look like intval($a) > intval($b) or strtotime($a) > strtotime($b).

Comment Not caring whether null or empty (Score 1) 536

I read "check to see if the string is null or empty" as meaning "I don't care which". In practice, I've seen more uses for "I don't care which" than for distinguishing null from empty. In fact, a lot of cases call for not only treating null like the empty string but also disregarding leading and trailing spaces, and that's why I often end up using trim($some_string) in PHP or (some_string or '').strip() in Python.

Comment Imposition of will through taxation (Score 1) 1330

However, I *also* think that it is ethically bankrupt for me to impose my will on the mother.

Funding abortions with tax revenue likewise imposes pro-choice advocates' will on taxpayers. Thus it is ethically bankrupt to require employers to pay for abortifacient means of birth control if they already pay for other, non-abortifacient means. And as I understand it, Hobby Lobby was paying for condoms, diaphragms, the pill, the patch, vasectomies, and more.

Comment Re:Fractal rant makes about six good points (Score 1) 536

I haven't tried every dynamically typed language out there, but I have tried Python, and it doesn't share a lot of PHP's faults.

What's an example of a (default) dynamic language doing comparing right?

Python at least doesn't aggressively try to convert strings that look like numbers to numbers to compare them numerically.

What's an example of an existing language with decently named library parts?

Python adopted PEP 8 fairly early on.

"Versions change semantics": That's another trade-off in improving the language versus backward compatibility. I'm not sure I'd classify that as summarily "bad".

Python allows each module to specify its own semantic versioning either with new syntax (such as with or new-style classes) or, when old syntax would get new semantics, with from __future__ statements.

Comment Generator expressions (Score 1) 536

The naming convention makes reading code a lot more readable


With a try/catch you can catch every failure, not just one per line, with a single handler.

And with returning false, you can handle failures even within a generator expression. In Python, statements can do things that expressions cannot, and one of these things is try. This means if you include a function call that may raise an exception in a generator expression, you need to make and name a separate function that tries the call and translates the exception to a sentinel value indicating that a particular call in the list failed. If you're using the warning-to-ErrorException snippet from PHP's manual, then @expression behaves as if there were an inline try/catch: exceptions when you want them, nulls when you don't.

Point me to a rebuttal that is more than essentially "You're right, but it's fine and everyone else should be totally okay with it broken this way" and maybe I'll change my mind.

I wasn't trying to change anyone's mind about PHP being broken. I was only trying to point out that not everybody agrees that PHP is as broken as "fractal" rant author believes it is.

Comment Re:Fractal rant makes about six good points (Score 1) 536

How does the presence of "C and Python crash fatally, potentially destroying the memory space of other programs. Got it." invalidate the whole rebuttal? Even if it isn't sarcasm, when programs hit undefined behavior, they can scribble on other programs running in the same process space, such as if your web app is loaded as a module instead of a CGI program. Granted, this is harder to do in Python without using native code interfaces like ctypes.

Comment Take Python, for example (Score 1) 536

After writing tons of Java code that [checks a string variable for both null and equality to the empty string]

Not all implicit conversions introduce problems. Casting to a Boolean type, as the if statement does, is fine with the caveat that which values are considered "truthy" or "falsey" depends on the language. For example, PHP's ordinary bool cast rules are pretty much the same as Python's, except that the string "0" is falsey in PHP but truthy in Python. C and Java have their own definition: a nonzero primitive or a nonnull pointer is truthy. I find these implicit conversions, as well as some language-specific rule for implicit conversion to the language's string type, to make sense in general.

The practical problem with how PHP handles comparisons comes when it performs implicit conversions that make little sense. Strings more often than not end up converted to numbers before they're compared.

For the parse errors, you mean you don't do precommit hooks to do php -l to validate your checkins and don't have continuous integration setup?

You are correct that a lot of people do not. For one thing, they may lack the money to lease both a testing environment and a production environment from the hosting provider. Or they may lack access to server logs because the hosting provider doesn't provide server logs to customers on plans below the VPS tier.

For the undefined functions, if you're doing OOP, the language has had great support for autoloading classes for over a decade

Autoload failures caused fatal errors until 5.3, and some hosting providers were still on 5.2 after 5.4 came out.

The only valid complaint is that the major version isn't incremented often enough to clue people in that there are potential breaking problems.

True. But there are several cases in Python where the interpreter implements both sets of semantics and allows each source code file to select one or the other. Some, such as the division semantics, use the from __future__ statement; others, such as the parallel "classic classes" and "new classes" in the 2.x series, use other syntactic triggers. And unlike Python, where the initial #!/usr/bin/env line selects the interpreter version, the choice of PHP version depends on a server configuration that's often out of the hosting subscriber's control.

PHP is basically a thin wrapper for C libraries.

Thin wrappers are better when they're namespaced. Namespaces allow providing both traditional names and PEP 8-compliant names without overly polluting the global namespace.

Slashdot Top Deals

"What the scientists have in their briefcases is terrifying." -- Nikita Khrushchev