Better HN
topnewbestaskshowjobs
Log inSign up

vec

2,000 karma · joined Aug 9, 2012 (14y ago) · 391 submissions

Submissions

comment 13y ago · link · parent

The reason that many people think the WP loop is badly constructed is because it entirely works by side effects. A (very simple) WP loop looks like this:

    <?php while (have_posts()) : the_post() ?>
      <h2><?php the_title() ?></h2>
      <?php the_content() ?>
    <?php endwhile ?>
There are four unique functions there. All of them depend on non-obvious global state and three of them are used specifically to produce side effects. the_post() invisibly overwrites a global and changes an iterator. It not only mutates global state, but it does something different if you accidentally call it twice. And WP's the_whatever() functions echo something and return nothing?! Want to do some filtering on the title before you print it? Better use get_the_whatever() instead. WTF?! Heres how it should work:

    <?php foreach ($post in $wpdb->get_posts() : ?>
      <h2><?= $post->title ?></h2>
      <?= $post->content ?>
    <?php endforeach ?>

comment 13y ago · link · parent

That's not a big surprise. jQuery's events use native browser events behind the scenes. Which is nice for dom-oriented plugins; you get bubbling for free and all the native event listeners just work. It's got a pretty fair amount of overhead though. Backbone's events are just a pure JS event emitter implementation.

I'm curious, though, why they added an external dependency instead of just inlining a solution. There's a couple of good MIT licenced barebones implementations[1][2] floating around, and it's pretty straightforward to reimplement yourself in an hour or two if you prefer.

[1] https://github.com/Wolfy87/EventEmitter [2] https://github.com/hij1nx/EventEmitter2

comment 13y ago · link · parent

Probably not, assuming our current theories about how these systems form are correct. Our best guess is that hot jupiters form about where our jupiter or saturn is and their initial orbit decays inward. If so, that would tend to destroy the orbit of anything vaguely earth-sized on the way in.

comment 13y ago · link · parent

This times a lot. I'm far from a naive user, but I recycle a handful of easily memorable passwords for most of the services I subscribe to. And I'm willing to bet that most of you do too.

Security is a tradeoff, and we tend to forget that complex, unique passwords have a very real cost. They drastically increase the risk that I will lock myself out of some service, and dramatically increase the workload of authorizing myself when I do want to use it. With a few obvious exceptions, this tradeoff is a huge net loss for the average user.

In other words, the risk of some stranger wanting to post as me in HN is acceptably small. The cost of having to install KeePassX, then download my passwords file from Dropbox then decrypt and copy/paste, then make sure the paste register is clear, then securely delete my passwords file every time I borrow a friend's computer is prohibitively high.

comment 13y ago · link · parent

In this situation I tend to follow the Montgomery Scott Miracle Worker Rule(tm). Come up with a nice, comfortable number in your head, pad it out a little if necessary so it's a nice round number, then multiply by 4.

comment 13y ago · link · parent

SQL databases are strongly typed and extremely good at enforcing consistency, whether you want them to or not. They are quite good at preventing many classes of bad data from being recorded in the first place, and allow you to do some types of low level data manipulation (joining datasets, eliminating duplicates, finding mins and maxes, etc) extremely efficiently.

NoSQL, on the other hand, is weakly typed and makes few if any attempts to validate your data, pushing that responsibility back onto you. They are very well suited to storing inherently inconsistent data (which, as a corollary, makes them very good for prototyping, when your data model is rapidly changing and growing). They also allow you to link much larger datasets into a 'document' which is retrieved as a unit with no extra computation.

So it mostly boils down to what kind of data you want to store. If you find yourself almost exclusively saying things like "All users have a username that is a string" or "I want to be able to find all products that cost less than $20" then you're probably looking for a traditional SQL database. If, on the other hand, you find yourself saying "some products have a width and height, but some just have a height, and a few have a volume instead" or "I want to be able to add custom fields to products on the fly" or "I never want to see purchases on their own, I always want to see them joined to the user that bought them" then you should probably consider a NoSQL solution.

comment 13y ago · link · parent

> What's plainly obvious to me is that many (most?) women just aren't interested in the field.

Which is exactly the problem. There's no strong reason to suggest that this difference is due to anything other than social pressure. Something in the way we socialize children is convincing half the potential talent pool that they shouldn't develop an interest in technology fields, almost certainly because they see few if any adult role models.

It's not really a failing of the industry, in the sense that we're probably not the ones who originally caused it. But it is a problem for the industry, and one that industry insiders are in a unique position to solve.

comment 13y ago · link · parent

Yeah, but things _were_ different in the 1700s when they wrote it. At the time there was no standing army, each state had a militia and citizens were often responsible for providing their own equipment. The 2nd amendment seems to have been aimed mostly at state governments, sort of a "when we need your militia, you'd better have one we can use".

The reading where being armed is a protected right of each individual _is_ a reinterpretation, and a fairly recent one at that. http://backstoryradio.org/straight-shot-guns-in-america-2/ (podcast, but well worth the time) has a wonderful summary of how this view has evolved over the last 2.5 centuries.

comment 13y ago · link · parent

By the same logic, the idea that in order to give a car to one's teenage child one must go to a government office and get said teenager licensed is also absurd.

Lets not forget that guns are devices whose primary function is to kill things very efficiently. I'd argue that if you're not willing to spend $50-$100 and wait a few days, then you're not treating that kind of transfer of power with the respect it deserves.

comment 13y ago · link · parent

> Keep in mind that Ember.js and other frameworks like it are really only valuable to people who are writing single page javascript applications. If you aren't, or you are against the idea of building single-page applications, then these frameworks won't really do much for you. Although, you can still get some value out of them.

This is fairly true of ember specifically, but much less so for some of the other frameworks. Backbone and Angular, in particular, are very well suited for building "islands of richness" in otherwise traditional sites. Even if you're doing something relatively simple, like a form with live validations and inline error messages, you're going to have an easier time writing it with something to handle the DOM manipulation for you.

If you're wanting to get into frontend JS, start with Backbone. It's much less powerful than the other frameworks, but is by far the easiest to grok, and having it under your belt will give you enough tools to start moving larger and larger chunks of functionality into the browser. Come back to Ember once you outgrow that.

comment 13y ago · link · parent

Going into debt to pay your medical bills is very different than going into debt to buy a yacht.

No one thinks a ballooning deficit is good, some of us just think it's less bad than cutting social security and medicaid in the middle of a recession.

comment 13y ago · link · parent

The reason here is that the interests of employers are misaligned with society's interests at large.

Individual employers are clearly demonstrating that they have a disincentive, rational or otherwise, from hiring potential employees with large gaps in their resumes. This obviously will tend to feed back on itself, making long gaps longer and unemployable applicants even more unemployable as time passes.

Society, on the other hand, has both economic and humanitarian interests in minimizing the number of unemployable individuals. Since the market has inadvertently began creating a large pool of these unemployable people, and it shows no sign of changing in the short to mid term, then society can and should apply non-market forces to advancing its interests.

Honestly, I'm not sure if direct employment is the best solution; I'd probably prefer some variation on tax incentives for employers. But reaching for the hammer, as you put it, is not always a knee-jerk reaction and seems like a pretty rational instinct in this situation.

comment 13y ago · link · parent

Remap caps lock to be a ctrl key, then preferably remap your prefix key to a. Caps+a is way easier to type.

comment 13y ago · link · parent

Reveal.js, at least, supports inline markdown blocks. https://github.com/hakimel/reveal.js#markdown

comment 13y ago · link · parent

That's actually backwards. Since each round is independent of the last, collisions on an intermediate step will propagate forward. Since each round has the same chance of creating a collision, more rounds means higher total odds.

comment 13y ago · link · parent

There's nothing wrong with typing Vjjjjj until it looks right, and you can still click and drag if that's what seems easiest to you. But if you're thinking of it in lines and characters you're missing the real advantage.

You're still mentally translating a what into a how. You almost certainly don't want to highlight 5 lines down for its own sake, you probably want to highlight, say, the body of a function. Vim provides a command to just do that directly.

comment 13y ago · link · parent

A bit off topic, but the big win with Vim (and, from what I hear, emacs) isn't the speed per se; it's the lack of cognitive load. "I need to replace everything after the equals sign", for example, takes less concentration than "I need to move my cursor to the beginning of the word after the equals sign, hold shift, move it to the end of the line, and then hit backspace". Once I got past the terrible learning curve, being able to use those kind of abstractions made a noticeable difference in how much program state I can hold in my head while I'm changing it.

comment 13y ago · link · parent

I'm getting in the habit of letting the caller decide, something like the following:

    myAsyncFunc = function (param1, param2, callback) {
      var usingPromises = (callback === undefined);
      var returnVal = usingPromises ? Q.defer() : this;

      someFunction(function (err, res) {
        if (usingPromises) {
          err ? returnVal.reject(err) : returnVal.resolve(res);
        } else {
          callback(err, res);
        }
      });

      return returnVal;
    };
So if I call myAsyncFunc(foo, bar) it returns a promise and if I call myAsyncFunc(foo, bar, cb) it returns itself for chaining.

comment 13y ago · link · parent

So ignoring the fact that today's April 1st, this is actually not a terrible idea. It's not perfect, but lynx is a pretty good first approximation of how usable your site will be with a screen reader.

comment 13y ago · link · parent

I'd always head the performace pitch for Mongo being "slightly slower on a single machine, but way easier to scale out horizontally"

comment 13y ago · link · parent

I'm thinking that's mostly due to the testing methodology. In JS it's pretty common to start a project by downloading and committing jQuery, Underscore, and whatever framework dependencies you're using. And just speaking from experience, coffeescript is better, but it's not _that much_ better (I'd guess ~1.5 lines of JS per line of CS, the chart shows somewhere around 8:1).

comment 13y ago · link · parent

Intriguing concept, but for those of us in offices an NSFW notice would not go amiss.

comment 13y ago · link · parent

> When I say that the consumers are equally complicit, what I really mean is that in many cases they just listened to a sales pitch and accepted it as truth.

If you tell me something that you know or should know to be false, I act on what you told me, and you benefit from my action, then by definition I have been defrauded.

comment 13y ago · link · parent

As a client, it is perfectly reasonable for me to say to a sales rep "I want X% average return, I'm willing to accept Y amount of risk to get it, and I don't care particularly much about how you give it to me", so long as X and Y are reasonable. My understanding is that the financial institutions were accurately describing the average rate of return but drastically under-representing the risk of these instruments to their clients.

Calling consumers 'complicit' for failing to understand a company's offerings significantly better than their own salespeople is at the very least insulting.

comment 13y ago · link · parent

Given the historical record, probably.

comment 14y ago · link · parent

It's probably out of order on purpose. I'm betting this was some of the test data that the developers used, and they just left it in when they finished.

comment 14y ago · link · parent

Sounds like the Dunning-Kruger effect hard at work. People get a good solid grasp of the basics and think they're experts because they don't know enough about the subject to realize that the basics aren't the whole domain.

Try exposing them to a few advanced topics in whatever they're overreaching on (like higher order functions for JS or named pipes in Unix). May not work, but you might get lucky and knock a few of them over the learning plateau and back on course to become real experts.

comment 14y ago · link · parent

Yes, but the absolutely most qualified person for a whole bunch of things is disproportionately often white and male. And even if we as a society wake up tomorrow magically not racist or sexist at all, that will be the case for the foreseeable future simply because white men have disproportionate amounts of money and connections.

Hiring through AA is _intentionally_ suboptimal. The whole point is to give members of disadvantaged communities access to opportunities they are less qualified for in the hope that they, and by extensions their communities, will over time become _less_ _disadvantaged_.

There are more important things in this universe than efficiency.

comment 14y ago · link · parent

Books don't cost $C/book to produce, they additionally cost $X to research, write, market, etc. And $X is much much larger than $C.

So to take your example, assuming X=12 and C=1, if I sell my books for $6 and $9, respectively, I make $1 profit, but if I'm forced to sell them both at $6 I lose $2.

Price discrimination is often a Good Thing, on balance. The takeaway from allowing price discrimination isn't (mainly) that Americans get gouged, it's that Thai students get access to textbooks they wouldn't otherwise be able to afford.

comment 14y ago · link · parent

Hopefully none of them (at least none that use floating point arithmetic). When you convert the equation to the exponent notation you get this:

(1.2x2^-2) - (1.6x2^-3) = (1.6x2^-3) - (1.6x2^-4)

which is pretty clearly false. http://www.h-schmidt.net/FloatConverter/IEEE754.html has a pretty nice conversion tool, if you're curious.

1
1011121314