« first day (1946 days earlier)      last day (3371 days later) » 
00:00 - 22:0022:00 - 00:00

22:10
singleton alert!
You might want to answer that one
I honestly don't understand the fuzz about singletons....
I mean they are just globals
josh wrote an article about it
and I can understand people not wanting multiple instances of same class being created
can't recall the link though
@Almo right now I'm struggling with globals too
but just because they might cause problems later doesn't mean you shouldn't use them altogether
josh has many valid points about singletons
I remember we once had a long conversation about'em
22:14
probably twice
I meant me and josh :P
i meant you and josh
:D
maybe twice then :D
"I mean they are just globals" that's exactly what the fuss is. most of the time people should be using static things to get exactly the same functionality, but they overthink the problem and use a singleton instead.
the only thing a singleton can do that static things can't is automatic initialization, and that's only in some languages, mainly C++
something that requires automatic initialization in C++ is a totally valid use case though, which means singletons aren't inherently evil
22:32
@IcyDefiance it's not automatic... but lazy initialization
I mean every object is automatically initialized right?
If they are static, yes.
(in the global scope, including static class variables)
yeah what I mean is C++ doesn't have a constructor that runs the first time you access a static variable. you can't do any complicated logic there like you can in a singleton.
C# does have a static constructor, so there is literally no reason for a singleton to ever exist in that language.
singletons have one big benefit though
when you are abstracting a hardware and you are sure only one instance of that hardware exist
you know only one instance of a static variable will exist too
or a whole static class in C#
but certain misguided programmer might create another instance of your class, and break everything
22:36
you can't create another instance of a static class. it's not possible.
well then C# static classes are just singletons
in C++ static classes doesn't exist, so you're right there, but C# just doesn't have that problem
no, C# static classes aren't singletons. singletons are an overly complicated structure with exactly the same functionality as a static class. that's my entire point here.
that is the difference. A static class cannot be instanced
22:38
his point is that you don't need to instance it.
I think
@IcyDefiance I can't even imagine how is 10 lines of code overly complicated stuff?
you get the same functionality
I use them. BUt I see his point.
if you make an abstract factory, you need instances because you don't know what class you are calling before-hand
they are abused though. most times a singleton is the wrong choice
class Singleton
{
    public static readonly SingletonB Instance = new SingletonB();

    public void Test()
    {
	// Code runs.
	Console.WriteLine(true);
    }
}

static class BetterThanSingleton
{
	public static void Test()
	{
		Console.WriteLine(true);
	}
}
there's two classes with exactly the same functionality
@IcyDefiance not really
you can create multiple instances of first one
22:42
The Singleton does not get created if you never use it.
I thought that was one of the reasons to use them
that they might not get created
@Ali.S you're right, there should be a constructor in the singleton that throws an exception when creating a second copy, but the point remains: why do that?
a static class does the same thing. just use static.
@IcyDefiance maybe because it's not C++?
oh hey, you do get it. so why are you pretending to argue with me?
class singleton
{
static singleton* getInstance(){static singleton* instance = new singleton(); return instance;}
private:
singleton(){};
}
@IcyDefiance i'm saying that static class is just a fancy wrapper over a idea, which was not hard to implement in first place
even in your example, you can keep the private constructor, scrap the singleton*, and just use only static variables
that would be functionally identical without the extra pointer
22:46
@Ali.S You'd have to add a static keyword on your getInstance line :)
also without the requirement to call getInstance() every time you want to use it
actually the code you pasted is a perfect example of misuing a singleton, lol
@IcyDefiance Why is that?
like I just said, keep the private constructor, scrap the singleton pointer, and just use static variables and functions. same functionality, less complicated, and it won't require you to call getInstance() all the time.
if you actually put some complicated logic inside the private constructor, then that would be a good use case for a singleton. otherwise don't bother.
And you call everything Singleton::DoStuff( x );?
(when you use it)
@IcyDefiance that's even worst... I mean what if after some time you added a new hardware, and now you need to have multiton instead of singleton?
22:51
Singleton::DoStuff(x):
vs
Singleton::getInstance().DoStuff(x);
exactly the same functionality, but one is more complicated.
this is 100% objective, not a matter of opinion. not sure why this is so hard to get.
Why get an instance if you are referencing the class explicitly?
Yeah, well if your singleton has multiple class attributes, it's multiple static class attributes VS one static variable. And you can do auto sing = Singleton::getInstance(); sing->doSttuff(x); which you can't if you declare everything as static.
db = MySQL::getInstance();
@IcyDefiance it's not complicated (as far as I can see) just few more characters to type!
and it's less versatile.
replace MySQL with another database implementation
22:56
in that case, it becomes
Singleton::DoStuff(x);
Singleton::DoMoreStuff(y);
vs
auto sing = Singleton::GetInstance();
sing->DoStuff(x);
sing->DoMoreStuff(y);
or 10 potential db implementations
still the same functionality, singleton is still more complicated
@FuzzyLogic that would be the one and only exception, which I've mentioned several times already. MySQL likely does some initialization things the first time an instance is created, to connect to the database and so on. that can't be done neatly with static methods.
that's not the point, it's separation of concerns
although I think that would be weird, because you wouldn't be able to close a connection...
yeah I'd still be surprised at that design
the rest of the code doesn't care if you are using MySQL or CSV
or shouldn't need to care
23:00
oh I see. that's actually a good point.
a rare use case, but still one that exists
@IcyDefiance I think the main concern, as you say, is about the construction. When is it constructed?
Why do people say "nuke" instead of microwave? It's not ionizing.
That's why I think we should refer to the microwave as the 2.4, since that's what frequency it uses.
"Yes, just stick it in the 2.4 for for 3 minutes".
using singletons should be rare. it's one of those things that is abused more often than not because of a lack of understanding when to use them and what should be used instead.
@AidanMueller because a microwave uses radiation. electromagnetic radiation, not nuclear, but most people don't know the difference.
Yeah, but I still think it's weird.
23:07
I've been taught to think of them like globals. Do use them when needed but if you are considering it, think HARD because it's uaully the wrong decision
@AidanMueller Radiation, Really wasn't generally usable until the late 60s - and by that point radiation meant nukes to the US population.
and yeah FL you're exactly right
People say radiation. Really, visible light is radiation.
@Noctrine Makes sense.
Duke Microwavem 3D would have been less popular I guess...
@AidanMueller And so is sound, and then you know - just a general byproduct of being.
23:09
the way I see singletons is like, if you're trying to walk across a room and grab something on the other side, but you refuse to just walk straight across the room. instead you skirt the outside, next to the walls, because it feels like the problem shouldn't be as easy as just walking straight.
3
But following WWII, Radiation is "Radiation"
now if there's a hidden trap in the middle of the room then great, you have a reason to walk around it, but that's really rare. most of the time just walk straight. it's much easier.
I use singletons to 1) force that there is only one instance available and 2) avoid passing shit around (generaly because I only need one instance)
user4704
@Almo That's because it's gone.
@AlexandreVaillancourt and both of those are the wrong reasons, lol. we just went over this.
whatever, I'm not gonna repeat it all
23:12
@AlexandreVaillancourt inb4 microwave simulator 2015.
@IcyDefiance I was probably AFK :)
you were replying to me...
I just don't use singletons. The first time I saw one I thought it was retarded gits.
@IcyDefiance lol really? hmm... something's wrong then
17 mins ago, by Icy Defiance
in that case, it becomes
Singleton::DoStuff(x);
Singleton::DoMoreStuff(y);
vs
auto sing = Singleton::GetInstance();
sing->DoStuff(x);
sing->DoMoreStuff(y);
that sums it all up
23:14
I was like "why would you have a static function that returns an instance?"
Ah, yeah, but I still have the concern of when is your static initialized. It can't be constructed.
there you go. that's the right reason to use a singleton. if the construction actually matters.
Yes. Sorry, it was implied in my two reasons :)
When I write a class that will be instanciated, but a method does not use any class attributes, I write it as as static method.
But yeah, if a class only offers services without needing an explicit initialization of the state, sure, static all the way!
I just have to emphasize that "I only want one instance" is a horrible reason to make a singleton, because sooo many people have turned that into dogma and started writing singletons everywhere when things really should just be static.
and that dogma created an opposing dogma, "all singletons are evil"
equal and opposite reaction I guess
oh well, back to advent of code. gotta finish today's problems.
Yeah. Generally, I'll have a "singleton manager". This will be the only 'enforced singleton', from which you'll be able to fetch pseudo-singleton: instances that will be unique, but not 'unique enforced', if I may put it this way.
23:21
can't use linq this time without being completely evil. so sad. :(
There can only be one taco.
I think I believe in the all singletons are evil dogma.
I kind of believe that objects should exist just fine by them self. If they don't, you are misrepresenting the object.
i only ever have 1 singleton in anything i write these days ... my DI provider
usually ninject
then i build my stacks using conventions so even that is kept lightweight
It seems as though there is a bit of a "object oriented programming is evil" dogma these days too.
23:29
wait...really? but everything is object oriented to some extent.
I would say that there is actually a "abusing OO programming is evil" fact.
oop is considered best practice round here
that's because it's too dogmatic
you can things like over user a particular concept
like i've seen inheritance stacks 20 types deep
there's just no need for excessive inheritence
often there is no need for OOP at all but OOP languages don't like to cooperate with other programming paradigms
23:31
yeah I've never worried too much about following all the oop design pattern stuff. most of the time I just do what makes sense and it works fine.
not sure I'd call it evil, but maybe overrated
design patterns in general are probably overrated. if it makes sense it's probably good.
user4704
Apparently the chat quicklink only works in comments.
user4704
Not post bodies.
user4704
@Wardy Excessive inheritance isn't always the problem, sometimes it's just dumb inheritance one level deep.
@IcyDefiance I am starting to move to "does it make sense for this to be an object".
@JoshPetrie yeh seen that too
or literally no inheritance where something should be
user4704
23:35
@Almo I replied anyway though
The reason why
cool :)
Nov 30 at 17:05, by Tyyppi_77
Java sucks.
is because everything has to be an object.
@AidanMueller thats not the reason ... c# is pretty awesome and that has the same rule
yeah I don't think that's really a bad thing. like in C# you can make an extension method for an int and be like "if (i.IsOdd())"...not that you should actually do that, but you can, lol
23:39
Hmm. Sounds kind of cool.
I don't like C# because I associate it with MS.
it's a shame that it doesn't work too well on linux yet, but as a language it's by far the nicest one I've ever used. I'm spoiled by it.
What's your opinion on CPP?
MS is working on making it cross-platform though. There's some beta stuff out there like vnext.
@IcyDefiance c# runs fine on linux
it runs on linux, but "fine" is situational. depends on what the program is.
23:42
?
like the ASP.NET MVC stuff doesn't work at all
aspnet is a mess atm
even on windows thats a shit storm
especally when you consider all that web api stuff and odata framework they have
all aweseome in concept but dably engineered
I'm not really going with it until there is a good FLOSS alternative. I like my programming stuff to be FOSS.
FOSS?
@AidanMueller If C# didn't exist I'd probably use C++ all the time. It's sometimes annoying to work with, but nothing horrible.
except linker errors...
23:44
@IcyDefiance me too i suspect ... and i don't know c++ pretty much at all
i just know i wont go near java after that whole issue with salesforce a few years back
@Wardy FOSS = Free Open Source Software
C# is basically proprietary, like Java. You are at the whim of Microsoft
@FuzzyLogic aspnet + mvc is
roslyn (the new cross platform compiler for c#) is also FOSS
roslyn is open source, but not really free
its completely free
go to github download the source, do what you want
yea, MS has at least made the language spec an open standard
so it's not a lock-in like Java
23:49
oh shit, Roslyn is released under Apache 2.0
it really is free
no idea why people get hung up on paying licence fees to microsoft
that's pretty cool
it's not the paying part, it's the hands-tied part
i mean ... these days its more expensive to have al inux box than a windows one
@FuzzyLogic the entire plan from day 1 with c~ was to make a 4th gen version of c++ with java like syntax
hands tied?
@FuzzyLogic no look up Apache 2.0. it's more free than most FOSS. way better than the GPL crap.
23:50
vendor lock-in
it's a really permissive license
@FuzzyLogic C# is not vendor locked as a language in any way
nor is the compiler for it
if roslyn catches on, that would be good but right now it's still MS
its a completely free and open standard
@FuzzyLogic created by yes, but there's no lock in
the latest version of VS is using roslyn, isn't it? I'd say it already caught on.
23:52
@IcyDefiance it can do ... dependso n the version of the clr you tell your code to compile against
you can actually choose not to use it if you prefer
it gets a bit confusing ... the clr has a version and the c# language has a version
the roslyn compiler was built to allow clr compliant compilation of c# 6 and higher
for .net 4.0 or later
regardless, if you can take any C# code and compile it against roslyn, and you can modify and redistribute roslyn however you want, and even profit from your modifications, that seems pretty free to me
@IcyDefiance i believe apache licencing allows for that
yeah it does
which is what roslyn is shared under
you can even commit core code changes to it through github i believe
become a contributor
yea, C# is getting there
23:55
all that said, it's still a little iffy on linux, which is a shame. that's pretty much the only reason to not use it right now, and it should change over the next couple years.
well not the only reason
iffy?
explained that already. not everything works perfectly.
write better code?
dude. scroll up. I already gave you an example that can't be solved by doing anything "better".
like the ASP.NET MVC stuff doesn't work at all
that's not true
I have deployed mvc sites on my linux based nas
running mvc on apache is ... interesting
but i can assure you it does work
23:58
huh, maybe apache does something different. I spent like 2 weeks trying to make it work with nginx and it just didn't.
not sure ... i don't know anything about nginx but it works pretty well with apache
mono's efforts mainly went toward the other structure, I forget what it's called.
00:00 - 22:0022:00 - 00:00

« first day (1946 days earlier)      last day (3371 days later) »