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
raminasi
Jan 25, 2005

a last drink with no ice

Jabor posted:

your program had something go horribly wrong and has arbitrarily corrupted internal state, why would you try to continue instead of letting it crash and restart?

BiohazrD posted:

You're in the right thread my friend

I write plugins for a 3D modeler. explain why letting a dumb bug crash the whole modeler and losing my user's work is preferable to emitting an error message and aborting.

Adbot
ADBOT LOVES YOU

HoboMan
Nov 4, 2010

HoboMan posted:

i've said it before and i'll say it again, the c# TryParse methods are bad and i hate them
C# code:
int? poo;
if(!int.TryParse(pooString, out poo)) {
    poo = null;
}
it's just so gross

i just realized this code don't even work
you would need to do
C# code:
int? poo;
int parsedPoo;
if(int.TryParse(pooString, out parsedPoo))
{
    poo = parsedPoo;
}
else
{
    poo = null;
}
for what I want

HoboMan fucked around with this message at 17:26 on Jun 1, 2016

brap
Aug 23, 2004

Grimey Drawer
it does make sense to USE stuff like promises in an impure language. I really don't care if you call them monads or not as long as you can see the utility in what the promise is doing. the bottom line for many programmers is: monads are very simple and you're already using them.

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

raminasi posted:

I write plugins for a 3D modeler. explain why letting a dumb bug crash the whole modeler and losing my user's work is preferable to emitting an error message and aborting.

that should be the modeler's issue to deal with, i.e. not letting wacknut plugins kill the whole modeler

raminasi
Jan 25, 2005

a last drink with no ice

Captain Foo posted:

that should be the modeler's issue to deal with, i.e. not letting wacknut plugins kill the whole modeler

1) well sure, but it doesn't, and i'm writing software in the real world, not the one where nobody writes bugs and everybody handles their business
2) how's it gonna do that without catch (Exception) anyway? running each plugin in a separate process?

hell, let's look at it from the other direction - say i'm calling into ThirdPartyLibraryThatMightHaveBugs.dll. how am i supposed to prevent wacknut libraries from killing my whole application?

c# is not erlang, and removing catch (Exception) will not make it erlang

Chamook
Nov 17, 2006

wheeeeeeeeeeeeee

HoboMan posted:

i just realized this code don't even work
you would need to do
C# code:
int? poo;
int parsedPoo;
if(int.TryParse(pooString, out parsedPoo))
{
    poo = parsedPoo;
}
else
{
    poo = null;
}
for what I want

We made a fancy functional library at work to use maybes and stuff in C#, I came up with this to handle these uggo TryParse things but decided it wasn't really nice enough
C# code:
public delegate T Parser<T>(string input, out T output);

public static Maybe<T> AsMaybe<T>(this Parser<T> parser, string input)
{
    if(parser == null)
        throw new ArgumentNullException(nameof(parser));
    if(input == null)
        throw new ArgumentNullException(nameof(input));

    T output;
    if(parser(input, out output))
        return output.ToMaybe();
    else
        return Maybe<T>.Empty();
}
which lets you write:
C# code:
var maybeInt = ((Parser<int>)int.TryParse).AsMaybe("12");

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

raminasi posted:

1) well sure, but it doesn't, and i'm writing software in the real world, not the one where nobody writes bugs and everybody handles their business
2) how's it gonna do that without catch (Exception) anyway? running each plugin in a separate process?

hell, let's look at it from the other direction - say i'm calling into ThirdPartyLibraryThatMightHaveBugs.dll. how am i supposed to prevent wacknut libraries from killing my whole application?

c# is not erlang, and removing catch (Exception) will not make it erlang

everything should be erlang

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

fleshweasel posted:

it does make sense to USE stuff like promises in an impure language. I really don't care if you call them monads or not as long as you can see the utility in what the promise is doing. the bottom line for many programmers is: monads are very simple and you're already using them.

please dont hurt my feelings by using a scary word

tef
May 30, 2004

-> some l-system crap ->

gonadic io posted:

rust's try! macro works out to the same thing, as do scalas for loops and um

Chaining futures in c#? That's a thing you can do right? Also the ?? operator

just because you use functional composition doesn't make it a monad

i mean, heck, comonads are *incredibly* popular in more mainstream languages

quiggy
Aug 7, 2010

[in Russian] Oof.


so is anyone gonna explain what a monad is to us morons or what

tef
May 30, 2004

-> some l-system crap ->

quiggy posted:

so is anyone gonna explain what a monad is to us morons or what

functional explanation: it's a monoid in the category of endofunctors, what happens when you turn a comonad inside out



oo explanation:

a monad is an object that stores a value which you can only access through a callback, which has rules on composition:

monad = new Monad(x)

monad.next( {|x| do something with x and return a monad } )

*and* the function *must* return another monad, so you can do method chaining

monad.next( { ... } ).next( { ... } )

when you use a callback, the monad object itself gets to control evaluation: the trick is that you can insert logic here, like for handling empty/null values to skip the callback

a monad is a building block for functional composition, using callbacks, so that the block can change evaluation order/return value.


you can also add another method to the monad object, call it join: monad.join( {|m| do something with monad and return a monad } )


back to functional composition:

m = monad(x) # this is called return
m.next({|.... a callback that returns a monad}) # this is called bind, or (>>=)


homework: why is a builder that has some wrapped values, that takes callbacks like turning code that uses normal iterators inside out

tef
May 30, 2004

-> some l-system crap ->
haskell comes with syntax that changes

do x <- foo()
return x

into this sorta code flow

foo().next({|x| new Monad(x)})


f# has a way more interesting do-notation called "computational expressions"

Shaggar
Apr 26, 2006
idk what do x <- foo() means.

tef
May 30, 2004

-> some l-system crap ->

Shaggar posted:

idk what do x <- foo() means.


it's special syntax to mean "call foo and use x as the callback argument and wrap what follows into the callback"

Plorkyeran
Mar 22, 2007

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

raminasi posted:

hell, let's look at it from the other direction - say i'm calling into ThirdPartyLibraryThatMightHaveBugs.dll. how am i supposed to prevent wacknut libraries from killing my whole application?

use a worker process per plugin that you communicate with using wcf

wcf is sort of a nightmare over a network (because remote objects over a network has always been a nightmare), but for ipc on a single machine it actually does come pretty close to being totally transparent

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
running third-party code out of process is amazing at reducing the amount of stupid bullshit you have to deal with

cinci zoo sniper
Mar 15, 2013




monads are like gonads, only computre

jony neuemonic
Nov 13, 2009

ErIog posted:

So basically, no matter what you call it, I think there should be separate paths for recoverable vs. non-recoverable errors.

you're coming dangerously close to advocating for php error handling.

brap
Aug 23, 2004

Grimey Drawer
nope, ask noted smart computer man Joe Duffy about this and you'll realize that recoverable and non-recoverable errors are different enough to have different mechanisms.

HoboMan
Nov 4, 2010


well turns out i'm even dumber than i thought

Progressive JPEG
Feb 19, 2003

Plorkyeran posted:

running third-party code out of process is amazing at reducing the amount of stupid bullshit you have to deal with

raminasi
Jan 25, 2005

a last drink with no ice

Plorkyeran posted:

use a worker process per plugin that you communicate with using wcf

wcf is sort of a nightmare over a network (because remote objects over a network has always been a nightmare), but for ipc on a single machine it actually does come pretty close to being totally transparent

you seriously run all library code in a separate process? that sounds like much more of a nightmare than a top-level "oh poo poo" exception handler

Plorkyeran
Mar 22, 2007

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

raminasi posted:

you seriously run all library code in a separate process? that sounds like much more of a nightmare than a top-level "oh poo poo" exception handler

certainly not all third-party code, but i've never come to regret it in the places where i have spawned separate processes for libraries (of course, i've only done so specifically because the library was poorly behaved and did things like modify process-global settings, not support multiple instances of it on different threads, leak memory, or just generally do insane things). should i ever design another plug-in interface it'll definitely be 100% out-of-process only because in-process plugins are literally never well behaved and at the minimum you'll get a million stupid bug reports that aren't your fault and you can't do anything about

aardvaard
Mar 4, 2013

you belong in the bog of eternal stench

jony neuemonic posted:

you're coming dangerously close to advocating for php error handling.

php error handling is hosed because it plows through what any normal language would consider a fatal error

quiggy
Aug 7, 2010

[in Russian] Oof.


tef posted:

functional explanation: it's a monoid in the category of endofunctors, what happens when you turn a comonad inside out



oo explanation:

a monad is an object that stores a value which you can only access through a callback, which has rules on composition:

monad = new Monad(x)

monad.next( {|x| do something with x and return a monad } )

*and* the function *must* return another monad, so you can do method chaining

monad.next( { ... } ).next( { ... } )

when you use a callback, the monad object itself gets to control evaluation: the trick is that you can insert logic here, like for handling empty/null values to skip the callback

a monad is a building block for functional composition, using callbacks, so that the block can change evaluation order/return value.


you can also add another method to the monad object, call it join: monad.join( {|m| do something with monad and return a monad } )


back to functional composition:

m = monad(x) # this is called return
m.next({|.... a callback that returns a monad}) # this is called bind, or (>>=)


homework: why is a builder that has some wrapped values, that takes callbacks like turning code that uses normal iterators inside out

:psyduck:

ok so a monad is a thing that takes either a value or another monad, does a thing to it, and returns a monad? so in c++ terms would this virtual class meet the definition of a monad (i know monads are a thing from functional programming that arent used much in imperative programming, but this is my background so it's the context in which im gonna manage to understand these if at all)

code:
template <typename T>
class Monad {
  public:
    virtual Monad<T>* doThing(T x) = 0;
    virtual Monad<T>* doThing(const Monad<T>* m) = 0;
};
and then theres some other thing that returns a joined Monad, so like within class Monad:

code:
static Monad<T>* join(const Monad<T>* first, const Monad<T>* second);
...or am i way off-base

also what do you mean when you say |x| or |M|

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
i think it's more like

code:
template <typename T>
class Monad {
  virtual Monad<T> andThen(std::function<Monad<T>, T> func) = 0;
}
(sorry for the bad syntax, I haven't done c++ in a long time)

obv this is super reductive

{|x| ...} is a syntax for an anonymous function that takes x as a parameter

quiggy
Aug 7, 2010

[in Russian] Oof.


Asymmetrikon posted:

i think it's more like

code:
template <typename T>
class Monad {
  virtual Monad<T> andThen(std::function<Monad<T>, T> func) = 0;
}
(sorry for the bad syntax, I haven't done c++ in a long time)

obv this is super reductive

{|x| ...} is a syntax for an anonymous function that takes x as a parameter

so a monad has/is a function that takes a (function that takes a value and returns a monad) and returns a monad

Zemyla
Aug 6, 2008

I'll take her off your hands. Pleasure doing business with you!

Asymmetrikon posted:

i think it's more like

code:
template <typename T>
class Monad {
  virtual Monad<T> andThen(std::function<Monad<T>, T> func) = 0;
}
(sorry for the bad syntax, I haven't done c++ in a long time)

obv this is super reductive

{|x| ...} is a syntax for an anonymous function that takes x as a parameter

Close, except andThen's type is virtual Monad<U> andThen(std::function<Monad<U>(T) func). So if I have a function that turns an int into a list of chars, then I can use it to turn a list of ints into a list of chars.

quiggy
Aug 7, 2010

[in Russian] Oof.


kalstrams posted:

monads are like gonads, only computre

thinkin' this might be the best explanation itt

HoboMan
Nov 4, 2010

quiggy posted:

thinkin' this might be the best explanation itt

this checks out with how excited people seem to get about them


computer gonads i mean




sexbots

NihilCredo
Jun 6, 2011

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

fsharpforfunandprofit is the best coding tutorial i have ever read, and not surprisingly Scott's monad computation expression explanation is also top-notch:

http://fsharpforfunandprofit.com/posts/computation-expressions-intro/

as a result i tend to think of monads in practical terms as "define custom behaviour for basic variable-handling keywords like 'let'/'var' and 'return', and do it in a type-safe way"

Share Bear
Apr 27, 2004

if you're using an apache java thing (ha, laughs! wow), is there any way to force its underlying dependencies to use the logging that they available, declared inside themselves

specifically apache vfs sits on top of jsch's ssh implementation, but you only include apache vfs in your project, and i want jsch to start logging a ton, but there's no config for that which i can find

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum
the only thing i know about monads is that microsoft used it as the project name for powershell

Luigi Thirty
Apr 30, 2006

Emergency confection port.

speaking of terrible programmers

https://twitter.com/anblanx/status/738139381744078849

MrMoo
Sep 14, 2000

Share Bear posted:

if you're using an apache java thing (ha, laughs! wow), is there any way to force its underlying dependencies to use the logging that they available, declared inside themselves

specifically apache vfs sits on top of jsch's ssh implementation, but you only include apache vfs in your project, and i want jsch to start logging a ton, but there's no config for that which i can find

Most of the Java logging systems are runtime configurable by the choice of jars, i.e. there is usually an implementation or binding jar that can target J.U.L., SLF4J, Log4j1, Log4j2, or Logback. You can also do things with Apache Commons logging and I think there is another one too, way too many.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Share Bear posted:

if you're using an apache java thing (ha, laughs! wow), is there any way to force its underlying dependencies to use the logging that they available, declared inside themselves

specifically apache vfs sits on top of jsch's ssh implementation, but you only include apache vfs in your project, and i want jsch to start logging a ton, but there's no config for that which i can find

the problem is that jsch doesn't log to any framework so you have to roll your own http://stackoverflow.com/a/26849101/102483

Soricidus
Oct 21, 2010
freedom-hating statist shill

Plorkyeran posted:

running third-party code out of process is amazing at reducing the amount of stupid bullshit you have to deal with

sadly ipc is also stupid bullshit so you really don't gain much (unless you're using erlang maybe?)

we have a bunch of ancient c libraries whose error handling consists of dumping poo poo directly to stdout and then calling exit(). I do run those out of process in a couple of programs, but it's bad and really I should just fix them to use proper error callbacks or something

Luigi Thirty
Apr 30, 2006

Emergency confection port.

for some reason our homemade email processor spits all its exceptions into an sqlite database

cinci zoo sniper
Mar 15, 2013




Luigi Thirty posted:

for some reason our homemade email processor spits all its exceptions into an sqlite database
hmm i wonder why. you should roll your own crypto next, to make sure the sqlite database with email logs is unbreachable :v:

Adbot
ADBOT LOVES YOU

Luigi Thirty
Apr 30, 2006

Emergency confection port.

kalstrams posted:

hmm i wonder why. you should roll your own crypto next, to make sure the sqlite database with email logs is unbreachable :v:

I got to listen to someone in the next cube over bitch all day about how it would make his job (remote support) easier if our application just used reversible password encryption

  • Locked thread