long id

Oct. 1st, 2015 02:02 pm
juan_gandhi: (VP)
I think I got it where all this bs about passing around numerical ids of entities instead of entity references (maybe lazy) come from. It's like 'error code'. It comes from the ancient c programming, where we just could not allocate a string for a readable piece of text, or for the data that may need some efforts to instantiate or allocate.

In short. It's stupid to pass around "ids" in a program.
juan_gandhi: (VP)
Find the type error in the following Haskell expression:

if null xs then tail xs else xs


Aug. 31st, 2014 03:40 pm
juan_gandhi: (VP)
If your constructor has a boolean parameter, you actually have two different types.
juan_gandhi: (VP)
http://qandwhat.apps.runkite.com/i-failed-a-twitter-interview/ (10x [livejournal.com profile] polycode)

Take a look.

I think thought it is not fair to ask this kind of questions from programmers that do not have an education in geometry. It's not a programming problem, it's just geometry.

Get a convex hull, split into chunks by the top vertices; find largest area. - BULLSHIT! does not work.

E.g. print $ solve [4,3,0,0,0,0,0,0,1]

But if a candidate is not familiar (or too familiar, like me) with all this crap, they'll go with a bunch of stupid "solutions", especially stressing "optimal" ones.

Makes ZERO sense to me. It is a bad interview question.
juan_gandhi: (Default)
is not with algorithms; there's hardly any algorithm that is hard to implement, once it's clearly formulated.
And it is probably not even performance, since it is another algorithm issue.

It is our struggle with monads. With monads that don't commute.

That's what makes Haskell so good (and so hard): it makes us to mention monads explicitly.
juan_gandhi: (Default)
  def bytes(is: InputStream) : Iterator[Byte] = new Iterator[Byte] {
    def hasNext = is.available > 0
    def next = is.read.toByte

  def isText(b: Byte) = b == 0x0a || b == 0x0d || b >= 32 && b < 0xff

  def chars(is: InputStream) = bytes(is) filter isText map (_.toChar)

So that I can use it like this:
  def main(args: Array[String]) {
    val is = new FileInputStream(args(0))
    for (c <- chars(is)) print(c)

(that's monadic, kind of)
juan_gandhi: (Default)
It's a known puzzle from the depths of object-oriented teaching: is Circle a subclass or Ellipse. From school we know it is; but as we read in books, for programmers, it is not. How come? Oh, "Liskov principle". They use Liskov principle to scare kids.

Actually we know that a circle is an ellipse with both axes being the same length.

But in programming, an ellipse is something different. It is at least stretchable. And it is also moveable. Somehow it is not rotatable, but we can skip it for simplicity.

An ellipse in programming is (almost) always horizontal; it can be moved (by changing coordinates of its center) and it can be stretched/compressed by changing its height and width. Sure a stretchable ellipse is neither an ellipse nor a circle, not even a stretchable circle. A stretchable circle stretches equally in all directions.

That's it, no? Questions? Objections?


juan_gandhi: (Default)

October 2017

1 2 3 45 6 7
8 910 11 12 13 14
15 16 17 18 19 20 21


RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 22nd, 2017 06:19 am
Powered by Dreamwidth Studios