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
coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

LARD LORD posted:

what is the advantage of Haskell, if any??
i like it because it's a language designed with truly terrible programmers in mind. the foundational language features are intended to either catch your mistakes or to make it much more difficult to make those mistakes in the first place.

efb by meram

Adbot
ADBOT LOVES YOU

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

AlsoD posted:

perhaps one reason why people struggle with Haskell's error messages* is that they're so used to VS or javac that actually reading them seems like a really weird concept

*: type errors are all just variations on:
code:
> let x = 3 :: Int
> length x
Couldn't match expected type '[a]' with actual type 'Int'
In the first argument of 'length', namely '3'
In the expression: length 3
:: means "has type", [a] means a list of something, Int is a number. that's all you need to know to decode that error message.

I struggled a lot with sml errors at first because I guess I was way too used to dynamic typing.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
terrible programmer question: if im dicking about in C++/CLI and i create an unmanaged std::thread to do some work in the background, will it block when the garbage collector runs

my intuition says "no" because the gc thread won't know about the unmanaged thread, but i dont know enough about .net/OSes/GC/anything to be sure there's not some process-wide magic going on

e: and two minutes later i find an answer by giving up on keywords and googling "how does the .net garbage collector interrupt threads"

quote:

This has the same property as the CLR's garbage collector. A GC won't stop threads that are not running managed code. Since those threads can't be touching the GC's heap anyways, there's no need for the GC to coordinate with them.

coffeetable fucked around with this message at 18:49 on Jul 14, 2014

Shaggar
Apr 26, 2006

LARD LORD posted:

what is the advantage of Haskell, if any??

if you are simon petyon jones it helps you prototype new features for use in a real language.

for everyone else there is no reason to use Haskell

Shaggar
Apr 26, 2006

coffeetable posted:

terrible programmer question: if im dicking about in C++/CLI and i create an unmanaged std::thread to do some work in the background, will it block when the garbage collector runs

my intuition says "no" because the gc thread won't know about the unmanaged thread, but i dont know enough about .net/OSes/GC/anything to be sure there's not some process-wide magic going on

iirc in c# if you have unmanaged code and the managed references to the unmanaged code get dereferenced, it will gc the managed bits but leave the unmanaged ones around forever. so you need to be very careful to make sure you include cleanup of the unmanaged code inside your managed code. IDisposable makes this pretty easy.

idk how managed c++ does it but I bet its similar.

Bloody
Mar 3, 2013

wish you implemented IDisposable

Nomnom Cookie
Aug 30, 2009



AlsoD posted:

then there's the typeclass related ones which mostly just take the form of "no instance of <typeclass> arising from the literal <literal>". typeclasses are essentially OO's interfaces

i've had terrible problems decoding XMonad type errors. afaict its because some XMonad contribs require language extensions. some inscrutable poo poo about typeclass instances related to type variables in the instance declaration iirc. w/e i copied the extension directives from the example config and it worked

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
I need to hurry up and learn a lambda and a LINQ in .NET. I just stackoverflow everything or write a loop.

Nothing wrong with loops but I want to belt out these fancy pants oneliners for interviews and sense of satisfaction.

Is there a good writeup or how-to-do guide somewhere? Conceptually speaking I know what I want to do, that is, "remove elements from list that do/not match this condition" or "return new list which reflects changes you want to be made to elements matching/notmatching".

My actual case here is "remove whitespace/empty strings from list" and "if a string has -'s remove them, that is, turn "1-2" into "12" ".

Feh.

Shaggar
Apr 26, 2006
so in linq u have certain query operations that are kind of similar to sql. it has 2 syntaxes, query and method.

for your example query syntax would look something like this

C# code:
	IEnumerable<String> nonEmptyStrings = from str in listOfStrings // foreach String str in listOfStrings
						  where !String.IsNullOrWhiteSpace(str) //where it isn't null or whitespace
						  select str; //select the string
the method syntax is more commonly used irl and the same thing would look like this

C# code:
	IEnumerable<String> nonEmptyStrings = listOfStrings.Where(x => !String.IsNullOrWhiteSpace(x));
this is more concise. it basically means give me listOfStrings where the values are not null or whitespace. its a filter. the x => means you are using lambadas, but you don't really need to know about lambdas to use linq right now so don't worry about it. in this scenario x=> means x is a parameter to the next part of the statement. Because we are working with a list of strings, the type of x will be string. then obv !String.IsNullOrWhiteSpace(x) means the condition for our filter is that x (aka each string in the list) is not null or whitespace.

there are loads of other query operations like lets say you had a list of Boners and you wanted to get a list of all their sizes
C# code:
IEnumerable<long> sizes = bonerList.Select(x=>x.Size); 
since bonerList is IEnumerable<Boner> x is of type Boner so we use the expression x.Size to get the size for each element in the list.

theres way way way more and you can have a lot of fun abusing the hell out of linq to make what would otherwise be easy to read loops almost incomprehensible. try it out on your teammates today!

Bloody
Mar 3, 2013

lol more like ienumerable<short> sizes!!!

(rly more actually like var sizes)

Shaggar
Apr 26, 2006
so a lil bit about lambdas. lambda syntax in c# is basically just shorthand for writing a function. in the case of x=>!String.IsNullOrWhitespace(x) that is the equivalent of writing

C# code:

delegate(String x)
{
	return !String.IsNullOrWhitespace(x)
}

so what is a delegate? Delegates are what separates c# from the uncivilized heathens of dynamic garbolangs. delegates are sort of like function pointers but way better because they are type safe.

So lets go back to select. What the heck are we actually doing inside those parenthesis?? Well its like all other methods. we are passing an argument to Select, but it just so happens to be a function instead of an object!!! what the gently caress? that is weird!

if you look closer in vs you will see the type parameter in intellesense for the previous select example is Select(Func<string,bool> predicate) . Func is a generic delegate in c# and u'll see it all the time. Func represents a pointer to a method that takes in a parameter of type String and returns a value of type bool.

So something like this:
C# code:


bool NotNullOrWhitespace(String s)
{
	return !String.IsNullOrWhitespace(s)
}

Would match that signature. We could pass NotNullOrWhitespace directly into the select like this

C# code:

	IEnumerable<String> nonEmptyStrings = listOfStrings.Where(NotNullOrWhitespace);

Since linq is expecting a method that matches the signature Func<string,bool> it accepts this and compiles because we are being type safe!!! if you were to add or remove parameters to NotNullOrWhitespace it would not compile because it does match the signature of func<string,bool> and the compiler would not have any idea what u are doing!

We can also do something like this
C# code:


private Func<String,bool> notNullOrWhitespace =  x=> !String.IsNullOrWhitespace(x); 

public whateverSomeMethod()
{
//do whatever
	IEnumerable<String> nonEmptyStrings = listOfStrings.Where(notNullOrWhitespace );
//do more whatever
}

public whateverSomeOtherMethod()
{
//do something different but still want to filter strings
	IEnumerable<String> nonEmptyStrings = listOfStrings.Where(notNullOrWhitespace );
//do more whatever
}


Now we have a reusable function for NotIsNullOrWhiteSpace!!! This is really stupid and you will never find anyone who actually does that tho. Its just to demonstrate that u can assign delegates to variables or fields (as in this example) and then pass them off to methods like they were just regular old parameters.

Shaggar fucked around with this message at 21:57 on Jul 14, 2014

Shaggar
Apr 26, 2006
you use delegates in c# for the same reasons you use function pointers in bad languages. they let you hide complex and unmaintainable implementations behind deceivingly simple facades! the difference is in c# the compiler makes sure you didn't gently caress up too bad.

Bloody
Mar 3, 2013

function pointers own and c is not a bad lang

Shaggar
Apr 26, 2006
yes it is

Luigi Thirty
Apr 30, 2006

Emergency confection port.

talked to them on the phone and they seemed legit, the guy on the other end knew what he was talking about, he said there's so few developers around here that they'll take anyone with any OOP experience and that the majority of the responses to his ads are people in india.

Bloody
Mar 3, 2013

C is a good lang

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Shaggar posted:

iirc in c# if you have unmanaged code and the managed references to the unmanaged code get dereferenced, it will gc the managed bits but leave the unmanaged ones around forever. so you need to be very careful to make sure you include cleanup of the unmanaged code inside your managed code. IDisposable makes this pretty easy.

idk how managed c++ does it but I bet its similar.
yeah when i was googling around i found plenty about managed vs unmanaged memory, and like you say the GC ignores the latter. what i was having trouble finding was about how the GC interacts with managed vs unmanaged execution.

how i had it in my head was that there were managed and unmanaged threads, with the managed threads checking in w/ the GC periodically to see whether they should suspend while it collected the garbage. now i realize all it is is that if a thread tries to access managed memory while the garbage is being collected, it blocks until the GC is done.

gently caress them posted:

I need to hurry up and learn a lambda and a LINQ in .NET. I just stackoverflow everything or write a loop.

Nothing wrong with loops but I want to belt out these fancy pants oneliners for interviews and sense of satisfaction.

Is there a good writeup or how-to-do guide somewhere? Conceptually speaking I know what I want to do, that is, "remove elements from list that do/not match this condition" or "return new list which reflects changes you want to be made to elements matching/notmatching".

My actual case here is "remove whitespace/empty strings from list" and "if a string has -'s remove them, that is, turn "1-2" into "12" ".

Feh.
stop half-arsing it. go get a copy of Essential C# 5.0 or whatever and read it cover-to-cover, making notes and experimenting as you go along. iirc you've had this new job of yours for months now and if you've been working with C# all this time without knowing how LINQ works then wowee

coffeetable fucked around with this message at 22:15 on Jul 14, 2014

Soricidus
Oct 21, 2010
freedom-hating statist shill

Bloody posted:

C is a good lang
agreed

Bloody
Mar 3, 2013

also if you cant figure out linq in like five minutes of intellisensing and googling then smdh its the most straightforward intuitive programming feature i think ive ever used

Nomnom Cookie
Aug 30, 2009



Shaggar posted:

so a lil bit about lambdas. lambda syntax in c# is basically just shorthand for writing a function. in the case of x=>!String.IsNullOrWhitespace(x) that is the equivalent of writing

C# code:
delegate(String x)
{
	return !String.IsNullOrWhitespace(x)
}
so what is a delegate? Delegates are what separates c# from the uncivilized heathens of dynamic garbolangs. delegates are sort of like function pointers but way better because they are type safe.

So lets go back to select. What the heck are we actually doing inside those parenthesis?? Well its like all other methods. we are passing an argument to Select, but it just so happens to be a function instead of an object!!! what the gently caress? that is weird!

if you look closer in vs you will see the type parameter in intellesense for the previous select example is Select(Func<string,bool> predicate) . Func is a generic delegate in c# and u'll see it all the time. Func represents a pointer to a method that takes in a parameter of type String and returns a value of type bool.

So something like this:
C# code:

bool NotNullOrWhitespace(String s)
{
	return !String.IsNullOrWhitespace(s)
}
Would match that signature. We could pass NotNullOrWhitespace directly into the select like this

C# code:
	IEnumerable<String> nonEmptyStrings = listOfStrings.Where(NotNullOrWhitespace);
Since linq is expecting a method that matches the signature Func<string,bool> it accepts this and compiles because we are being type safe!!! if you were to add or remove parameters to NotNullOrWhitespace it would not compile because it does match the signature of func<string,bool> and the compiler would not have any idea what u are doing!

We can also do something like this
C# code:

private Func<String,bool> notNullOrWhitespace =  x=> !String.IsNullOrWhitespace(x); 

public whateverSomeMethod()
{
//do whatever
	IEnumerable<String> nonEmptyStrings = listOfStrings.Where(notNullOrWhitespace );
//do more whatever
}

public whateverSomeOtherMethod()
{
//do something different but still want to filter strings
	IEnumerable<String> nonEmptyStrings = listOfStrings.Where(notNullOrWhitespace );
//do more whatever
}

Now we have a reusable function for NotIsNullOrWhiteSpace!!! This is really stupid and you will never find anyone who actually does that tho. Its just to demonstrate that u can assign delegates to variables or fields (as in this example) and then pass them off to methods like they were just regular old parameters.

function pointers are type safe to the extent that anything is type safe in C. the big honkin difference is that delegates can have state and the compiler leverages this to provide simple syntax for poo poo thats a huge pita in C. ofc every language feature can be emulated by a sufficiently determined C programmer which is why callbacks almost always have an extra void* for passing state

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

gently caress them posted:

Nothing wrong with loops
also lol

see this is what happens when your education is based entirely on homework assignments and 500-word articles

MeruFM
Jul 27, 2010
C is an easily abusable lang

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

coffeetable posted:

terrible programmer question: if im dicking about in C++/CLI and i create an unmanaged std::thread to do some work in the background, will it block when the garbage collector runs

my intuition says "no" because the gc thread won't know about the unmanaged thread, but i dont know enough about .net/OSes/GC/anything to be sure there's not some process-wide magic going on

e: and two minutes later i find an answer by giving up on keywords and googling "how does the .net garbage collector interrupt threads"

the party line on c++/cx is that you should not use c++/cx for anything but a shim for data binding and poo poo to link to your xaml

u can pin poo poo using gc handles, useful for p/invoke and native interop so that u can have a fixed ptr that the gc won't molest

remember to clean it up using c#'s bastardized cousin of RAII, idisposable

Soricidus
Oct 21, 2010
freedom-hating statist shill

MeruFM posted:

C is an easily abusable lang
all langs are easily abusable in some way. the solution is to make sure you're always the worst programmer in your team, that way you aren't the one being pissed off by other people's bad code

ShadowHawk
Jun 25, 2000

CERTIFIED PRE OWNED TESLA OWNER
YOSPOS I have tried to "not learn" Javascript like 4 times now using various x-to-javascript translators and they're all inadequate and now I'm learning Javascript from scratch and all the tutorials act like I want to learn baby's first programming language

Shaggar
Apr 26, 2006
the most JavaScript you need to know is how to import knockout into your project and how to google for the jquery library that does what you want

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

ShadowHawk posted:

YOSPOS I have tried to "not learn" Javascript like 4 times now using various x-to-javascript translators and they're all inadequate and now I'm learning Javascript from scratch and all the tutorials act like I want to learn baby's first programming language

read javascript the good parts I guess

Soricidus
Oct 21, 2010
freedom-hating statist shill

Symbolic Butt posted:

read javascript the good parts I guess
it doesn't take long!!

Nomnom Cookie
Aug 30, 2009



ShadowHawk posted:

YOSPOS I have tried to "not learn" Javascript like 4 times now using various x-to-javascript translators and they're all inadequate and now I'm learning Javascript from scratch and all the tutorials act like I want to learn baby's first programming language

it's like C except everything is shittier except it has anonymous functions and lexical scope

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Malcolm XML posted:

the party line on c++/cx is that you should not use c++/cx for anything but a shim for data binding and poo poo to link to your xaml

u can pin poo poo using gc handles, useful for p/invoke and native interop so that u can have a fixed ptr that the gc won't molest

remember to clean it up using c#'s bastardized cousin of RAII, idisposable
its not winrt im wantin this for. tl;dr is im writing an F# thing but there's a chunk functionality that can't tolerate GC hangs, so its gotta be unmanaged. the interface is also wide enough - and prone enough to change - that its lookin to be better to bridge the gap with c++/cli than pinvoke

but this is all exploratory so watch me change my mind in a month's time

Symbolic Butt posted:

read javascript the good parts I guess
quotin

then, if you're able to pick the language rather than having it proscribed to you, go read TypeScript Revealed. TS is a superset of JS (so retains all the functionality) that feels remarkably like C#. now that isn't exactly high praise but its a step up from "feels remarkably like JS"

coffeetable fucked around with this message at 00:06 on Jul 15, 2014

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

coffeetable posted:

yeah when i was googling around i found plenty about managed vs unmanaged memory, and like you say the GC ignores the latter. what i was having trouble finding was about how the GC interacts with managed vs unmanaged execution.

how i had it in my head was that there were managed and unmanaged threads, with the managed threads checking in w/ the GC periodically to see whether they should suspend while it collected the garbage. now i realize all it is is that if a thread tries to access managed memory while the garbage is being collected, it blocks until the GC is done.

stop half-arsing it. go get a copy of Essential C# 5.0 or whatever and read it cover-to-cover, making notes and experimenting as you go along. iirc you've had this new job of yours for months now and if you've been working with C# all this time without knowing how LINQ works then wowee

Two, and it's vb.net.

And it's web poo poo. I literally never actually needed much linq at all. It's the most boring of cruds.

Edit: Sometimes I'll actually do-a-logic, but it's largely just filter a thing, which databases are quite good at, or plug-in-a-thing from an existing library. I've ONCE had to actually do something more complicated than a one liner while webdevving, unless you count debugging as nontrivial.

:smith:

Just how lazy web poo poo can make you is hard to appreciate until you actually get stuck doing it.

Fuck them fucked around with this message at 00:18 on Jul 15, 2014

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

coffeetable posted:

also lol

see this is what happens when your education is based entirely on homework assignments and 500-word articles

Care to explain the pithy wisdom here? I'm really not sure how explicit loops are 'bad'.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

gently caress them posted:

Care to explain the pithy wisdom here? I'm really not sure how explicit loops are 'bad'.
the vast majority of the loops you'll be writing have no need for state and can be replaced with map/filter/reduce (aka select/where/aggregate), which are shorter, safer and communicate intent more effectively

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
welp, fair enough.

gonadic io
Feb 16, 2011

>>=
literally the topic of one of my papers :3:

also important are imap, ifilter and ifold i.e. the indexed versions

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
I'm starting to wonder is this is a part of the webdev growth experience. Do you take side projects, change direction, or just embrace the lazy?

Because holy poo poo is there some lazy where I work.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
i only program with recursion

loops make me feel dirty

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

gently caress them posted:

I'm starting to wonder is this is a part of the webdev growth experience. Do you take side projects, change direction, or just embrace the lazy?

Because holy poo poo is there some lazy where I work.

idk my job is web and i've been really amazed by how hard everyone is working all the time. either that or they're all much smarter than me and do things 20x faster (also possible)

syntaxrigger
Jul 7, 2011

Actually you owe me 6! But who's countin?

ugh... was forced to switch bosses a few weeks ago and things feel like they are at the beginning of plunging into unpleasantness. I was told I was 'pillaged' because some guy up the food chain needed me to pump out more PoC code...

post your criteria for looking for another job, tia

Adbot
ADBOT LOVES YOU

Brain Candy
May 18, 2006

gently caress them posted:

I'm starting to wonder is this is a part of the webdev growth experience. Do you take side projects, change direction, or just embrace the lazy?

Because holy poo poo is there some lazy where I work.

find another job because your current one isn't going to make you any better. or suck forever, that's doable I guess

  • Locked thread