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

AWWNAW posted:

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

i did save though?? this has happened before: i hit save and the little "unsaved changes" asterix goes away but then it don't actually save

Adbot
ADBOT LOVES YOU

Bloody
Mar 3, 2013

asterisk

HoboMan
Nov 4, 2010

*asterisk

also that comic was cool

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

HoboMan posted:

i did save though?? this has happened before: i hit save and the little "unsaved changes" asterix goes away but then it don't actually save

did you like blow away your local copy with whatever was in source control before you committed or something? ive never heard of saving just failing like that.

gonadic io
Feb 16, 2011

>>=

Bloody posted:

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

business as usual

Fergus Mac Roich
Nov 5, 2008

Soiled Meat

Notorious QIG posted:

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)

what is the purpose of reducing the number of functions?

i make functions that are only ever called once. i like the idea that i give a discrete bit of computation a name and an identity.

VikingofRock
Aug 24, 2008




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"

I looked into this for you, and I agree it was a pain (especially figuring out how to create a State properly--I cheated and looked at the source for runParser). Anyways hopefully this example will get you started:

code:
import qualified Text.Megaparsec as Mpc
import Text.Megaparsec.Text (Parser)
import Text.Megaparsec.Pos (initialPos, defaultTabWidth)
import qualified Data.Text as T

stateyParse :: Parser a -> T.Text -> String -> a
stateyParse parser source filename =
    case Mpc.runParser' parser (initialState source filename) of
        (_, Right val) -> val
        (state, Left err) -> error message
            where
                message =
                    "You dingus! You messed up on line " ++ line
                    ++ " column " ++ col ++ " in file " ++ file ++ "! "
                    ++ "Here's what you did wrong: " ++ show err
                (line, col, file) =
                    (show $ Mpc.sourceLine pos,
                     show $ Mpc.sourceColumn pos,
                     Mpc.sourceName pos)
                pos = Mpc.statePos state

initialState :: T.Text -> String -> Mpc.State T.Text
initialState contents name =
    Mpc.State contents (initialPos name) defaultTabWidth
You might also want to look at Text.Megaparsec.Error, which looks like it will handle a lot of the error message stuff for you. Keep in mind that even if you can't find any useful documentation about Megaparsec, you still might be able to find documentation about Parsec and most of it will still apply. Googling "haskell parsec <whatever>" will usually avoid astronomy false positives.

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo 💋 🙏
Taco Defender

Fergus Mac Roich posted:

i like the idea that i give a discrete bit of computation a name and an identity.

im reading the clean code book right now and they advocate exactly this

quiggy
Aug 7, 2010

[in Russian] Oof.


Fergus Mac Roich posted:

what is the purpose of reducing the number of functions?

i make functions that are only ever called once. i like the idea that i give a discrete bit of computation a name and an identity.

keeps anybody reading the code (yourself included) from having to jump around in a file (or multiple files!) to figure out what the code is doing. if you need code that does One Thing, write a function that does it. don't then separate One Thing into Nine Subthings and write nine functions

quiggy
Aug 7, 2010

[in Russian] Oof.


example from my current neural network code for job:

one function trainFromCsv that opens a csv file, reads data out of it, closes the csv file, and then trains itself based on that data i could do, in theory (pseudocode before someone jumps down my loving throat)
code:
function trainFromCsv(csv_file_path) {
    csv_file = fopen(csv_file_path);
    data = getdata(csv_file);
    fclose(csv_file);
    train(data);
}
but why should i when i can just do it all in one function? if i need to break it up later i can do that later, no reason to add complexity now

VikingofRock
Aug 24, 2008




Notorious QIG posted:

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

Fair enough, I actually misread your post so I thought you were complaining about the awkward map syntax. My bad. I totally agree that C++03 is really awkward and verbose since you don't have lambdas or auto.

JimboMaloi
Oct 10, 2007

Notorious QIG posted:

example from my current neural network code for job:

one function trainFromCsv that opens a csv file, reads data out of it, closes the csv file, and then trains itself based on that data i could do, in theory (pseudocode before someone jumps down my loving throat)
code:
function trainFromCsv(csv_file_path) {
    csv_file = fopen(csv_file_path);
    data = getdata(csv_file);
    fclose(csv_file);
    train(data);
}
but why should i when i can just do it all in one function? if i need to break it up later i can do that later, no reason to add complexity now

uh the reason you do it like that is because its way easier to read. if youre working in a language with a functional ide the cost of jumping to a method implementation is trivial, and then each thing is actually readable without the noise of unrelated tasks surrounding it. its precisely the 'write a function that does one thing' notion that you just stated. reading a csv file and training a neural net are 2 things

AWWNAW
Dec 30, 2008

I wonder if there's some middle ground between linear machine code and over factored function spaghetti. nah never write a function unless it's called from more than one place

Bloody
Mar 3, 2013

VikingofRock posted:

I looked into this for you, and I agree it was a pain (especially figuring out how to create a State properly--I cheated and looked at the source for runParser). Anyways hopefully this example will get you started:

code:
import qualified Text.Megaparsec as Mpc
import Text.Megaparsec.Text (Parser)
import Text.Megaparsec.Pos (initialPos, defaultTabWidth)
import qualified Data.Text as T

stateyParse :: Parser a -> T.Text -> String -> a
stateyParse parser source filename =
    case Mpc.runParser' parser (initialState source filename) of
        (_, Right val) -> val
        (state, Left err) -> error message
            where
                message =
                    "You dingus! You messed up on line " ++ line
                    ++ " column " ++ col ++ " in file " ++ file ++ "! "
                    ++ "Here's what you did wrong: " ++ show err
                (line, col, file) =
                    (show $ Mpc.sourceLine pos,
                     show $ Mpc.sourceColumn pos,
                     Mpc.sourceName pos)
                pos = Mpc.statePos state

initialState :: T.Text -> String -> Mpc.State T.Text
initialState contents name =
    Mpc.State contents (initialPos name) defaultTabWidth
You might also want to look at Text.Megaparsec.Error, which looks like it will handle a lot of the error message stuff for you. Keep in mind that even if you can't find any useful documentation about Megaparsec, you still might be able to find documentation about Parsec and most of it will still apply. Googling "haskell parsec <whatever>" will usually avoid astronomy false positives.

this is very useful tyvm

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
if you must insist on keeping all your functionality in one function you'll end up putting comments in between each 'block' of logic anyway, so it's pretty much the same thing with less discipline, more likelihood of sharing state.

with JavaScript there can be a benefit of a structure like this if you really don't wanna split it out of that single function:


code:

function digestiveSystem(food) {
  const waste = digest(food);
  const result = poop(waste);
  return result;

  function digest(food) {
    // things
  }
  function poop(waste) {
    // things
  }
}

Still the risk of sharing state in a dumb way due to the closure, but it still breaks up logical blocks, showing the overall flow and structure first, then showing the details of each step. you could always force yourself to pull the functions out of that closure too.

anything is better than a long as gently caress singular function.

quiggy
Aug 7, 2010

[in Russian] Oof.


JimboMaloi posted:

uh the reason you do it like that is because its way easier to read. if youre working in a language with a functional ide the cost of jumping to a method implementation is trivial, and then each thing is actually readable without the noise of unrelated tasks surrounding it. its precisely the 'write a function that does one thing' notion that you just stated. reading a csv file and training a neural net are 2 things

i mean i run vim/ctags so it's literally as easy as :ta <name of function> or C-] on the function name itself. that still doesn't change the fact that it's an additional step other than "scrolling down"

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen

Notorious QIG posted:

but why should i when i can just do it all in one function? if i need to break it up later i can do that later, no reason to add complexity now

no reason not to inhabit simplicity now

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





i have a job writing erlang (for services and control plane), clojure (for monitoring), scala (for spark) and elm (for dashboards). functional languages rule

Bloody
Mar 3, 2013

i have a job writing verilog. verilog is non-functional (that is, broken)

Bloody
Mar 3, 2013

verilog's most common form of flow control is a convoluted version of goto

quiggy
Aug 7, 2010

[in Russian] Oof.


Bloody posted:

verilog's most common form of flow control is a convoluted version of goto

*hits blunt*

all programs are just applications of subleq, maaaaaaan

Bloody
Mar 3, 2013

yeah and verilog is a really lovely form of subleq

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo 💋 🙏
Taco Defender

Notorious QIG posted:

i mean i run vim/ctags so it's literally as easy as :ta <name of function> or C-] on the function name itself. that still doesn't change the fact that it's an additional step other than "scrolling down"

The ideal is that you don't need to scroll down or look at the other function at all because it does exactly what the function name says

Bloody
Mar 3, 2013

imagine you wanted to do some sort of series of operations in a sequential manner

here's some code snippets for doing that in verilog:

code:
integer current_state;
localparam state_idle = 0, state_fart = 1, state_butt = 2, state_fartbutt = 3, state_yospost = 4;

always @(posedge clock) begin // lol if you ever negedge clock
	case(currentstate)
	state_idle:
		// do nothing until we have some reason to
		if(do_a_thing == 1) current_state <= state_fart;
	end

	state_fart:
		do_a_fart <= 1; 
		butt_counter <= 13'd69; // verilog numeric literals are really good actually
		current_state <= state_butt;
	end

	state_butt:
		if (butt_counter == 0) begin
			current_state <= state_fartbutt;
		end else begin
			butt_counter <= butt_counter - 1;
		end
	end

	state_fartbutt:
		do_a_fart <= 0; // finally clear the fart-doing because are counter expired
		current_state <= state_idle;
	end
	endcase
end

Bloody
Mar 3, 2013

like yeah its a language that lives in some wonky concurrent-as-default space instead of the typical sequential-as-default space but goddamn is it tedious to do anything sequential, which sucks rear end when doing sequential work in a concurrent-as-default space is a hideously common pattern

Bloody
Mar 3, 2013

equivalent C would just be like
while (!do_a_thing);
do_a_fart = 1;
butt_counter = 69;
while(butt_counter != 0) butt_counter--;
do_a_fart = 0;

Bloody
Mar 3, 2013

once my parser-linter works well enough i am going to create verilog++ which will first allow for implicit state declaration (note how we had to declare each valid state as a separate compile-time constant numeric value; the synthesis tools straight up throw these out as soon as they realize you're making a state machine and encode it however they want. its loving ridiculously dumb)

Bloody
Mar 3, 2013

thats my intoxicated pentapost about how loving dumb verilog is thanks for reading

Corla Plankun
May 8, 2007

improve the lives of everyone
can anyone recommend a course or book or open source project that makes java seem worth learning?

i hate basically everything i know about the language but people keep making interesting things in it so i guess i should stop trying to avoid it an figure out why everyone uses it for everything

Bloody
Mar 3, 2013

people make interesting things in java? since when? i thought everyone used it in a kind of lowest common denominator/cant shoot yourself in the foot sort of way

quiggy
Aug 7, 2010

[in Russian] Oof.


Illusive gently caress Man posted:

The ideal is that you don't need to scroll down or look at the other function at all because it does exactly what the function name says

and trainFromCsv() trains the network from a .csv

your point?

Corla Plankun
May 8, 2007

improve the lives of everyone

Bloody posted:

people make interesting things in java? since when? i thought everyone used it in a kind of lowest common denominator/cant shoot yourself in the foot sort of way

basically everything relating to distributed computation is in java or sometimes a java-based other language, i do not know why

Bloody
Mar 3, 2013

weird langs get picked for odd tasks all the time; see also lua and machine learning

gonadic io
Feb 16, 2011

>>=

Corla Plankun posted:

can anyone recommend a course or book or open source project that makes java seem worth learning?

i hate basically everything i know about the language but people keep making interesting things in it so i guess i should stop trying to avoid it an figure out why everyone uses it for everything

What other programming experience do you have?

PokeJoe
Aug 24, 2004

hail cgatan


i like java

Bloody
Mar 3, 2013

it turns out that this parser state business does not do what i hoped and also i have no idea what i am doing

Luigi Thirty
Apr 30, 2006

Emergency confection port.

same

good thing I have this hardware debugger for arduinos

Fergus Mac Roich
Nov 5, 2008

Soiled Meat

PokeJoe posted:

i like java

me too kinda

Bloody
Mar 3, 2013

i like that ive cobbled together a language parser in haskell without a drat clue at all what's going on

Adbot
ADBOT LOVES YOU

Jerry Bindle
May 16, 2003

Bloody posted:

i like that ive cobbled together a language parser in haskell without a drat clue at all what's going on

that's how I feel all the time when programming racket. it's so easy to slowly build up something that does something useful, then at the end have no clue how it works

  • Locked thread