« first day (723 days earlier)      last day (170 days later) » 

4:51 PM
@рытфолд You should design a programming language sometime where each and every language feature should never be used.
 
user1804599
C++.
 
user1804599
My comments are like Java: they are outdated and they suck.
 
user1804599
(* TODO: Add 'out in Boolean' postcondition. *)
#doc("Determines whether `x` is NaN.");
def isNaN(x)(require x in number)
            (ensure out in boolean) =
    global.isNaN(x);
 
Are postconditions comments?
 
user1804599
4:54 PM
No, look at line four.
 
Okay, and will they appear in the generated "Javadoc"?
 
user1804599
Yeah.
 
nice
That's what I hate most about DbC in Java. That your logic is duplicated in the comments. Basically impossible to maintain.
 
user1804599
 
user1804599
This is what my documentation generator currently outputs.
 
4:56 PM
nice
 
user1804599
The contracts are also checked at runtime similar to D and Eiffel.
 
user1804599
There'll be syntactic sugar for in contracts soon:
 
Types? :)
 
user1804599
def isNaN(x: number): boolean = global.isNaN(x);
 
user1804599
Note how in acts like isInstanceOf for types. You could say this too:
 
user1804599
4:57 PM
def foo(x: Set(1, 2, 3)) = …;
foo(4); -- error
 
user1804599
Since in also works on sets.
 
user1804599
@FredOverflow You can write a class loader that takes the Javadoc comments and puts the contracts in the code as as assertions. Javadoc comments are available in class files AFAIK.
 
user1804599
Nah, you can't. You have to compile the comments to bytecode.
 
user1804599
You can write a compiler plugin that does it, though.
 
...Or I could just not use Java :)
 
user1804599
5:00 PM
Yeah, that's better.
 
user1804599
Java Sucks
 
How long are pins?
 
user1804599
14 days.
 
user1804599
Maybe 15.
 
@рытфолд Is that a special type that can be either Nothing or Just 15, but no other integer? :)
 
user1804599
5:01 PM
Soon you can say Option[15.type] in Scala. :D
 
user1804599
Then it can only be None or Some(15), and nothing else.
 
awesome :)
 
user1804599
You can already acquire 15.type with a macro, there's just no syntax for it yet.
 
Does 15.type.type make sense?
 
user1804599
No.
 
user1804599
5:02 PM
Types have no types, but kinds.
 
15.type.kind
 
user1804599
You cannot get the kind like that.
 
user1804599
I don't think kinds are first-class in Scala. You can't parameterise over them.
 
user1804599
Would 15.type.kind be a subkind of Int.kind?
 
user1804599
I.e. can you use it anywhere the kind of Int is expected?
 
5:06 PM
I have no idea :)
 
user1804599
Or are the kind of the singleton type of 15 and Int the same kind?
 
user1804599
No wait.
 
user1804599
15.type.kind would be the singleton kind of the singleton type of 15. It should be a subtype of the kind of all types.
 
user1804599
15.type and Int have the same kind, but 15.type.kind and Int.kind don't, since their kinds only inhabit 15.type and Int respectively.
 
user1804599
@FredOverflow guess what I named Any and Nothing in LasagnaScript.
 
5:08 PM
The other day I wrote a program that generates swears. It comes in a file called swear.jar
@рытфолд Any and Nothing would be my first tip.
 
user1804599
LasagnaScript has a swear keyword.
 
user1804599
@FredOverflow top and bottom!
 
@рытфолд What does it do?
 
user1804599
You can use it to swear that an existing type implements an interface.
 
Doesn't bottom usually mean non-termination?
 
user1804599
5:09 PM
If it doesn't actually do that, it's UB.
 
class ArrayList swear List
 
user1804599
@FredOverflow In type theory, bottom is a subtype of all types.
 
user1804599
@FredOverflow class creates a new type, not an existing type.
 
Then I must be confusing it with a different bottom.
 
user1804599
Something like, interface Length { def length: number; } swear Length for Array;.
 
user1804599
5:10 PM
Now Array is a subtype of Length.
 
Ah, kind of like how type classes can be instantiated after the fact.
 
user1804599
No, they already have to be implemented. swear just creates the subtyping relationship.
 
dang
 
user1804599
It's for interop with JavaScript libraries that depend on duck typing.
 
user1804599
For type-class-like behavior you can use protocols, which don't use member functions but free functions.
 
5:16 PM
 
user1804599
protocol Length {
    def length(this): number;
}

implement Length for Array {
    def length(xs) = xs.length;
}

implement Length for List {
    def length(xs) = match xs {
        case Nil => 0;
        case Cons(_, ys) = 1 + length(ys);
    };
}

console.log(length(array(1, 2, 3)));
console.log(length(list(1, 2, 3)));
 
user1804599
This doesn't pollute the classes' namespaces, unlike adding members to them.
 
You know what the rationale at our University is behind teaching LISP instead of Haskell in the second year?
 
user1804599
No.
 
Because students already know static typing from Java :-D
 
user1804599
5:19 PM
Which lisp? Common Lisp?
 
I think it's... Racket?
Is that even a language or just an IDE?
 
user1804599
Ah.
 
user1804599
It's a language.
 
user1804599
If they used Clojure they could stay with their precious Java ecosystem. :P
 
The people who teach LISP aren't very fond of Java.
 
user1804599
5:21 PM
 
You should add a caption that says "All types, from top to bottom"
 
user1804599
@FredOverflow Gonna do that, awesome.
 
user1804599
In ECMAScript 7 you can create your own value types, which will fit neatly into this model.
 
You can propably reformulate that into something a little more witty :)
 
user1804599
Forward-compatibility ftw!
 
5:23 PM
I have a hidden desire. I want to implement a non-trivial tree structure.
Would RB trees be a good choice for a start?
 
user1804599
I have no idea.
 
user1804599
I have never implemented any data structures other than arrays, cons lists and records.
 
user1804599
Arguably cons lists are just nested records.
 
> Tracking the color of each node requires only 1 bit of information per node because there are only two colors. The tree does not contain any other data specific to its being a red–black tree so its memory footprint is almost identical to a classic (uncolored) binary search tree. In many cases the additional bit of information can be stored at no additional memory cost.
Interesting. In the lowest bit of a pointer, I would guess?
 
user1804599
 
user1804599
5:31 PM
This one is nicer.
 
user1804599
@FredOverflow Yeah, at least in x86-64.
 
Too bad I can't fiddle with pointers in Java.
 
user1804599
Use boolean.
 
But that could cause an overhead of 8 bytes :)
 
user1804599
bits, not bytes
 
user1804599
5:34 PM
well, more, since the metadata has to be stored for reflection
 
user1804599
but that's only once, not per instance
 
77
Q: What is the memory consumption of an object in Java?

manuelIs the memory space consumed by one object with 100 attributes the same as that of 100 objects, with one attribute each? How much memory is allocated for an object? How much additional space is used when adding an attribute?

 
user1804599
It's O(1), where the O is for "Occurrence" :D
 
Object size is round up to the next mutiple of 8 on 64 bit systems, so adding a boolean can indeed cost 8 bytes.
For example, java.lang.Boolean costs 16 bytes instead of 9.
 
user1804599
Hmm.
 
user1804599
5:35 PM
Yeah, but there should only ever be two instances of that.
 
user1804599
Unless some moron says new Boolean.
 
right
 
user1804599
In Perl 6 and Dart, new can return an existing object. :D
 
But it's a problem if you have a boolean in every node of a tree.
Oh wait, I could just have two different classes, RedNode and BlackNode.
 
user1804599
@FredOverflow Then store a bit array separately.
 
5:36 PM
Then I don't need the boolean flag :)
 
user1804599
Meh. :v
 
user1804599
Then you have extra overhead since you cannot make it final.
 
user1804599
So no final-specific optimisations can be performed.
 
user1804599
I'd go with enum Color { RED; BLACK; }.
 
Ah, so if I have only one Node class, the optimizer can get rid of virtual dispatch?
 
user1804599
5:37 PM
Yeah.
 
user1804599
Since it's a JIT it doesn't even need to be final since the JIT can already see there are no subclasses of it.
 
user1804599
Don't optimise prematurely.
 
user1804599
public enum Color { RED; BLACK; }

public final class Node<T> {
    public final Color color;
    public final T value;
    public final Optional<Node<T>> left, right;
}
 
6:04 PM
abstract class Tree[T] {
  def contains(x: T): Boolean
}

object Empty extends Tree[Nothing] {
  def contains(x: Nothing) = false
}
 
user1804599
Make Tree covariant on T.
 
user1804599
Otherwise it will be terrible to use Empty.
 
@рытфолд So abstract class Tree[+T]?
 
user1804599
abstract class Tree[+T] {
  def contains(x: T): Boolean
}

object Empty extends Tree[Nothing] {
  def contains(x: Any) = false
}
 
user1804599
Parameter types are contravariant.
 
6:06 PM
@рытфолд I get a compiler error that complains about that.
 
user1804599
Make it x: Any instead of x: Nothing.
 
The error is in the Tree class, not the Empty class.
 
user1804599
What is the error?
 
user1804599
Oh right, you cannot do that for obvious reasons.
 
user1804599
Do this instead:
 
user1804599
6:08 PM
abstract class Tree[+T] {
  def contains[U >: T](x: U): Boolean
}
 
covariant type T occurs in contravariant position in type T of value x
abstract class Tree[+T] {
  def contains[U >: T](x: U): Boolean
}

object Empty extends Tree[Nothing] {
  def contains[U](x: U) = false
}
Now it compiles.
 
user1804599
Nice.
 
[U] is the same as [U >: Nothing], right?
 
user1804599
Yeah.
 
user1804599
All types are supertypes of Nothing.
 
6:11 PM
So what is the benefit of this genericity? Now I can ask a Tree[Dog] whether it contains some Animal?
 
user1804599
If you didn't make Tree covariant on T, then val x: Tree[Int] = Empty would not compile.
 
user1804599
Which would be incredibly stupid for obvious reasons.
 
user1804599
@FredOverflow That's a drawback, yeah.
 
You know what? Fuck genericity. I'm gonna make a tree of strings :)
 
user1804599
6:14 PM
Noooo, this is good.
 
user1804599
Seq also does it this way.
 
I want to learn about trees, not generics.
 
user1804599
OK. Make it specific first, then generalise it. :P
 
good idea
And if I fail to implement it with strings, at least I didn't waste any time on generic matters :)
Just out of curiosity, how do I specifiy that T must be comparable?
 
user1804599
Ordering type class.
 
user1804599
6:16 PM
class NonEmpty[+T](implicit ord: Ordering[T]) extends Tree[T] { … }
 
user1804599
Or class NonEmpty[+T: Ordering] extends Tree[T] { … } if you don't need a name for the type class instance.
 
Ah, so I can have an empty tree of a type that is not comparable? :)
 
user1804599
Sure.
 
user1804599
In fact, implicitly[Ordering[Nothing]] is ambiguous.
 
user1804599
The empty tree doesn't care about the element type anyway, since it contains no elements.
 
user1804599
6:19 PM
Hmm, implicitly is the identity function. :D
 
user1804599
assert(implicitly[Int](42) == 42)
 
user1804599
A nice thing about this is that you can make type class instances on the fly.
 
user1804599
new NonEmpty(Ordering.by((_: String).toUpperCase))
 
6:51 PM
RB trees are way too complicated. Researching 2-3-trees now.
 
user1804599
My favourite tree is the linked list.
 
user1804599
In JavaScript you get undefined if you access a non-existing property.
 
user1804599
> {}.foo
undefined
 
user1804599
However, in LasagnaScript I want that to be an error.
 
user1804599
6:54 PM
So I compile x.foo into $lasagnascript$readProperty(x, 'foo').
 
user1804599
However, this is insanely slow because there is a function lookup, a function call and the function in question has several checks.
 
user1804599
So I decided to make it a precondition that the property exist, and preconditions aren't compiled in release mode. :)
 
user1804599
Precondition violation in release mode is UB.
 
user1804599
And UB is fast. :D
 
user1804599
dlang.org got redesigned.
 
7:05 PM
They have a new logo, right?
Or was that just for the conference?
 
user1804599
@FredOverflow No.
 
user1804599
That's just for DConf.
 
user1804599
The D logo is still the letter D with Phobos and Deimos in the background.
 
When will D get a third standard library? ;)
 
user1804599
7:08 PM
When did you ever need a try statement with both catch and finally clauses?
 
user1804599
@FredOverflow When Mars gets a new moon.
 
user1804599
I am thinking of detaching finally from try.
 
@рытфолд I haven't done exception-related stuff in a long time, dunno.
 
user1804599
So you can say { val x = …; finally x.close(); … } instead of { val x = …; try { … } finally { c.close(); }; }.
 
y u no RAII?
 
user1804599
7:10 PM
Because JS no RAII.
 
user1804599
JS doesn't even have destructors.
 
But could you not convert RAII-aware LasagnaScript to whatever you translate finally blocks to now?
 
user1804599
I do plan on { use x = …; … } which desugars into { let x = …; finally dispose(x); … }.
 
user1804599
Which will also work within do notation if bracket has been implemented for the monad in question.
 
user1804599
The latter is needed in async code.
 
user1804599
7:17 PM
The Future monad can implement bracket, for example.
 
user1804599
do future {
    let! x = someFuture;
    use y = open(s"files/$x.txt");
    let! z = y.read();
    return parseInt(z);
}
 
user1804599
future.bind(someFuture, fn(x) => {
    let y = open(s"files/$x.txt");
    future.bracket(fn() => { dispose(x); }, fn() => {
        future.bind(y.read(), fn(z) => {
            future.@return(parseInt(z));
        });
    });
});
 
user1804599
Same thing.
 
user1804599
s/@return/return/
 
11:49 PM
@рытфолд My 2-3-tree seems to work for strings now:
var a = Tree()
println(a)
for (x <- 'a' to 'z') {
  a = a.insert(x.toString)
  println(a)
}
()
(a)
(a b)
((a) b (c))
((a) b (c d))
((a) b (c) d (e))
((a) b (c) d (e f))
(((a) b (c)) d ((e) f (g)))
(((a) b (c)) d ((e) f (g h)))
(((a) b (c)) d ((e) f (g) h (i)))
(((a) b (c)) d ((e) f (g) h (i j)))
(((a) b (c)) d ((e) f (g)) h ((i) j (k)))
(((a) b (c)) d ((e) f (g)) h ((i) j (k l)))
(((a) b (c)) d ((e) f (g)) h ((i) j (k) l (m)))
(((a) b (c)) d ((e) f (g)) h ((i) j (k) l (m n)))
((((a) b (c)) d ((e) f (g))) h (((i) j (k)) l ((m) n (o))))
((((a) b (c)) d ((e) f (g))) h (((i) j (k)) l ((m) n (o p))))
 
user1804599
@FredOverflow Congrats!
 
So... time to go generic? :)
 
user1804599
Yeah. :P
 
Or maybe let some Scala expert review my code first.
 
user1804599
All you probably need to do is to use the Ordering type class and the +T and Nothing and >: stuff.
 
11:51 PM
>: looks like a sad smiley.
 
user1804599
@FredOverflow If only there were one in this room. :)
 
user1804599
In Perl 6, zipWith is an infix operator which takes another infix operator:
 
user1804599
> (1, 2, 6, 2, 3) Z== (8, 2, 3, 4, 3)
False True False False True
 
user1804599
// Line 100 can be shortened:
override def toString = s"($a $b $c $d $e)"
 
11:58 PM
I am more worried about the asInstanceOf stuff.
Probably needs a complete redesign to get rid of that.
@рытфолд Will that be transformed by the compiler into the code I have now?
 

« first day (723 days earlier)      last day (170 days later) »