Better HN
topnewbestaskshowjobs
Log inSign up

makecheck

12,740 karma · joined Feb 17, 2008 (18y ago) · 2,917 submissions

Submissions

comment 14y ago · link · parent

Like many things it's generally useful but not a law that applies to every class.

Some counterexamples that come to mind...

- [NSImage initWithPasteboard:] (must NSImage retain the original pasteboard and/or its contents for all eternity, in case you want it back, even if it was in some odd format like NSPICTImageRep that probably doesn't match the internal representation?)

- [NSDictionary initWithContentsOfFile:] (must NSDictionary remember the file path for eternity, and/or its contents, in case you want it back?)

Yes, if an initializer is basically accepting things that become properties anyway, it makes sense to expose those properties. But initializer arguments are not necessarily sensible or useful to keep around in all situations.

comment 14y ago · link · parent

What I find interesting about Facebook pages is the brutal honesty that consumers can sometimes share (as the brand watches frantically and tries to do damage control on comments). It's like the opposite of smart advertising: giving every prospective customer an easy place to go see what people really think. For example some new diet beverages set up pages, and after reading enough comments about how horrible the drinks tasted I never needed to buy even one to try myself.

comment 14y ago · link · parent

I guess producers are used to a world where it takes agreements with local outlets in many parts of the world to figure out how a show will be broadcast in each region.

When a pirated show is instantly available in a region that would otherwise wait a week, that shows an industry asleep at the wheel. Producers should ask themselves some hard questions if they're unable to deliver a better format when they're the ones being paid for it.

As I see it the future looks something like this:

1. ISPs and other infrastructure companies start charging much, much more for bandwidth but in exchange they invest hugely in it. The default assumption would be that everyone and his grandmother needs obscene amounts of data because this is now how they're watching TV, etc. There would be exceptions for people who somehow use very little, just like now where some people don't own a TV and don't buy cable.

2. Content companies make deals with these ISPs that basically say this: "hey, I'll produce lots of stuff people want, which will cause them to download obscene amounts of data; in exchange, give me a guaranteed cut of whatever you're charging them".

3. There would be a way to buy temporary bandwidth, e.g. instead of a pay-per-view movie you rent an hour of "high bandwidth" and download whatever you feel like watching in that time.

In other words, companies have to stop pretending the Internet isn't the best way to distribute things, and customers have to stop pretending that things don't cost money.

comment 14y ago · link · parent

It's good to point out the race condition.

To solve this particular problem in future code more compactly however, note that Python 3.2 (finally) adds an "exist_ok" Boolean keyword parameter to the multi-directory variant, os.makedirs(). In other words, calling os.makedirs("mydir", exist_ok=True) will silently ignore existing directories and only raise if other errors occur.

comment 14y ago · link · parent

Well that's true, a function is generally written as if it's been given what it wants. I wouldn't check for other types either.

But None is a result that can happen in situations that would otherwise return exactly the expected type. If "nothingness" can be meaningful (especially in a function that accepts an empty list as a parameter, say), it's nicer if the code just deals with None itself instead of requiring checks for None in all the callers.

comment 14y ago · link · parent

The thing is, None is always a possible value for a parameter so it's actually more robust if functions are written to expect None.

If you say "f(x=[])" (assuming that worked without the actual side effects it has), someone could still say "x(None)" instead of "x()", causing the function to die. Since a robust program isn't able to avoid checking for None, it might as well set defaults there too.

There is another case where this is important; you might want the equivalent of "f(x=expensive_function_to_calculate_useful_default())", and you don't want that function called unless it needs to be. Only the x=None approach allows this to be deferred.

comment 14y ago · link · parent

I've seen initials used too, which is at least a nice hint; but the case I based the example on conjured these characters essentially at random. The real kicker was that they were forced upon users in Unix environments who had been using CVS, Subversion, etc. and went from seeing useful log messages like "changed by jsmith" to aggravating ones like "changed by rjx133".

comment 14y ago · link · parent

Not only is it overly-verbose and ultimately unnecessary (as shown by the alternative that follows in the article) but this mechanism is actually broken. For instance if "freqs" were data given to you from somewhere else and "freqs[c]" happened to have a type that cannot legally have 1 added to it, you'd want to see this error. The "except:" however will absorb any and all exception types and respond to all of them by setting the value to 1.

comment 14y ago · link · parent

Trailing commas are a bit subtle and readers of the code may think it was a mistake. (We spend more time reading code later than writing it in the first place.)

Even Python removed one of its most prominent cases of this, the print command. In Python 2.x you could have a trailing comma after a print to omit the new-line but Python 3's print() function requires print('something', end=' ') to be more explicit about it.

1840.

I don't want your iPad-optimized web site

19 points · by makecheck · 14y ago · 2 comments

comment 14y ago · link · parent

Sometimes an E-mail is used on other company systems as a log-in, in whole or in part. I used to sympathize with past co-workers who had names much longer than mine, imagining them having to type "really_long_first.really_long_last@company.com" just to log into some web site.

I've also seen IT people enforce their random rules on everyone, leading to things like "rba186" as someone's actual E-mail address name instead of something meaningful.

So yes, choosing your own log-in and E-mail name would be pretty nice.

comment 14y ago · link · parent

Communication isn't one-way.

There are billions of people and plenty of languages out there (nearly 200 are spoken by at least a few million people per language, if you go by the list on Wikipedia).

We live in a world where most co-workers have probably had to claw their way up to their current language proficiency.

People who only know one language can't really complain about poor communication. Both people in a conversation have a responsibility to work at closing any gaps, and frankly a native speaker has more than 50% of that responsibility.

Even if you have learned another language, do you really know how tough it could possibly be? For example, have you learned to read, write, speak, swear and slang in the 2nd language to the point where no one will misunderstand you? And here's the real test: is the alphabet the same as your native language or is it something totally new?

I grew up with English. I spent years learning to read, write and speak French, and while this gave me some appreciation for the difficulty in learning a language it was still the same letters, similar words and a few new rules. I've since invested a lot of time in learning basic Japanese and that is something I'd recommend to anyone who thinks they're an expert at a language.

You have to try something completely unlike anything you've ever seen before you understand what a chore it must be for others to try to communicate with you.

comment 14y ago · link · parent

While raw communication can be hard to hear, I've found it lets me grow the most and it is far superior to no communication.

There is nothing quite as motivational as deciding that you're going to prove naysayers wrong. If they say that what you did sucks, you work really hard to make them liars. Anger is good for this. Hearing nothing but praise just keeps you from trying to do better, and sugar-coated problems never seem severe enough to invest time in.

It's also a clue (albeit one lacking social graces) when people speak strongly about something: the topic is important to them. Don't allow bad language to keep you from parsing a good point out of an argument; you might not hear that same argument from anyone else.

comment 14y ago · link · parent

There's already an effort to do this:

http://fixradarorgtfo.com/

500+ developers so far have submitted this to Apple.

comment 14y ago · link · parent

One of the most important things programmers can learn is that you don't have to choose one language per project. Binding, say, Python and C++ in the same program can be very valuable (though it is not trivial, even with SWIG). Some code benefits from the simplicity, clarity, testability and huge standard library of the scripting language, and the remaining code gains performance and expressiveness to handle its greater complexity.

comment 14y ago · link · parent

There's a tricky problem that comes up in teams. A "bad" developer can hack and slash and appear to implement new features in a certain amount of time, and a "good" developer who takes the time to do everything right may actually produce less of obvious value in the short term. When approaching software restructuring, you have to make damn sure that your management chain understands the importance of the refactoring and can evaluate the time you spent for its actual worth. If your organization uses "metrics" or other weasel words to examine productivity, tread carefully.

It's also worth noting that even if you believe you know how to improve/simplify/whatever, it may be worse than you think and sometimes you don't figure out the extent of the complexity until days have gone by.

This, like many things, is a trade-off and not a set rule. In brand new code, by all means make it small and pretty and documented and whatever else would win it an award; but in established code bases be smart about what you "fix".

comment 14y ago · link · parent

It's funny to see this perspective; lately Robert X. Cringely devoted several posts on his site[1] to just how messed-up IBM seems to be.

[1] http://www.cringely.com/

comment 14y ago · link · parent

Well as an example, on a Sprint HTC phone the crapware auto-started itself not only when the phone powered on, but apparently several times a day (despite using an app-killer). This wasn't just 1 or 2 apps, it was like 10. So my idle battery was draining away in part because I couldn't stop this phone from running things I never intended to use. I have never been happier since switching to the iPhone from that broken ecosystem.

comment 14y ago · link · parent

iMessage is a threat because iPhones are popular; the extent of the threat is directly proportional to iPhone market share.

Carriers made significant amounts of money because of the iPhone that arguably they would not have found any other way to make. Very few of their personal investments led to this success (except perhaps things like Cingular's agreement to invest in "visual voice mail" at Jobs' behest, before AT&T bought Cingular).

From my point of view the complaint from AT&T is a little like an investor trying to socialize his losses while keeping all his capital gains. AT&T enjoyed Apple's success when it benefited them, and now that it's working against them they're worried? Well, tough.

comment 14y ago · link · parent

Every language's standard library needs a "current best practices" concept, even if it's just a well-maintained document and not something structural like a special namespace.

I think the Python "decorator" concept goes a long way toward cleaning up code. Basically you can add a decorator to a routine that you've deprecated so that it will complain if it's actually used (you can even include advice on what would be a good replacement call).

As far as cleaning up what's installed as standard, it's not really practical to remove anything (the fact that it stays is one of the attractive things about Python in old code bases). What you can do though is define a preferred namespace, e.g. "preferred"; this would physically contain only those libraries that are recommended, and perhaps even forked copies of modules that only contain the functions that should be used. This gives programs the option to explicitly import from "preferred" and request purity over long-term stability.

comment 14y ago · link · parent

There are already plenty of cases that valid UTF-8 readers have to deal with (unused ranges of code points, invalid byte combinations, etc.). Ignoring a BOM is trivial by comparison. A UTF-8 reader honestly doesn't care about the "stringness" of a .txt file because of all the other crap that can be in a byte stream.

Older programs do care, but as I've said elsewhere in the thread an ASCII file can remain ASCII (no BOM). There's no reason to BOM-ify an old ASCII file if it really is ASCII and only ASCII-expecting programs will ever use it.

Over time these old programs will either be upgraded or go away and it will finally be safe to say that inputs must be UTF-8. At that time, the BOM has no reason to exist.

comment 14y ago · link · parent

I agree with the use of context, yes; if you already know your input is UTF-8 (e.g. C strings in a program API or a protocol or whatever) there's no point in adding an extra specifier.

If a program requires ASCII compatibility in order to work then by all means make the input files ASCII (no BOM), just make sure the files have no true UTF-8 dependencies in them.

Once a program supports UTF-8 "properly" however, the BOM is useful as a signal that the input is somewhat complicated.

At some point in the future when UTF-8 really is everywhere and programs may no longer even try to sniff encodings, etc. then yes, the BOM has no real reason to exist.

comment 14y ago · link · parent

If a file really is pure ASCII, leave it that way. I am not suggesting to do otherwise. If a 30-year-old program only deals with ASCII then make sure your input looks like ASCII.

But if your input could contain complex UTF-8 (e.g. it's multi-language or whatever), you're not doing any favors by hiding this fact. The BOM is a quick way to know exactly what the file is, and it shows you that your program won't work with that input. So you translate the input or you fix the program.

At some point in the future the majority of programs will handle even complex UTF-8 properly, and then the BOM will be pointless because virtually all inputs will be UTF-8.

comment 14y ago · link · parent

I prefer to solve the problem in the right place.

Raw concatenation of bytes without encoding-awareness introduces the possibility that the bytes will combine in unexpected ways. The presence of something as obvious as a BOM makes it harder to make this mistake, at least during the transition phase to "UTF-8 everywhere".

What you really want in this situation is something that forces you to see the potential bug and introduce the correct translation and/or text-concatenation tools to fix it.

And yes, at some point in the future enough tools will be truly aware of UTF-8 that the BOM will not have a reason to exist. But right now it has some value.

comment 14y ago · link · parent

No, UTF-8 cannot be processed in exactly the same way as ASCII! It is highly compatible with ASCII-assuming environments because it can accept the same data (e.g. it remains a stream of bytes that doesn't have to be converted to some "fat" integer) and any UTF-8 text that just happens to contain only ASCII characters will work just fine with an old ASCII program. But complex multi-byte UTF-8 inputs will not work without special treatment.

Historically code pages mapped character values directly to individual bytes: typically redefining the upper half (129+) while leaving the lower numbers the same as ASCII. Programs could display a wide variety of text encodings correctly as long as they knew what the encoding was, and all they had to do was read bytes individually. These encodings could all be handled in a way largely similar to ASCII.

UTF-8 however is a multi-byte encoding, which means you could have (say) 3 bytes that combine to form a symbol. Not only that, but in certain forms multiple symbols could imply display as a single glyph (e.g. an accent followed by a letter). A program that does everything the old ASCII way would choke on multi-byte UTF-8, despite being otherwise-compatible. Consider a program with a fixed-size read buffer; if the last byte is only partway through a multi-byte character, that character will be mishandled unless the program knows how to preserve those bytes and "complete" the character when more bytes arrive.

comment 14y ago · link · parent

Agreed. The user of "cat" is responsible if they've created a stream that is invalid input to some other program. Unix philosophy is for programs to do (ideally) one simple thing well. If the contents of any one file cannot be used directly, then the idea would be to run some other filter program first (e.g. one that strips bytes from the beginning) prior to using "cat" and piping the results somewhere else.

In practice though some programs and protocols have text/binary distinction (e.g. FTP). It's not unreasonable to have a mode that hints when bytes are to be used as text. This is frequently done to handle different new-line styles for instance.

comment 14y ago · link · parent

You wouldn't prefix every string with it because presumably your API or program's state has already determined the string's encoding. I am not suggesting that every fragment of text has to be explicit (I agree that would be ridiculous). I am only stating facts: there is nothing incorrect about having the mark, a conformant reader must be able to handle the mark, and the mark has some value as a short-cut for avoiding elaborate decoding tricks.

comment 14y ago · link · parent

If you're reading something in pieces, like a buffer that fills 256 bytes at a time, you have to be careful. UTF-8 is a multi-byte encoding so the last byte in your buffer may not completely finish a code point. Unlike older code that can just read a bunch of bytes and use them, with multi-byte encodings you have to have a way to deal with "left-overs" until new bytes show up.

Fortunately the UTF-8 encoding (e.g. see the Wikipedia page) makes it clear when a byte is the beginning of a new point and it tells you how many intermediate bytes should follow.

comment 14y ago · link · parent

The mark isn't useless; it clearly identifies files as UTF-8 so they can be processed as such immediately. Otherwise a program has to "sniff" several bytes to see if the encoding could be something different, and it may not guess correctly.

Also, how can "all kinds of things" break with this mark? If something is reading UTF-8 correctly then it'll be fine with the mark; and if it's not reading UTF-8 correctly then it will screw up a lot more than the mark at the beginning of the file.

comment 14y ago · link · parent

Markus Kuhn's web page has a lot of useful UTF-8 info and valuable links (e.g. samples of UTF-8 corner cases that people often miss).

http://www.cl.cam.ac.uk/~mgk25/unicode.html

1
616263
98