« first day (54 days earlier)      last day (839 days later) » 

5:26 AM
0
Q: How to count the num of instances created, using a static function in MATLAB?

MATLAB newbieI am learning OOP in MATLAB after C++. I am trying to create a static function to get the numOfInstances created for a class. Also, changes in one object should reflect the changes in other objects . Below is my code: classdef (Sealed) Student < handle properties (GetAccess = 'public', Se...

 
 
13 hours later…
6:32 PM
@Zoidberg All hail the Java Sucks room!
 
user142019
> All
 
Today a colleague came into my office with an inheritance problem, and I convinced him to use the Strategy pattern instead.
Fuck inheritance!
 
user142019
What is the strategy pattern.
 
user142019
I got invited for an extra class about design patterns because of my skills. For school.
 
user142019
I declined because I'm afraid of singletons. :v
 
6:35 PM
In computer programming, the strategy pattern (also known as the policy pattern) is a software design pattern, whereby an algorithm's behaviour can be selected at runtime. Formally speaking, the strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. For instance, a class that performs validation on incoming data may use a strategy pattern to select a validation algorithm based on the type of data, the source of the data, user choice, and/or other discriminating factor...
 
user142019
> whereby an algorithm's behaviour can be selected at runtime.
 
With interfaces. And classes implementing those interfaces.
 
user142019
Aka polymorphic functions: retarded edition.
 
I don't call that "inheritance", if that was your point.
 
user142019
Use std::function you scrub. :v
 
6:37 PM
Practically every Design Pattern can be viewed as [awesome language feature missing from Java] retarded edition.
3
 
user142019
Oh Java.
 
user142019
LOL
 
But what if you need, I don't know, 5 functions? Do you use 5 std::functions? Or do you write an interface with 5 operations?
 
user142019
std::function<R(T1, T2)> pick_strategy(U some_context) {
    if (some_context == 0) return [] { … };
    if (some_context == 1) return [] { … };
    if (some_context == 2) return [] { … };
}
 
user142019
@FredOverflow oooh wait.
 
user142019
6:40 PM
A struct with five std::functions will do just fine.
 
user142019
But anyway, I can't imagine calling that (interface with five functions) "strategy pattern".
 
user142019
Because that would mean that basically any kind of polymorphism through interfaces would be strategy pattern.
 
It depends on the intent. The State pattern has the same UML diagram as the Strategy pattern, for example, but it's still a different pattern.
 
user142019
UML: Ur Momma LOL
 
user142019
UML gave me nightmares.
 
user142019
6:47 PM
I missed my second chance for the UML test at school. xD
 
user142019
I missed the test the first time.
 
@Zoidberg Do you know what Simon PJ recommends instead of UML?
 
user142019
Signatures?
 
yes :)
 
user142019
Then I will now answer your question.
 
user142019
6:52 PM
@FredOverflow Yes.
 
user142019
public static void Main(string[] args) {
    stackoverflow.com
    Console.WriteLine("Hello, world!");
}
 
user142019
C# has URL literals!
 
It's a label followed by a comment. Big deal ;-)
 
user142019
Y u know. :(
 
6:53 PM
It's in the "Java Puzzlers" book IIRC.
 
user142019
Java has labels?
 
Funny that unreferenced labels are allowed.
Sure, for switches and breaks.
 
user142019
Oh.
 
user142019
In Go it's not allowed to have unused variables. :P
 
user142019
Except for _ which is similar to Haskell.
 
6:54 PM
Which is probably a good thing.
 
user142019
Yes.
 
user142019
Because Go has no exceptions.
 
What about unused functions? :)
 
user142019
So you often return T, Error.
 
Pair?
 
user142019
6:54 PM
Go allows multiple return values.
 
user142019
x, err = myFunction()
// must use err otherwise error
 
Ah, interesting.
 
user142019
Go is quite nice but oh so ugly.
 
lol
Gotta take a shower and stuff.
 
user142019
At least it's illegal to put { on a newline in most cases in Go. :)
 
user142019
6:57 PM
Because of automatic semicolon insertion.
 
user142019
@FredOverflow Good luck.
 
7:16 PM
@Zoidberg The amount of retarded stuff Java devs invent because they don't have high-order methods is too damn high
 
@Zoidberg Fortuna was on my side, I didn't die in the shower.
@BenjaminGruenbaum At least Java 8 will have closures.
 
user142019
Instead, you drowned in the hydrated towel while drying yourself.
 
user142019
@FredOverflow will it also have var/auto?
 
@FredOverflow I'll believe it when I see it :/
 
user142019
If not, then Java is still not worth it.
 
7:20 PM
@Zoidberg It's supposed to have type inference, yeah
 
Of course not, Java devs fear dynamic typing, and they don't understand that var/auto is still strongly statically typed :)
 
But you can say Map<String, Whatever> x = new HashMap<>(); since Java 7. It's kinda backwards, but better than nothing.
@BenjaminGruenbaum The C# people had the same unfounded fears.
 
@FredOverflow It's very backwards. I want the language to infer the type of x, what they have is 'somewhat shorter syntax to feel like the cool guys'
 
user142019
@FredOverflow it's a joke.
 
user142019
7:22 PM
@FredOverflow C# has var and even dynamic.
 
@FredOverflow Yet C# people have 'var' and 'dynamic'
 
user142019
The latter is for real dynamic typing.
 
Look, nobody is arguing that C# kicks Java's arse.
 
user142019
It even defers overload resolution to runtime (eliminating need for retarded visitor pattern WIN).
 
@BenjaminGruenbaum dynamic came at least one version number later than var.
 
7:23 PM
@FredOverflow Yeah, dynamic is 4 and var is 3 iirc
 
I would love to continue this conversation, but I'm late for watching Friends with someone special :)
cu guys
 
user142019
Bye.
 
user142019
Good luck.
 
user142019
Don't drown.
 
In the snow? Could happen :)
 
7:24 PM
I'm just here whenever I hear people talking about how 'clever' Java is and need to blow off steam :P
It's 'scalable' and 'enterprise', usually their winning argument is 'It's the only language I know because I learned it in college and I got a crappy job doing Java afterwards'
It's also really secure, not a single critical security flaw was found in Java in forever... if forever is 19 days... java-0day.com
 
user142019
Java is not scalable, whatever that means.
 
user142019
If you want languages that make it easier to write software that scales to multiple machines, try Erlang, Haskell or one of the billion other functional languages. Not Java.
 
Of course it's scalable, didn't you see how scalable FizzBuzz is in Java? (hint very, they have singletons , facroties and interfaces)
 
user142019
If you mean shit like easy to extend existing software, well
 
user142019
7:29 PM
Haskell and Erlang would still do the job very well
 
user142019
even Ruby or C++.
 
The only problem with Haskell is that I can't find a job coding Haskell :(
 
user142019
:P
 
user142019
Erlang is becoming more and more popular these days.
 
I read "Learn you a Haskell", did all the exercises and was like "Fuck yeah! That's fun, I'm going to do that", then I looked for Haskell developer ads and was like "Oh, fuck, nvm"
I really like F# too. I mostly do JavaScript though, it still needs plenty of stuff but it's getting there, and I also like C# because it lets me mess with lambda expression trees easily.
 
user142019
7:33 PM
Did you try CoffeeScript?
 
Erlang looks fun, probably the train of thought of facebook when choosing to use it for their chat was "WTF have we done?!?? Look at all this horrible PHP... That is so bad we had to write a compiler for it... wonderwhat would make up for it?"
 
user142019
Erlang is quite fun.
 
user142019
It's a completely different way of writing programs.
 
user142019
(Even completely different from how you would do it in Haskell.)
 
I like CoffeeScript, it's nice, compact, does scoping better than JS. I don't get to use it much because I work in an environment where I have to write a lot of new code other people would have to later maintain
 
user142019
7:35 PM
I once wrote a functional library for CoffeeScript with some functions from Haskell.
 
So I hear (About Erlang), I should really give it a try. I'm currently trying to pick up Rebol (really fun, and the chat room here is great!) and Clojure (I'm pretty ashamed that I don't know properly know a dialect of lisp well enough yet, and I actually might need it for my research)
Anyway, I'm off to "drink responsibly and moderately". TTYL.
 
user142019
bye
 
9:44 PM
2
Q: Java Singleton.getInstance() returns null?

DogI have this singleton I'm trying to use, but getInstance can apparently return null: class Singleton { public static final String K_LEVEL = "level"; static Singleton instance = new Singleton(); private int level; static Singleton getInstance() { return instance; } ...

 
^ That's awesome
Integer.getInteger , and on top of that it throws NullReferenceException HAHA, that's Java in a nutshell
 

« first day (54 days earlier)      last day (839 days later) »