Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

New Yorp New Yorp posted:

Does "modifying your program to display a political message every time it's run" constitute a coding horror? There's even a GitHub issue about it that's just waiting to turn into a shitfest.



not really seeing the problem here

Adbot
ADBOT LOVES YOU

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
vim asks me to donate to Uganda on startup and has done so for like, decades, so that seems fine.

fishmech
Jul 16, 2006

by VideoGames
Salad Prong

Asymmetrikon posted:

vim asks me to donate to Uganda on startup and has done so for like, decades, so that seems fine.

Huh, I wonder how much Vim users have donated by now.

Fergus Mac Roich
Nov 5, 2008

Soiled Meat
I prefer my software to be free as in "suggested donation is $10"

hyphz
Aug 5, 2003

Number 1 Nerd Tear Farmer 2022.

Keep it up, champ.

Also you're a skeleton warrior now. Kree.
Unlockable Ben

Hammerite posted:

~~~HYPERLAMBDA~~~

There's no way it can possibly be serious, the author is a masterful troll.

I have recently had to persuade a research group NOT to design an entire language around this concept. It's definitely an ongoing thing.

brap
Aug 23, 2004

Grimey Drawer
We've been maintaining a client's contracted web app project which uses a bespoke resource bundling system written by the grad students who made the web app. They write a bunch of script tags in XML and put them in named groups. They reference groups from within other groups, then reference a group in a page template, and basically either puke out all the script tags into the page or concatenate the referenced scripts together in order in the end. This happens every time a page template is rendered.

Tracking down why the bundler quits without reporting any problems after writing about 80% of the concatenated script has been a thrill.

hyphz
Aug 5, 2003

Number 1 Nerd Tear Farmer 2022.

Keep it up, champ.

Also you're a skeleton warrior now. Kree.
Unlockable Ben
Oh, wow. Based on the above, I googled Hyperlambda and ended up at Hyperlambda.com, which is a blog for.. a rather more sensible person who's writing an event flow DSL in Scala, which is actually useful for the research we're doing.

Then I had to find the page for the guy who actually wanted Hyperlambda to be a programming language, and it's here: https://github.com/polterguy/phosphorusfive . This is Hyperlambda:

pre:
p5.web.widgets.create-container
  parent:content
  widgets
    sys42.widgets.tree
      _crawl:true
      _items
        root:/
      .on-get-items
        p5.io.folder.list-folders:x:/../*/_item-id?value
        for-each:x:/-/*?name
          p5.io.folder.list-folders:x:/./*/_dp?value
          p5.string.split:x:/./*/_dp?value
            =:/
          add:x:/../*/return/*
            src:@"{0}:{1}"
              :x:/..for-each/*/p5.string.split/0/-?name
              :x:/..for-each/*/_dp?value
          if:x:/./*/p5.io.folder.list-folders/*
            not
            add:x:/../*/return/*/_items/0/-
              src
                _class:tree-leaf
        return
          _items
It appears to be what happened when Smalltalk and Common Lisp got together and decided to remove all the best features of both. Brilliantly, in the GitHub repository there is no Hyperlambda code that I can see. There is a Hyperlambda interpreter .exe file checked in to the GitHub repository because we apparently do not know what a Release is.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

uncurable mlady posted:

not really seeing the problem here

I feel like mixing politics/religion and software is bad form in general, but especially right now, since the political atmosphere in the US is so strongly polarized.

I don't want this to turn into a political discussion. If no one else is bugged by that kind of thing, then it's just me. :shrug:

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies

New Yorp New Yorp posted:

Does "modifying your program to display a political message every time it's run" constitute a coding horror? There's even a GitHub issue about it that's just waiting to turn into a shitfest.


I expect he'll lock the issue like he did the PR that added in this message.

Master_Odin fucked around with this message at 16:27 on Mar 16, 2017

HFX
Nov 29, 2004

Master_Odin posted:

I expect he'll lock the issue like he did the PR that added in this message.

Honestly, open source code is free speech. As such, you can add whatever you want when it is your own project. People are free to fork it and start their own project free of messages. However, not every code project needs to be corporate clean less you piss off someone. I personally would not include such a directed message (at least not in such an obvious manner), but others are free to do what they want.

HFX fucked around with this message at 17:07 on Mar 16, 2017

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I mean, obviously the dev is going to alienate some people, but they decided its worth it to them, so good for them I guess.

Personally, I wouldn't choose to use or not use something just because of it...it's not like I'm surprised a dev has a political opinion, and if it's a political opinion I disagree with it's not like I'm paying them money or something.

Though, I guess by increasing his download count or whatever I'm kind of indirectly "paying" the dev...

lifg
Dec 4, 2000
<this tag left blank>
Muldoon

Ghost of Reagan Past posted:

I once, on a lark, wrote an application that'd create a REST API with Flask from a JSON spec.

I quit when I realized that anything more than simple SQL insert/select and schema updates were going to be nearly impossible to do without building out a DSL that embeds within the JSON.

This guy saw that and said "good idea."

Weird, I did the exact same thing with Flask+JSON, and quit for the same reasons.

antpocas
Jun 30, 2004

IF THIS POST ISN'T ABOUT GLORIOUS SALAZAR YOU MUST BE READING IT WRONG
code:
    public class GenericFactory<T> : IFactory<T>
    {
        private readonly Dictionary<string, Type> storedTypes = new Dictionary<string, Type>();

        public GenericFactory()
        {
            TypeHelper.LoadInterfaceTypesFromAssembly<T>().ToList().ForEach(
                type => storedTypes.Add(type.GetType().Name, type.GetType()));
        }

        public T CreateInstance(string typeName)
        {
            Type t = GetTypeToCreate(typeName);

            Guard.Against<ArgumentNullException>(t.IsNull(), "Couldn't find any implementation to type: " + t.FullName);

            return (T)Activator.CreateInstance(t);
        }

        private Type GetTypeToCreate(string typeName)
        {
            foreach (var type in this.storedTypes)
            {
                if (type.Key.Equals(typeName))
                {
                    return this.storedTypes[type.Key];
                }
            }

            return null;
        }
    }
this is it

this is the worst code i've ever seen

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

antpocas posted:

this is it

this is the worst code i've ever seen

The result of hearing "Lists are slow for lookups, use a Dictionary".

Athas
Aug 6, 2007

fuck that joker

Bognar posted:

The result of hearing "Lists are slow for lookups, use a Dictionary".

That's not the big problem.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Yeah, this is someone complaining that the compiler keeps throwing irrelevant "wrong type" errors at them. They just want to compile and run, dammit, types don't matter anyway.

GPF
Jul 20, 2000

Kidney Buddies
Oven Wrangler

New Yorp New Yorp posted:

I feel like mixing politics/religion and software is bad form in general, but especially right now, since the political atmosphere in the US is so strongly polarized.

I don't want this to turn into a political discussion. If no one else is bugged by that kind of thing, then it's just me. :shrug:

I'm bugged by it, so you're not alone.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

antpocas posted:

code:

    public class GenericFactory<T> : IFactory<T>
    {
        private readonly Dictionary<string, Type> storedTypes = new Dictionary<string, Type>();

        public GenericFactory()
        {
            TypeHelper.LoadInterfaceTypesFromAssembly<T>().ToList().ForEach(
                type => storedTypes.Add(type.GetType().Name, type.GetType()));
        }

        public T CreateInstance(string typeName)
        {
            Type t = GetTypeToCreate(typeName);

            Guard.Against<ArgumentNullException>(t.IsNull(), "Couldn't find any implementation to type: " + t.FullName);

            return (T)Activator.CreateInstance(t);
        }

        private Type GetTypeToCreate(string typeName)
        {
            foreach (var type in this.storedTypes)
            {
                if (type.Key.Equals(typeName))
                {
                    return this.storedTypes[type.Key];
                }
            }

            return null;
        }
    }

this is it

this is the worst code i've ever seen

:vince::vince::vince::vince::vince::vince::vince::vince::vince:

antpocas
Jun 30, 2004

IF THIS POST ISN'T ABOUT GLORIOUS SALAZAR YOU MUST BE READING IT WRONG

Athas posted:

That's not the big problem.
There are many big problems with this code. Iterating over the dictionary to find the key is one of them. Returning this.storedTypes[type.Key] instead of type.Value once you've found it is another.

The Guard.Against<TException> class is pretty nifty, however its implementation uses reflection the find the constructor for TException, and doesn't cache the constructor anywhere, which kind of bothers me.

The extension method IsNull (which is literally public static bool IsNull(this object source) { return source == null; }) is another. (there is also an IsNotNull extension method, its implementation is left as an exercise for the reader).

Using Activator.CreateInstance(Type t) without any assurance that t has a default constructor is asking for trouble as well. Using Activator is just nasty in general.

The biggest problem is in the constructor though. TypeHelper.LoadInterfaceTypesFromAssembly<T> which I didn't bother posting, is scanning the executing assembly for classes that implement the T interface. Then it's creating a new dictionary based on that (but not before creating a List first! it's not as if there's a ToDictionary method or anything) every single time GenericFactory<T> is instanced, even though this needs to be done exactly once for each closed GenericFactory.

TypeHelper.LoadInterfaceTypesFromAssembly<T> shouldn't exist either, but that's beyond the scope of this post.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt


That and, you know, the fact that Activator.CreateInstance has a (String assemblyName, String typeName) overload which makes the class's very existence completely pointless in addition to revolting.

antpocas
Jun 30, 2004

IF THIS POST ISN'T ABOUT GLORIOUS SALAZAR YOU MUST BE READING IT WRONG

NihilCredo posted:

That and, you know, the fact that Activator.CreateInstance has a (String assemblyName, String typeName) overload which makes the class's very existence completely pointless in addition to revolting.
I didn't know about this, oh god it's even worse

john donne
Apr 10, 2016

All suitors of all sorts themselves enthral;

So on his back lies this whale wantoning,

And in his gulf-like throat, sucks everything

That passeth near.
What kind of weird bubble do you have to live in to avoid a DI container in this day and age? Microsoft's been shipping one with every framework for like seven years.

EssOEss
Oct 23, 2006
128-bit approved
At this 100 person company I work for, there are 2 people who understand DI containers and maybe 10 who use them. Plenty of people think DI is hipster weirdness overhead and a bizarre way to define method parameters.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

EssOEss posted:

At this 100 person company I work for, there are 2 people who understand DI containers and maybe 10 who use them. Plenty of people think DI is hipster weirdness overhead and a bizarre way to define method parameters.

Isn't it enterprise weirdness overhead?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Edison was a dick posted:

Isn't it enterprise weirdness overhead?

Kind of.

I think that reaching the point in an application where you need a DI container to manage the dependency graph can be an indication that it's poorly architected and needs clearer delineations between subsystems.

I read it as, "I've made my dependency chain so byzantine and inscrutable that I need to have special software to manage it"

Mr Shiny Pants
Nov 12, 2012
Meh, I am coming around to the fact that DI just makes stuff more complicated and diffuse. Going on all the question on Stack Overflow from people who can't grasp it, it seems needlessly complex.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Dependency injection is what we're talking about, right? It's loving amazing. You use it to make your code testable. Instead of having a hardcoded reference to the database, your query code takes the DB connection as a parameter, and then your unit test code can create a mock or fake DB and send that in instead. Ditto with network calls, references to the filesystem, etc. Your unit tests can do everything in memory, which means they run faster and more reliably, which means you run them more often, which means they're more useful.

Of course there are good and bad ways to do dependency injection, but one of the things IMO almost every developer should be learning is how to recognize where a dependency should be injected vs. implicit.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

TooMuchAbstraction posted:

Dependency injection is what we're talking about, right? It's loving amazing. You use it to make your code testable. Instead of having a hardcoded reference to the database, your query code takes the DB connection as a parameter, and then your unit test code can create a mock or fake DB and send that in instead. Ditto with network calls, references to the filesystem, etc. Your unit tests can do everything in memory, which means they run faster and more reliably, which means you run them more often, which means they're more useful.

Of course there are good and bad ways to do dependency injection, but one of the things IMO almost every developer should be learning is how to recognize where a dependency should be injected vs. implicit.

I wasn't talking about DI, I was talking about using DI containers to manage constructing and injecting the dependencies. I like DI, I dislike DI containers.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Mr Shiny Pants posted:

Meh, I am coming around to the fact that DI just makes stuff more complicated and diffuse. Going on all the question on Stack Overflow from people who can't grasp it, it seems needlessly complex.

I find dependency injection difficult to wrap my head around but I recognise that it's a bit of a personal blindspot. The same way some people find it difficult to understand pointers, or what have you, dependency injection is something I find difficult to grasp.

I've felt at times that I had a good grasp of it, when I've seen an explanation that's particularly compatible with my way of understanding things I guess, but I don't use it enough to keep a handle on it for the next time I need to understand it...

Axiem
Oct 19, 2005

I want to leave my mind blank, but I'm terrified of what will happen if I do

New Yorp New Yorp posted:

I like DI, I dislike DI containers.

It continues to amaze me how many people conflate the two.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

New Yorp New Yorp posted:

I wasn't talking about DI, I was talking about using DI containers to manage constructing and injecting the dependencies. I like DI, I dislike DI containers.

I was reacting to this, to be clear:

Mr Shiny Pants posted:

Meh, I am coming around to the fact that DI just makes stuff more complicated and diffuse. Going on all the question on Stack Overflow from people who can't grasp it, it seems needlessly complex.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Hammerite posted:

I find dependency injection difficult to wrap my head around but I recognise that it's a bit of a personal blindspot. The same way some people find it difficult to understand pointers, or what have you, dependency injection is something I find difficult to grasp.

I've felt at times that I had a good grasp of it, when I've seen an explanation that's particularly compatible with my way of understanding things I guess, but I don't use it enough to keep a handle on it for the next time I need to understand it...

What's hard to understand about this?
Given this:
code:
public interface IDependency {
   void Butts();
}

public class Dependency : IDependency {
   public void Butts() {
   }
}
Using DI:
code:
public class Foo {
   IDependency bar;
   public Foo(IDependency bar) {
     this.bar=bar;
   }
}

public class Main {
   public Main() {
      var dependency = new Dependency();
      var foo = new Foo(dependency);
   }
}
Using not-DI:

code:
public class Foo {
   IDependency bar;
   public Foo() {
     this.bar = new Dependency();
   }
}

public class Main {
   public Main() {
      var foo = new Foo();
   }
}
The idea is that your classes don't depend on concrete implementations of dependencies defined within the class itself, they depend on being given implementations adhering to an interface.

New Yorp New Yorp fucked around with this message at 18:08 on Mar 17, 2017

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

New Yorp New Yorp posted:

What's hard to understand about this?
Given this:
code:

public interface IDependency {
   void Butts();
}

public class Dependency : IDependency {
   public void Butts() {
   }
}
Using DI:
code:

public class Foo {
   IDependency bar;
   public Foo(IDependency bar) {
     this.bar=bar;
   }
}

public class Main {
   public Main() {
      var dependency = new Dependency();
      var foo = new Foo(dependency);
   }
}

Using not-DI:

code:

public class Foo {
   IDependency bar;
   public Foo() {
     this.bar = new Dependency();
   }
}

public class Main {
   public Main() {
      var foo = new Foo();
   }
}

The idea is that your classes don't depend on concrete implementations of dependencies defined within the class itself, they depend on being given implementations adhering to an interface.

Stated differently: constructors exist for a reason, use them.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only
Yeah that's the thing. Dependency injection is just passing your dependencies around as parameters, but then there's​ dependency injection Frameworks that do magic that makes it implicit somehow.

return0
Apr 11, 2007
IoC containers are cool and good in plangs where they are idiomatic (c# and java).

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

New Yorp New Yorp posted:

What's hard to understand about this?
Given this:
code:
public interface IDependency {
   void Butts();
}

public class Dependency : IDependency {
   public void Butts() {
   }
}
Using DI:
code:
public class Foo {
   IDependency bar;
   public Foo(IDependency bar) {
     this.bar=bar;
   }
}

public class Main {
   public Main() {
      var dependency = new Dependency();
      var foo = new Foo(dependency);
   }
}
Using not-DI:

code:
public class Foo {
   IDependency bar;
   public Foo() {
     this.bar = new Dependency();
   }
}

public class Main {
   public Main() {
      var foo = new Foo();
   }
}
The idea is that your classes don't depend on concrete implementations of dependencies defined within the class itself, they depend on being given implementations adhering to an interface.

Well, that's not hard to understand at all, in fact it's extremely simple. But generally when I see an explanation of dependency injection it's explained in abstract terms and crucially, the discussion is bundled up with a whole lot of other terms, like "inversion of control" and "SOLID" that I might be able to understand if they were introduced individually but which are too much to take in when all introduced at once and defined abstractly. I'm best equipped to understand concepts when they're expressed in terms of a prototype - a motivating example - rather than an abstract definition. It doesn't help that I tend to remember dependency injection as meaning the kind of big, complex frameworks that other posters are talking about (as being distinct from dependency injection), because that's what I've seen talked about in discussions at work.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Hammerite posted:

Well, that's not hard to understand at all, in fact it's extremely simple. But generally when I see an explanation of dependency injection it's explained in abstract terms and crucially, the discussion is bundled up with a whole lot of other terms, like "inversion of control" and "SOLID" that I might be able to understand if they were introduced individually but which are too much to take in when all introduced at once and defined abstractly. I'm best equipped to understand concepts when they're expressed in terms of a prototype - a motivating example - rather than an abstract definition. It doesn't help that I tend to remember dependency injection as meaning the kind of big, complex frameworks that other posters are talking about (as being distinct from dependency injection), because that's what I've seen talked about in discussions at work.

DI is a method of implementing IoC. It's just a way of solving the problem "I want to test a thing that gets data from a web service/database/other complex component without actually involving the web service/database/other complex component" or, "I want this thing that gets data from something else to be able to get data from any number of something elses based on some set of criteria, without altering the logic of the thing".

Volguus
Mar 3, 2009

New Yorp New Yorp posted:

DI is a method of implementing IoC. It's just a way of solving the problem "I want to test a thing that gets data from a web service/database/other complex component without actually involving the web service/database/other complex component" or, "I want this thing that gets data from something else to be able to get data from any number of something elses based on some set of criteria, without altering the logic of the thing".

My way of looking at it is as follows: "In order to do my job I need an instance of X. Someone give that to me."
In the example presented above, Foo needs a Bar to be able to do its work. It explicitly asks for it in the constructor, and Main provides it when it makes a Foo. What DI frameworks do is provide that automatically (via the magic that is also known as reflection). All that Main has to do is tell the DI framework: whenever anyone requests an IBar give them an instance of this Bar object. That's all there is to it.
But then, you can't go and say "new Foo()" anymore. You have to go to the DI framework and ask it to make a Foo for you. Then the DI framework will take care of providing all the required dependencies that Foo asks for.

Hughlander
May 11, 2005

One of my favorite systems was a game server holding 10,000 concurrent player connections running on 150 or so threads. The DI system would handle setting up the player classes before processing client input. I.e.: open bank ui is being called, and so the player object and the bank object would be injected. But it would be that players player object cached from a previous call, and we'd context switch away when we saw we couldn't instantiate the bank without a db hit. So it'd make the request and try again when the data came back.

Meanwhile game engineers didn't think of that they just thought, this call requires the player and the bank, ok given that do...

Adbot
ADBOT LOVES YOU

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Hammerite posted:

It doesn't help that I tend to remember dependency injection as meaning the kind of big, complex frameworks that other posters are talking about (as being distinct from dependency injection), because that's what I've seen talked about in discussions at work.

I feel like most tutorials tend to start from a complicated example of everything it can do, instead of just building up from the basics so you can grasp the different layers of functionality

At its most basic level a DI framework just provides stuff - it lets you specify which classes it can instantiate, and then you can ask for one. It can obviously do no-arg constructors, and it can also build objects that require other objects it knows how to make. Sometimes you'll need to specifically tell it how to instantiate a particular class. So long as it can put all the pieces together, it'll work out what needs to be made in what order and out pops the thing you wanted

You don't need to worry about the process, it handles all that for you, and if the dependencies change it'll just do work out how things are connected now. You added a new dependency to a class's constructor? Cool, if the framework knows how to provide that dependency, it'll do it automatically and everything will still work, even if it means the instantiation order has changed. If you do need to change anything, it'll be something in your DI definitions, all in one place

If you like, you can get into fancier stuff, like providing different versions of a particular dependency by specifying different ways to instantiate it. Or scoping stuff so certain objects all share the same instance of a dependency, or whatever. It's all there to help you enforce DI as a pattern and manage all the stuff you need to pass in. Sometimes that stuff and its relationships to other stuff is fairly complicated! It can be a good example of the organisational power of DI frameworks, and how it simplifies complex relationships and lets the computer worry about resolving them, but it doesn't necessarily make for a good introduction to the whole concept

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply