« first day (774 days earlier)      last day (119 days later) » 

9:35 AM
0
Q: Not able get response from server when many socket connections are in ESTABLISHED state

Bharath KrishnaI have a search server, which responds to the queries from client machine. I have implemented a singleton connection pool, but when there are many established states, the next search(ie. next time when it tries to connect to search server) gives an error getting server response. Is many connectio...

 
 
2 hours later…
user1804599
12:03 PM
So, I had this wonderful idea.
 
user1804599
I don't like the do keyword here:
 
user1804599
def f() do
    // ...
end
 
user1804599
But removing it would result in a problem with ensure, require, throw, synchronized and strictfp.
 
user1804599
Type classes in Scala are OO classes!
 
user1804599
And type class instances in Scala are class instances! :D
 
12:26 PM
@райтфолд My Lexer supports simple escape sequences now ;)
 
user1804599
Should I make a method without a do clause automatically abstract or should there be an abstract clause?
 
user1804599
I.e. def f() end vs def f() abstract end.
 
user1804599
The abstract keyword is there anyway since you can have empty abstract classes.
 
hint: the concept of an abstract class is an anomaly
what you want are interfaces
abstract classes are an ugly hack to get interfaces
 
user1804599
@orlp No, because abstract classes can contain data members whereas interfaces cannot.
 
12:35 PM
@райтфолд Can you give an example of a problem that would be elegantly solved by requiring a data member in the interface of a class, that can not be elegantly solved by purely function interfaces?
 
14 messages moved from Lounge<C++>
 
user1804599
@orlp No, but does it matter?
 
@orlp I always thought it was the other way around?
 
user1804599
I'm doing Java interop, and not supporting some Java features would make it impossible to use some Java libraries for no good reason.
 
Now that Java 8 interfaces can have method bodies, the distinction becomes less clear.
 
user1804599
12:37 PM
@FredOverflow The only difference real is non-static data members.
 
If you want interfaces with non-static data members, use Scala traits ;)
 
@FredOverflow I don't think so
 
What if you want implementation in an abstract class?
Every interface can be simulated with an abstract class, but not the other way around.
Of course, you can't inherit from multiple abstract classes.
 
user1804599
Few problems can be solved elegantly with OOP anyway, since few problems require adding new data types and many problems require adding new subroutines.
 
@райтфолд FP and ADTs and PM to the rescue!
 
user1804599
12:40 PM
That said, some problems are extremely elegantly solved by OOP.
 
@райтфолд GUIs?
 
user1804599
I'm currently working on an uptime monitor system. I often want to add new monitors but there are very few things you can do with them; the only interesting thing is starting them, stopping them and getting events out of them. This is a very fixed interface which I don't need to extend, but I want many implementations of it.
 
Why is every Java object a monitor?
 
user1804599
No idea, but it's convenient.
 
user1804599
And probably more efficient than most people think. I would be surprised if monitors weren't created lazily.
 
3:44 PM
0
Q: Is my style of coding - using static object with non-static getter - causing 'memory leaks' or 'performance issues' in my Java app on Heroku

AnkurI'm running Play Framework 1.2.7 on Heroku, and my app is only functioning because I've rigged it up to restart every ten mins. I would like to get to the bottom of this problem and I suspect the following aspect of my code is the issue. I hit upon a certain style of coding which involves using...

 
@райтфолд Any suggestions on how to make my printf sanitizer more functional (as opposed to imperative, not dysfunctional)?
 
user1804599
 
@райтфолд Of course, regex to the rescue :)
@райтфолд Fails for the input string %d%%. because it finds the "illegal" %. sequence.
 
4:51 PM
1
Q: Why to double check the singleton intantiation

jayendra bhattIn this link i found the singleton intantiation as below: public static Singleton getInstanceDC() { if (_instance == null) { // Single Checked (1) synchronized (Singleton.class) { if (_instance == null) { // Double checked ...

 
user1804599
5:20 PM
@FredOverflow Use foreach instead of isEmpty! :D
 
user1804599
@FredOverflow Use libclang.
 
user1804599
It can give you a C AST and it can emit diagnostics for these sorts of things.
 
5:47 PM
@райтфолд No, I'd rather do it like this ;)
 
user1804599
Nice!
 
user1804599
The phase thing works out very well.
 
user1804599
I'm now implementing it.
 
cool
 
user1804599
6:02 PM
I wonder whether null is a valid value for an abstract type.
 
user1804599
scala> trait A { type X }
defined trait A

scala> def f[T <: A](x: T#X) = 42
f: [T <: A](x: T#X)Int

scala> f(null)
<console>:10: error: type mismatch;
 found   : Null(null)
 required: ?#X
Note that Null extends Any, not AnyRef.
Such types can participate in value classes, but instances
cannot appear in singleton types or in reference comparisons.
              f(null)
                ^
 
user1804599
@FredOverflow A method can be abstract or native, but not both. How would you deal with this?
 
user1804599
Two Booleans would allow for invalid combinations.
 
user1804599
There are more invalid combinations.
 
user1804599
For example, an abstract method cannot be synchronised.
 
user1804599
6:11 PM
But a native method can.
 
user1804599
There are many allowed combinations.
 
6:44 PM
@райтфолд Have a bit for each modifier and then a LUT that tells you which combinations are legal.
Or do you have more than, say, about 10 modifiers?
 
user1804599
7:09 PM
@FredOverflow abstract, native, override, static, strictfp, synchronized, virtual.
 
user1804599
And the possible combinations seem arbitrary.
 
user1804599
Although it's probably easy to implement with some subset assertions.
 
user1804599
val illegalCombinations = Set(
  Set(Abstract, Native),
  Set(Abstract, Override),
  Set(Static, Override)
  // ...
)

for (illcomb <- illegalCombinations) {
  if (illcomb subsetOf modifiers) {
    diagnose(Error, s"illegal combination of modifiers '${illcomb.mkString("', '")}'", method)
  }
}
 
user1804599
Like that. :)
 
7:27 PM
@райтфолд Or just write the LUT with 128 entries yourself ;)
 
user1804599
No. :v
 
What do you like better, an if statement nested inside a for comprehension, or a for comprehension with an if guard?
 
user1804599
 
user1804599
@FredOverflow Depends on whether there are multiple lines in the for comprehension.
 
user1804599
@FredOverflow does the subset of C you're compiling allow arbitrary pointer arithmetic?
 
7:36 PM
int a[10];
int * p = a + 0     // ok
int * q = a + 9;    // ok
int * r = a + 10;   // ok
*r;                 // error
int * s = a + 11;   // error
int * s = a - 1;    // error
int i;
&i + 1;             // error, although standard C allows this
 
user1804599
Is Vector[String] enough to represent any fully qualified Java name unambiguously?
 
Define "unambiguously" ;)
 
user1804599
So foo.bar.Baz would be Vector("foo", "bar", "Baz").
 
user1804599
And the same name never refers to two different classes.
 
user1804599
> The Java language allows class identifiers to be obscured by package identifiers. In your case the class com.xx.a is obscured by the package com.xx.a.
 
user1804599
7:38 PM
3
A: Java class name same as the nested package name

aioobeThe Java language allows class identifiers to be obscured by package identifiers. In your case the class com.xx.a is obscured by the package com.xx.a. From the Java Language Specification: 6.3.2 Obscured Declarations A simple name may occur in contexts where it may potentially be interp...

 
user1804599
Interesting.
 
Imagine how much the world would suck without stack overflow.
We'd be asking on Quora and chatting in IRC.
// Time for some bike-shedding, which do you prefer?
boolean is_lvalue = true;
value_category cat = LVALUE;
 
user1804599
lol
 
user1804599
def findJavaClass(name: Name)(implicit ctx: Context[_]): Option[java.lang.Class[_]] =
  try {
    Some(ctx.classLoader.loadClass(name.mkString(".")))
  } catch {
    case _: ClassNotFoundException => None
  }
 
user1804599
Beautiful!
 
7:48 PM
mkString is one of my favorite functions.
 
user1804599
def findClass(name: Name)(implicit ctx: Context[ClassFindingPhase]): Option[Class[ClassFindingPhase]] =
  findJavaClass(name) map { javaClass =>
    Class(null, null, Some(javaClass))
  }
 
user1804599
Now the interesting part: finding classes defined in source files.
 
Your phasing approach seems interesting, maybe you should write a paper about it?
 
user1804599
:v
 
user1804599
Perhaps.
 
7:49 PM
Do you like writing papers? I feel the complexity of writing a paper is bigger than O(n), where n is the number of pages. More like O(n^2).
 
user1804599
case class Class[P <: Phase](bases: P#BaseList,
                             methods: P#MethodList,
                             javaClass: Option[java.lang.Class[_]])
 
user1804599
During the class finding phase, P#BaseList and P#MethodList are still abstract, so null is a completely safe thing to do.
 
> Phasing out the classic approaches to static analysis
 
user1804599
Since you can't do anything with the bases and methods anyway since their most specific concrete type is Any.
 
^ suggested title
 
user1804599
7:52 PM
scala> case class A(x: String)
defined class A

scala> A(null).toString
res0: String = A(null)
 
user1804599
Nice!
 
user1804599
Imagine that throwing an NPE, lol.
 
user1804599
Debugging would be an immense pain.
 
user1804599
@FredOverflow I'll probably write a blog post about it.
 
awsum
 
user1804599
7:53 PM
Ok, so how do I find all files ending with .mill in the current class path?
 
FileFilter or something?
 
user1804599
> Returns all resources loadable from the current class path, including the class files of all loadable classes but excluding the "META-INF/MANIFEST.MF" file.
 
user1804599
I should put that in a lazy val!
 
user1804599
@FredOverflow what is the most elegant way to sequence options?
 
Depends on the language. Probably comprehensions, if that works.
 
user1804599
8:00 PM
++
 
What is option++option?
 
user1804599
scala> Seq(None ++ None, Some(1) ++ None, None ++ Some(2), Some(1) ++ Some(2))
res0: Seq[Iterable[Int]] = List(List(), List(1), List(2), List(1, 2))
 
user1804599
Meh.
 
user1804599
Ah, I found it.
 
Well, what would you like Some(1)++Some(2) to evaluate to instead?
 
user1804599
8:02 PM
scala> Seq(None orElse None, Some(1) orElse None, None orElse Some(2), Some(1) orElse Some(2))
res1: Seq[Option[Int]] = List(None, Some(1), Some(2), Some(1))
 
user1804599
8:13 PM
def findClass(name: Name)(implicit ctx: Context[ClassFindingPhase]): Option[Class[ClassFindingPhase]] =
  Stream(findClassFromSource _, findClassFromJavaClass _).map(_(name)).reduce(_ orElse _)
 
user1804599
The only problem is that this isn't lazy enough.
 
user1804599
It calls both functions.
 
I thought Streams were lazy?
 
user1804599
Yes, but _ orElse _ isn't AFAIK.
 
user1804599
The parameter to orElse is by-name, Function2#apply's parameters aren't.
 
user1804599
8:15 PM
@FredOverflow + and - are just identifiers!
 
user1804599
scala> class +-[+ -, - +](+ : +, - : -)
defined class $plus$minus
 
@inline final def orElse[B >: A](alternative: => Option[B]): Option[B] =
  if (isEmpty) alternative else this
 
user1804599
Beat that, Java!
 
looks pretty lazy to me
 
user1804599
Yes, but _ orElse _ is a lambda.
 
user1804599
8:16 PM
And lambdas are of one of the function types.
 
user1804599
And function types have an apply method that takes everything by value.
 
user1804599
In fact, it will evaluate everything in the stream, since reduce consumes everything.
 
user1804599
I have a better idea.
 
user1804599
def findClass(name: Name)(implicit ctx: Context[ClassFindingPhase]): Option[Class[ClassFindingPhase]] =
  Stream(findClassFromSource _, findClassFromJavaClass _).collectFirst(Function.unlift(_(name)))
 
user1804599
This is lazy. :)
 
user1804599
8:19 PM
I wish collectFirst took T => Option[U] instead of PartialFunction[T, U].
 
user1804599
Function.unlift is ugly.
 

« first day (774 days earlier)      last day (119 days later) »