Hacker Newsnew | past | comments | ask | show | jobs | submit | more ThatOtherPerson's commentslogin

Not everybody targets all their code for the web.


You mean there's code... not on the web?!


It's an improvement in the sense that it's more general; you can loop through any container that implements that protocol, which most (if not all) of the STL containers do. For example,

    template <class T>
    void foo(T arr)
    {
        for (auto it = arr.begin(); it != arr.end(); ++it)
        {
            std::cout << *it << std::endl;
        }
    }
You could pass a `std::map<int>` to `foo`, or a `std::list<string>`, or a `std::vector<char>`. You could even create your own classes and give them to `foo`, as long as they implement the `begin`/`end` protocol.

It's certainly more verbose than necessary, but it can be convenient.


You want to use 'T const&' as your argument type, not 'T', otherwise foo() will take a copy of anything you pass.


I've never understood the STL's infatuation with iterators. Why do I even need to know about them when all I want is walk through the collection?

Ideally, it should be something like:

    for (auto it : arr) {
      // do something with *it
    }


You can do that. That's part of C++11 and is supported by basically every major compiler.

The advantage of iterators is that they're incredibly flexible. You can use them for sub-ranges, reversed ranges, non-ranges like input and output iterators, etc, etc. This is vastly more powerful than something like, say, Objective C's NSFastEnumeration, which just allows for the trivial case handled by the range-based for-loop.


> Why do I even need to know about them when all I want is walk through the collection?

Because there are algorithms where you may not want to walk through the whole collection. STL wasn't meant to be a container library alone, it also includes many generic algorithms that work using iterators to delimit the range of data to be operated upon.


It basically is this easy these days, thankfully. It is nice to have iterators, though, because it allows you some flexibility for swapping out the underlying data structures on existing algorithmic code. This has proved quite useful when I've written graph code.


Oh yes, and I'm hella thankful for those containers. I just wish "auto" had come along a little sooner :)


He says he stored the map data as a single PNG. So, each pixel specifies what tile type that area of the map is.


That's correct, it's nothing fancy. Rather than use anything complicated it's so much faster for these sorts of game-jam situations to pack all the level data into a bitmap and just edit it visually. Since I was loading the level image anyway for display, it made the process of editing monster placement, triforce pieces, etc very fast.


Check out pandoc [1], it will let you write documents in Markdown + LaTeX for equations and then convert it to LaTeX, a PDF, or several other document formats.

Also, even though Markdown tends to be fairly easy to write, there are many edge cases where you can't really be sure what the result is unless you try it.

[1]: http://johnmacfarlane.net/pandoc/


I've gotten to the point where I just tune those out. I wouldn't have even known there was an advertisement on that page if you hadn't pointed it out.


Advertisers must hate you, you know one weird trick to tune out advertisements.


Can you explain your array[i] / i[array] reference? I can't find it on Google.


  By definition, the subscript operator [] is interpreted in such a
  way that ‘‘E1[E2]’’ is identical to ‘‘*((E1) + (E2))’’.  Because
  of the conversion rules which apply to +, if E1 is an array and
  E2 an integer, then E1[E2] refers to the E2th member of E1.
  Therefore, despite its asymmetric appearance, subscripting is a
  commutative operation.¹
¹ Dennis M Ritchie, C Reference Manual, 1975 http://cm.bell-labs.com/cm/cs/who/dmr/cman.pdf (A revised version of this became Appendix A to K&R.)


There's an answer [1] on the linked SO thread (flip to the first page) but basically, the following two lines are equivalent in C:

a[10] 10[a]

This is because a[10] is equivalent to (a + 10), and 10[a] is equivalent to (10 + a), as the first comment on this answer explains.

[1] http://stackoverflow.com/questions/1995113/strangest-languag...


From the c standard[0]:

> The definition of the subscript operator [] is that E1[E2] is identical to (* ((E1)+(E2))).

Since * (E1 + E2) is commutative, E1[E2] == E2[E1].

[0] http://c0x.coding-guidelines.com/6.5.2.1.html


Now obviously, c arrays are just strips of memory allocated to that array, so you can access them using the address of the start of the address and the offset (number of array items to skip). To access them, you sum the address and the offset, then you have the address of the item.

     [~~~~~~~~~~~~~~~~[a~~~~~~~b~~]~~~] Memory
     ^–––––––––––––––––^                Address
                       ^–––––––^        Offset
And now, a[b] is just short hand for the pointer arithmetic going on and you could just use any two ints and access any arbitrary memory address (i assume the compiler enforces that this doesn't happen).

     address[offset] => *(address + offset) => getValueAtAddress(valueIn(address) + valueIn(offset))

    a[b]  => *(a + b) => getValueAtAddress(valueIn(a) + valueIn(b))
    b[a]  => *(b + a) => getValueAtAddress(valueIn(a) + valueIn(b))
Those two are obviously the same so *(a + b) == b[a] == a[b]


I think the trick is that array[i] and i[array] will always be the same value in C.

It's confusing because array[i] makes sense but i[array] doesn't (how the hell can you use an array as an index on an integer?)

It works because array is a pointer to a memory address and i (or index) is an offset. array[i] will add the index to the memory address and return the value there, where as i[array] will add the memory address to the index. Since array+index == index+array, they point to the same memory and return the same value.


"Why am I here?"

"Because my daughter loves it here."

Seems to fit in with what he was saying to me.


Don't agree.

Something like "because my kids can receive great education here" would be a great answer, but just "lovin' it" means nothing. And having good friends is not a good reason either, because real friends are those that stay close to you when you are far away.

Moreover, I'd say adult people's life should not be constructed around their kids. It should be the opposite: kids follow their parents where they go until they can fly alone. I think it has been the case for most of humanity most of the time (the only exceptions could have been "baby kings" like Louis XIII, but they do not count).

In the same vein, if you father or mother love hiking, find a way to hike with kids. If you love snorkeling just teach them to snorkel early. If you prefer reading books at home just stay at home. They will follow. Having happy parents is the best gift for kids.

In our new society, having kids often means becoming their slave, and you are frowned upon if you dare keeping your hobbies once you have them. This is one of the most worrying mistakes I can imagine. I mean educational mistake. Kids do not need, or even like to be baby dictators.


Eh, I think too many parents are selfish, especially in America (not saying Sivers is--clearly he's not).

How often do you see parents dragging their screaming kids around, giving their 2-year old an iPad to shut them up at the coffee shop, buying a 50" flat screen TV while the college fund is at $0 and the bank accounts are overdrawn.

In the spirit of Sivers' post, I think if parents stopped, maybe once a month, and asked themselves "What am I doing to set my children up to have happy lives?" we'd all be better off.


Right, but none of the author's reasons seemed to revolve around anything but his own desire to focus and work on his products. In the context of raising a family, that's hard to justify.


I don't aim to be thorough when blogging. They're just succinct little tidbits.

Of course there's more to the story, and of course it was a whole-family decision. In fact my wife kinda led the decision even more than me.

We hope to move back to Singapore when our kid is a bit older, but he's still just a baby, so I really want him to grow up outside surrounded by nature, not inside shopping malls.


I hear you and appreciate the brevity, but I think it makes the post sound (to me) a little like: "Hey, I just ask myself a simple question about what I want, follow my heart, and off I go!"


Well, none of this is communicated by your blog post. The "more" to your story is actually key to your story, it seems to me. Why did you not include it?


Check your previous history. You probably don't have many failed attempts before the past 24 hours. It seems to be some sort of botnet attack.


I just checked my account's security history, and there's been a failed login attempt every 7 hours for the past two days, all from different IP addresses.

It reminds me of the "Hail Mary Cloud" posted previously on HN - http://bsdly.blogspot.com/2013/10/the-hail-mary-cloud-and-le...


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: