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.
 
  • Locked thread
HoboMan
Nov 4, 2010

so linq looks like it just makes it so you can just write straight sql queries in c# code? i don't see the value

Adbot
ADBOT LOVES YOU

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



HoboMan posted:

so linq looks like it just makes it so you can just write straight sql queries in c# code? i don't see the value

It's two parts as I understand it -- a common standard for writing code that works through collections in a functional/chaining way (the code you posted), and a syntax in C# that lets you write linq queries in a syntax that is reminiscent of SQL.

The first part is just easier to read and write for the most part. The second part I guess is nicer too? I'm not a C# dev.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Soricidus posted:

what could possibly go wrong

"uh, james, ive called you into my office here because it's come to my attention that you've been naming all your variables 'poop' and 'butt'"

Bloody
Mar 3, 2013

HoboMan posted:

so linq looks like it just makes it so you can just write straight sql queries in c# code? i don't see the value

nah, linq lets you use functional programming idioms in .net

some of them happen to be named similarly to similar concepts in sql

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

HoboMan posted:

so linq looks like it just makes it so you can just write straight sql queries in c# code? i don't see the value

nah, you gotta look past the sql-like syntax poo poo. The power is when you have a collection of Turd (like List<Turd>) and you do stuff like:

TurdList.Select(turd => turd.ID.ToString()).Where(turd => turd.Color == Color.Green).ToList().

Normally, if you wanted to extract all the ID's as strings from green Turds, you'd have a foreach loop with if-logic that checks the Color and a ToString() and don't forget your placeholder variables etc.etc.etc.

Or, if you just want to know RIGHT NOW if there are any brown turds:

TurdList.Any(turd => turd.Color == Color.Brown)

And that's just the basic stuff. When you start doing .Join(), .Union(), .Intersect(), and poo poo like that stuff can get weird, man. But it's a good weird, ya know?

JawnV6
Jul 4, 2004

So hot ...
a for loop is like hiring a fancy architect to build your house, then pedantically explaining where you want every individual stud to be placed

linq is saying "i want a kitchen, living room, and master bath" and letting the architect figure out the implementation details

you're specifying "what" you want, not "how" to do it

Bloody
Mar 3, 2013

Finster Dexter posted:

nah, you gotta look past the sql-like syntax poo poo. The power is when you have a collection of Turd (like List<Turd>) and you do stuff like:

TurdList.Select(turd => turd.ID.ToString()).Where(turd => turd.Color == Color.Green).ToList().

Normally, if you wanted to extract all the ID's as strings from green Turds, you'd have a foreach loop with if-logic that checks the Color and a ToString() and don't forget your placeholder variables etc.etc.etc.

Or, if you just want to know RIGHT NOW if there are any brown turds:

TurdList.Any(turd => turd.Color == Color.Brown)

And that's just the basic stuff. When you start doing .Join(), .Union(), .Intersect(), and poo poo like that stuff can get weird, man. But it's a good weird, ya know?

u got your select and where backwards gotta filter then map

HoboMan
Nov 4, 2010

ok these is good examples and i see how this could be cool&good.

did i mention i'm the only software engineer on staff and i don't know poo poo about dicks?

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

HoboMan posted:

ok these is good examples and i see how this could be cool&good.

did i mention i'm the only software engineer on staff and i don't know poo poo about dicks?

https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b

Bloody posted:

u got your select and where backwards gotta filter then map

Woops. I am bad at this, so

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

HoboMan posted:

ok these is good examples and i see how this could be cool&good.

did i mention i'm the only software engineer on staff and i don't know poo poo about dicks?

you've got it made in the shade then

no one gonna fire you if they have no idea what you're doing

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
linq is the best thing about c#

brap
Aug 23, 2004

Grimey Drawer
the other neat thing about lambdas/linq is that c# has expression trees so you can basically write "functions" in c# that are really expression trees that get compiled to sql at runtime and... well, it's a mixed bag, actually.

linq and async/await...and ASP.NET...are the reasons for using C#.
you just have to live with windows or a windows VM to use it.

Shaggar posted:

use MSSQL server and ASP.net 5 WebAPI

this except asp.net 4 not 5 because lol asp.net 5 and .net core are seriouslyy not ready.

Bloody
Mar 3, 2013

ctps: i made a c# program that generates tcl scripts that run the fpga tools to generate fpga projects from source, synthesize the projects, and program the hardware. its like a giant heap of future unmaintainability im really excited about it

on the plus side my jenkins server now gets to have repeatable/reproducible builds

Potassium Problems
Sep 28, 2001
we have such sights to show you

code:
            return GetButtServices()
                // Log into every butt server
                .Select(service => service.Login())
                // Create a list of butts to turds
                .Select(service => new
                {
                    Service = service,
                    Turds = service.FetchTurds()
                })
                // Map a 1-to-1 of non unique turds to the butt they were pulled from
                .SelectMany(x => x.Turds, (x, turd) => new ReferenceToButtServiceMapping
                {
                    Service = x.Service,
                    Turd = turd
                })
                // Removing any turds in the blacklist
                .Where(mapping => !TurdBlacklist.Any(item => item.TurdName.Is(mapping.Turd.Name)))
                // Group remaining turds by their color...
                .GroupBy(
                    mapping => mapping.Turd.Color.ToLower()
                    // ...and return a custom collection (instead of an IGrouping) of lowercase turd colors with a
                    // collection of references to butts they exist in
                    (groupKey, collectionResult) => new TurdToButtMappings
                    {
                        Name = groupKey,
                        Mappings = collectionResult
                    }
                );

Bloody
Mar 3, 2013

i dislike how that is formatted

oh no blimp issue
Feb 23, 2011

Lone_Strider posted:

we have such sights to show you

code:
            return GetButtServices()
                // Log into every butt server
                .Select(service => service.Login())
                // Create a list of butts to turds
                .Select(service => new
                {
                    Service = service,
                    Turds = service.FetchTurds()
                })
                // Map a 1-to-1 of non unique turds to the butt they were pulled from
                .SelectMany(x => x.Turds, (x, turd) => new ReferenceToButtServiceMapping
                {
                    Service = x.Service,
                    Turd = turd
                })
                // Removing any turds in the blacklist
                .Where(mapping => !TurdBlacklist.Any(item => item.TurdName.Is(mapping.Turd.Name)))
                // Group remaining turds by their color...
                .GroupBy(
                    mapping => mapping.Turd.Color.ToLower()
                    // ...and return a custom collection (instead of an IGrouping) of lowercase turd colors with a
                    // collection of references to butts they exist in
                    (groupKey, collectionResult) => new TurdToButtMappings
                    {
                        Name = groupKey,
                        Mappings = collectionResult
                    }
                );

its...beautiful

oh no blimp issue
Feb 23, 2011

there's just something i love about linq blocks
nest and chain that poo poo, make it unintelligible

HoboMan
Nov 4, 2010

Lone_Strider posted:

we have such sights to show you

code:
            return GetButtServices()
                // Log into every butt server
                .Select(service => service.Login())
                // Create a list of butts to turds
                .Select(service => new
                {
                    Service = service,
                    Turds = service.FetchTurds()
                })
                // Map a 1-to-1 of non unique turds to the butt they were pulled from
                .SelectMany(x => x.Turds, (x, turd) => new ReferenceToButtServiceMapping
                {
                    Service = x.Service,
                    Turd = turd
                })
                // Removing any turds in the blacklist
                .Where(mapping => !TurdBlacklist.Any(item => item.TurdName.Is(mapping.Turd.Name)))
                // Group remaining turds by their color...
                .GroupBy(
                    mapping => mapping.Turd.Color.ToLower()
                    // ...and return a custom collection (instead of an IGrouping) of lowercase turd colors with a
                    // collection of references to butts they exist in
                    (groupKey, collectionResult) => new TurdToButtMappings
                    {
                        Name = groupKey,
                        Mappings = collectionResult
                    }
                );
welp, time to re-think my career

Potassium Problems
Sep 28, 2001
I'm real bad at creating long linq chains so I got into the habit of trying to format/comment complicated ones for maintenance sake. But man it's soooo good when you take a bunch of function calls and logic and turn it into a single linq statement and almost never have to touch it again because the work is in separately defined predicate/map methods :hellyeah:

AWWNAW
Dec 30, 2008

uncurable mlady posted:

linq is the best thing about c#

mos def but I think it's also one of the most divisive things about it too. can't think of any other feature that scares people so much. I used to work on a team of old school c++ programmers who wouldn't use LINQ because they thought it was too complicated or slow

AWWNAW
Dec 30, 2008

there's magic in them monads

fritz
Jul 26, 2003

i am always glad i dont do web development, but even more glad now :

https://github.com/azer/left-pad/issues/4
https://medium.com/@azerbike/i-ve-just-liberated-my-modules-9045c06be67c#.hhi6b21g5

summary: javascript developer gets sort-of-bogus trademark claim, npm backs up the claimants, developer pulls all his code, chaos reigns


one of his modules was, in its entirety,
code:
 module.exports = leftpad;
  
  function leftpad (str, len, ch) {
    str = String(str);
  
    var i = -1;
  
    if (!ch && ch !== 0) ch = ' ';
  
    len = len - str.length;
  
    while (++i < len) {
      str = ch + str;
    }
  
    return str;
  }

Arcsech
Aug 5, 2008

fritz posted:

i am always glad i dont do web development, but even more glad now :

https://github.com/azer/left-pad/issues/4
https://medium.com/@azerbike/i-ve-just-liberated-my-modules-9045c06be67c#.hhi6b21g5

summary: javascript developer gets sort-of-bogus trademark claim, npm backs up the claimants, developer pulls all his code, chaos reigns


one of his modules was, in its entirety,
code:
 module.exports = leftpad;
  
  function leftpad (str, len, ch) {
    str = String(str);
  
    var i = -1;
  
    if (!ch && ch !== 0) ch = ' ';
  
    len = len - str.length;
  
    while (++i < len) {
      str = ch + str;
    }
  
    return str;
  }

You forgot the part where a bazillion packages depended on that 11 line package. Ember, react native, and babel won't build right now, among others.

fritz
Jul 26, 2003

Arcsech posted:

You forgot the part where a bazillion packages depended on that 11 line package. Ember, react native, and babel won't build right now, among others.

i got tired of typing and left it at 'chaos reigns'

Arcsech
Aug 5, 2008

fritz posted:

i got tired of typing and left it at 'chaos reigns'

Also apparently (according to comments,so take with a grain of salt) when you unpublish an npm package it frees the name so anybody can claim it for whatever they want

Lol :rip:

E: I guess this isn't quite true due to some fuckery with version numbers but close enough

Arcsech fucked around with this message at 02:10 on Mar 23, 2016

HoboMan
Nov 4, 2010

lol @ javascript "development" in general

e: but seriousposting that sounds like a super lovely move by npm

HoboMan fucked around with this message at 02:19 on Mar 23, 2016

Bloody
Mar 3, 2013

lmao

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

AWWNAW posted:

mos def but I think it's also one of the most divisive things about it too. can't think of any other feature that scares people so much

var

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

var is weirdly divisive, I don't think I've ever heard a good argument against it though. it makes things so much more readable and clean

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
isnt kik some lovely chat app 4channers use to coerce naked selfies out of teenagers? how does that poo poo have enough legal clout to pull shenanigans like that.

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


uncurable mlady posted:

var is weirdly divisive, I don't think I've ever heard a good argument against it though. it makes things so much more readable and clean

static typing peeps are against it cause they think it gets rid of static typing for some reason

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

LeftistMuslimObama posted:

isnt kik some lovely chat app 4channers use to coerce naked selfies out of teenagers? how does that poo poo have enough legal clout to pull shenanigans like that.

VC funded messaging apps have a lot of lawyers

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

uncurable mlady posted:

VC funded messaging apps have a lot of lawyers

but, like, wouldnt a court take one look at them, realize their app is mostly used by predatory pedophiles, and just tell them to gently caress off?

nevermind, im just being naive and wishing the world worked like it does in my head again. chaos reigns.

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

LeftistMuslimObama posted:

but, like, wouldnt a court take one look at them, realize their app is mostly used by predatory pedophiles, and just tell them to gently caress off?

nevermind, im just being naive and wishing the world worked like it does in my head again. chaos reigns.

that's not really how trademark works so no, they wouldn't

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
the funniest part are the people who got hosed by this supporting the dude "yeah you broke my entire build and hosed up my poo poo but fight the power man!!!"

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


in the vein of npm having retarded packages, look at this other vital package for nodejs:
https://github.com/tjmehta/is-positive-integer

JavaScript code:
Usage

var isPositiveInteger = require('is-positive-integer')

isPositiveInteger(1) // true
isPositiveInteger(10) // true
isPositiveInteger(100) // true
isPositiveInteger(1000) // true
isPositiveInteger(0) // false
isPositiveInteger(-1) // false
isPositiveInteger(-10) // false
isPositiveInteger(-100) // false
isPositiveInteger(-1000) // false
isPositiveInteger(1.1) // false
isPositiveInteger(10.1) // false
isPositiveInteger(100.1) // false
isPositiveInteger(1000.1) // false
isPositiveInteger(-1.1) // false
isPositiveInteger(-10.1) // false
isPositiveInteger(-100.1) // false
isPositiveInteger(-1000.1) // false
isPositiveInteger(Infinity) // false
isPositiveInteger({}) // false
isPositiveInteger([]) // false
isPositiveInteger('10') // false
isPositiveInteger('what') // false
isPositiveInteger(/what/) // false
the source code for this incredible module is:

JavaScript code:
var passAll = require('101/pass-all')
var isPositive = require('is-positive')
var isInteger = require('is-integer')

module.exports = passAll(isPositive, isInteger)

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



if you can wait until 2017 then this whole issue will blow over (until it happens to another npm package) because the language is getting native string padding!!!

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Condiv posted:

in the vein of npm having retarded packages, look at this other vital package for nodejs:
https://github.com/tjmehta/is-positive-integer

JavaScript code:
Usage

var isPositiveInteger = require('is-positive-integer')

isPositiveInteger(1) // true
isPositiveInteger(10) // true
isPositiveInteger(100) // true
isPositiveInteger(1000) // true
isPositiveInteger(0) // false
isPositiveInteger(-1) // false
isPositiveInteger(-10) // false
isPositiveInteger(-100) // false
isPositiveInteger(-1000) // false
isPositiveInteger(1.1) // false
isPositiveInteger(10.1) // false
isPositiveInteger(100.1) // false
isPositiveInteger(1000.1) // false
isPositiveInteger(-1.1) // false
isPositiveInteger(-10.1) // false
isPositiveInteger(-100.1) // false
isPositiveInteger(-1000.1) // false
isPositiveInteger(Infinity) // false
isPositiveInteger({}) // false
isPositiveInteger([]) // false
isPositiveInteger('10') // false
isPositiveInteger('what') // false
isPositiveInteger(/what/) // false
the source code for this incredible module is:

JavaScript code:
var passAll = require('101/pass-all')
var isPositive = require('is-positive')
var isInteger = require('is-integer')

module.exports = passAll(isPositive, isInteger)

I don't have the link but I remember seeing a dev on twitter posting this dude's npm profile and he had like a thousand packages in his name but at least 50 of them were just like 'ansi-[colour]' so he'd have a package for 'ansi-blue' and another for 'ansi-black' and so on

MononcQc
May 29, 2007

piratepilates posted:

I don't have the link but I remember seeing a dev on twitter posting this dude's npm profile and he had like a thousand packages in his name but at least 50 of them were just like 'ansi-[colour]' so he'd have a package for 'ansi-blue' and another for 'ansi-black' and so on

Found the guy: https://www.npmjs.com/~jonschlinkert

E: other worthwhile contributions include packages such as:

git-repo-name - v0.5.1 - Get the repository name from the git remote origin URL.
git-user-email - v0.2.1 - Get the email address of the current user from git config.
git-username - v0.4.0 - Get the username from a git remote origin URL.
git-user-name - v1.2.0 - Get a user's name from git config at the project or global scope, depending on what git uses in the current context.
is-even - v0.1.1 - Return true if the given number is even.
is-false - v0.1.1 - Returns false if the value of a property is either strictly false, or it's inverse is strictly true.
is-number - v2.1.0 - Returns true if the value is a number. comprehensive tests.
is-odd - v0.1.0 - Returns true if the given number is odd.
month - v2.0.1 - Get the name or number of the current month or any month of the year.
month-day - v0.1.1 - Get the current day of the month, according to local time or UTC.
months - v1.0.1 - Months of the year.

MononcQc fucked around with this message at 03:20 on Mar 23, 2016

Adbot
ADBOT LOVES YOU

crazysim
May 23, 2004
I AM SOOOOO GAY

Condiv posted:

in the vein of npm having retarded packages, look at this other vital package for nodejs:
https://github.com/tjmehta/is-positive-integer

JavaScript code:
Usage

var isPositiveInteger = require('is-positive-integer')

isPositiveInteger(1) // true
isPositiveInteger(10) // true
isPositiveInteger(100) // true
isPositiveInteger(1000) // true
isPositiveInteger(0) // false
isPositiveInteger(-1) // false
isPositiveInteger(-10) // false
isPositiveInteger(-100) // false
isPositiveInteger(-1000) // false
isPositiveInteger(1.1) // false
isPositiveInteger(10.1) // false
isPositiveInteger(100.1) // false
isPositiveInteger(1000.1) // false
isPositiveInteger(-1.1) // false
isPositiveInteger(-10.1) // false
isPositiveInteger(-100.1) // false
isPositiveInteger(-1000.1) // false
isPositiveInteger(Infinity) // false
isPositiveInteger({}) // false
isPositiveInteger([]) // false
isPositiveInteger('10') // false
isPositiveInteger('what') // false
isPositiveInteger(/what/) // false
the source code for this incredible module is:

JavaScript code:
var passAll = require('101/pass-all')
var isPositive = require('is-positive')
var isInteger = require('is-integer')

module.exports = passAll(isPositive, isInteger)

So how many things depend on it and is there anything important going up?

  • Locked thread