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
quiggy
Aug 7, 2010

[in Russian] Oof.


Notorious b.s.d. posted:

and smarter pointers

not if it's c++03 or earlier :negative:

Adbot
ADBOT LOVES YOU

HoboMan
Nov 4, 2010

fart simpson posted:

how do you know this? like i find refactoring and modifying stuff in elm (a pure functional language) is way way way easier than doing the same in javascript, because elm code easily ends up being modular and composable and the compiler is v helpful

i had to use LISP for some academic poo poo like 6 years ago. i remember nothing about it except infinite function nesting.
but now, upon typing that, i realize i may be ascribing to functional programming what might just be the fact it was academic code.
but surely my professor would never write code that is a muddled mess only he understands! :v:

weird
Jun 4, 2012

by zen death robot

Notorious QIG posted:

nah now it's

code:
for (std::Butt::iterator it = butt.begin(); it != butt.end(); ++it) {
    fart(*it);
}
(ok or you just use auto in c++11 and up)

code:
std::for_each(butt.begin(), butt.end(), fart);

JawnV6
Jul 4, 2004

So hot ...

Illusive gently caress Man posted:

its just so dumb that every time i want to say
code:
DoThis();
DoThat();
instead it has to be
code:
result = DoThis();
if (!result.ok()) {
  return result;
}
result = DoThat();
if (!result.ok()) {
  return result;
}
even though its doing the same thing, my eyes fuckin glaze over with the second one.

code:
#define CHECKED(x) result=x;\
if(result.ok()){\
return result;\
}

Jerry Bindle
May 16, 2003
i asked 10x to talk with me about what was needed for <feature> PR, so that we don't repeat what happened earlier this week. most of the stuff needed for this feature was from the PR that got blasted because there were too many conflicts with his local branch, so i wanted to talk about it to make sure we were on the same page.

he responds with "There needs to be a PR for the <feature> so it can be merged……". boss chimes in to the email chain with "seems like an MVC design pattern?".

i feel like walking out and i probs would if i were confident in my ability to find another job within a reasonable time frame.

gonadic io
Feb 16, 2011

>>=
Of course, it should be "a mvc"

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Captain Foo posted:

probably some code, tbqh

probably

i need a wifi shield so i can connect to the ksp server directly instead of using my computer as a passthrough

fritz
Jul 26, 2003

Illusive gently caress Man posted:

its just so dumb that every time i want to say
code:
DoThis();
DoThat();
instead it has to be
code:
result = DoThis();
if (!result.ok()) {
  return result;
}
result = DoThat();
if (!result.ok()) {
  return result;
}
even though its doing the same thing, my eyes fuckin glaze over with the second one.

can you get away with :
code:
return (DoThis() && DoThat());

fritz
Jul 26, 2003

Notorious QIG posted:

not if it's c++03 or earlier :negative:

can you at least use a boost

gonadic io
Feb 16, 2011

>>=

HoboMan posted:

i had to use LISP for some academic poo poo like 6 years ago. i remember nothing about it except infinite function nesting.
but now, upon typing that, i realize i may be ascribing to functional programming what might just be the fact it was academic code.
but surely my professor would never write code that is a muddled mess only he understands! :v:

I'm glad you reconsidered. All of the best parts of the c# language (ie NOT the .net infrastructure) are considered to be "functional" features. var, foreach, linq, expression bodies, cascading nulls, AndThen (is that what it's called when u chain futures together?)

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

this is how i sometimes feel at redhat

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

gonadic io posted:

I'm glad you reconsidered. All of the best parts of the c# language (ie NOT the .net infrastructure) are considered to be "functional" features. var, foreach, linq, expression bodies, cascading nulls, AndThen (is that what it's called when u chain futures together?)

AndThen? Do you mean async/await?

Plorkyeran
Mar 22, 2007

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

Illusive gently caress Man posted:

its just so dumb that every time i want to say
code:
DoThis();
DoThat();
instead it has to be
code:
result = DoThis();
if (!result.ok()) {
  return result;
}
result = DoThat();
if (!result.ok()) {
  return result;
}
even though its doing the same thing, my eyes fuckin glaze over with the second one.

return DoThis().then([&] { return DoThat(); });

or if you want to pretend you're writing haskell, return DoThis() >> [&] { return DoThat(); };

Bloody
Mar 3, 2013

DoThis()?.DoThat()

weird
Jun 4, 2012

by zen death robot

HoboMan posted:

i had to use LISP for some academic poo poo like 6 years ago. i remember nothing about it except infinite function nesting.
but now, upon typing that, i realize i may be ascribing to functional programming what might just be the fact it was academic code.
but surely my professor would never write code that is a muddled mess only he understands! :v:

also lisp as it's written outside of functional programming classes isn't particularly functional, and out of the box it doesn't support some things people used to modern fp languages will expect. it's a multiparadigm language that was just the biggest language that supported fp 30 years ago

quiggy
Aug 7, 2010

[in Russian] Oof.


fritz posted:

can you at least use a boost

in theory yes, at this job no

quiggy
Aug 7, 2010

[in Russian] Oof.


weird posted:

code:
std::for_each(butt.begin(), butt.end(), fart);

yes this technically works but it assumes that the contents of the loop are one and only one function call

of course you could (a) write an external function that handles the inside of loop (:gonk:) or (b) write a lambda, but lambdas only exist in c++11 and up. and besides goddamn is that some ugly code either way if you aren't just trying to fart() each butt

oh also without lambdas you can't capture variables from outside the loop so have fun trying to get that to work with c++03 with any function that depends in some way on external state!

quiggy
Aug 7, 2010

[in Russian] Oof.


i pretty frequently have to iterate over stl::map objects, which is really "fun" in c++03. say i want to add one to each member of an int map keyed by strings

C++ code:
std::map<std::string, int> myMap;
...
for (std::map<std::string, int>::iterator it = myMap.begin(); it != myMap.end(); ++it) {
    ++myMap[it->first];
}
concise!

quiggy
Aug 7, 2010

[in Russian] Oof.


also be sure to note that it is not a pointer, it just overrides operator* and operator-> to make it look like one! this has the fun side effect that

&(*it) != it

more like dICK
Feb 15, 2010

This is inevitable.
std::transform should do that?

quiggy
Aug 7, 2010

[in Russian] Oof.


more like dICK posted:

std::transform should do that?

same problem as before re: external functions or lambdas. im intentionally making simple examples here of loop structures, ofc there are easier ways to add 1

(also std::transform and std::for_each are in libraries separate from, say, <map> so you have the added joy of more #includes, hooray)

AWWNAW
Dec 30, 2008

typedef the pain away

weird
Jun 4, 2012

by zen death robot
c++11 owns

more like dICK
Feb 15, 2010

This is inevitable.
I think that "operation I regularly apply to a map entry" is he perfect thing to encapsulate in a function but I'm in this thread so whatevs

Bloody
Mar 3, 2013

c++ is bad

quiggy
Aug 7, 2010

[in Russian] Oof.


more like dICK posted:

I think that "operation I regularly apply to a map entry" is he perfect thing to encapsulate in a function but I'm in this thread so whatevs

depends on how often you actually apply that operation i guess. plus im generally of the opinion that fewer functions = better (within reason, of course)

Bloody
Mar 3, 2013

i have an incredibly noob haskell question

okay so i have a type like:
data Butt = Fart String | Poop Int | Diarrhea Bool

and now i have a list like butts = [Butt]

and i wanna filter the list down to just Fart Strings somehow. so right now im doin like:
isFart :: Butt -> Bool
isFart (Fart _) = true
isFart _ = false

...filter (isFart) butts

this seems insanely bad. like if butts was actually butts = [Bool] i could filter (=True) butts to get True butts but because its a Fart String i don't seem to be able to do that?

gonadic io
Feb 16, 2011

>>=

Bloody posted:

i have an incredibly noob haskell question

okay so i have a type like:
data Butt = Fart String | Poop Int | Diarrhea Bool

and now i have a list like butts = [Butt]

and i wanna filter the list down to just Fart Strings somehow. so right now im doin like:
isFart :: Butt -> Bool
isFart (Fart _) = true
isFart _ = false

...filter (isFart) butts

this seems insanely bad. like if butts was actually butts = [Bool] i could filter (=True) butts to get True butts but because its a Fart String i don't seem to be able to do that?

what you are doing really is the best way.

*: you can do this using lens, or like
isFart x = case x of {(Fart _) -> True; _ -> False}
but those are both fundamentally the same thing.

Bloody
Mar 3, 2013

hmm ok. glad im not missing some hilariously trivial bit of functionality somewhere at least

im writing functions to filter my parsed statements into declarations (so i can check for duplicate identifier usage and poo poo) and usages (so i can check for unused/unreferenced identifiers)

gonadic io
Feb 16, 2011

>>=
if you then immediately get the string out, then consider doing
fartString :: Butt -> Maybe String
instead

Bloody
Mar 3, 2013

while ur here do you happen to know how to interact or at least capture state from megaparsec it's clearly a thing that can be done but is either lightly documented or i don't understand how to read the docs for it. i wanna be able to tag all this stuff im parsing out with where it came from so later when im doing stuff with it i can say "hey this thing is never used, it was declared on line 16"

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Bloody posted:

either lightly documented or i don't understand how to read the docs for it

welcome to haskell enjoy your stay

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

this is my favorite documentation ever: https://hackage.haskell.org/package/base-4.8.2.0/docs/Control-Arrow.html#t:Kleisli

its beautiful

fart simpson fucked around with this message at 20:11 on Apr 14, 2016

VikingofRock
Aug 24, 2008




Notorious QIG posted:

i pretty frequently have to iterate over stl::map objects, which is really "fun" in c++03. say i want to add one to each member of an int map keyed by strings

C++ code:
std::map<std::string, int> myMap;
...
for (std::map<std::string, int>::iterator it = myMap.begin(); it != myMap.end(); ++it) {
    ++myMap[it->first];
}
concise!

Why wouldn't you just do ++(it->second)?

quiggy
Aug 7, 2010

[in Russian] Oof.


VikingofRock posted:

Why wouldn't you just do ++(it->second)?

again because it's a simple example to demonstrate the general gist of what im talking about

christ almighty do i have to write unit tests for example code too

gonadic io
Feb 16, 2011

>>=

Bloody posted:

while ur here do you happen to know how to interact or at least capture state from megaparsec it's clearly a thing that can be done but is either lightly documented or i don't understand how to read the docs for it. i wanna be able to tag all this stuff im parsing out with where it came from so later when im doing stuff with it i can say "hey this thing is never used, it was declared on line 16"

It's been too long since I've done haskell in anger so try the haskell irc

I think the way I did it uni was to do an initial lexing lass turning each char (or token) into data CharSrc = CharSrc Char Int Int
For the line and column numbers and then writing your parsers to usually ignore the positions with a bunch of utility functions

gonadic io
Feb 16, 2011

>>=
But that was with regular parsec not mega so maybe it's built in now? It's a pretty common use case...

HoboMan
Nov 4, 2010

well great, went to check in the last few hours of work, visual studio crashes. everything i just did is gone.

AWWNAW
Dec 30, 2008

try saving your changes every once in a while. that happens automatically when you build. vs also has auto recover

Adbot
ADBOT LOVES YOU

Bloody
Mar 3, 2013

gonadic io posted:

But that was with regular parsec not mega so maybe it's built in now? It's a pretty common use case...

yeah megaparsec seems to allow it but pretty much just documents it with inscrutable type signatures heh

  • Locked thread