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.
 
  • Post
  • Reply
mystes
May 31, 2006

Symbolic Butt posted:

the1percent/the99percent
Capitalist/proletariat

Adbot
ADBOT LOVES YOU

VikingofRock
Aug 24, 2008




gru/minion

mystes
May 31, 2006

My favorite OS

gonadic io
Feb 16, 2011

>>=
ctps:
code:
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Bloody
Mar 3, 2013

gonadic io posted:

ctps:
code:
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

:stonk:

VikingofRock
Aug 24, 2008




before posting that you oughta warn us to brace ourselves!

gonadic io
Feb 16, 2011

>>=

VikingofRock posted:

before posting that you oughta warn us to brace ourselves!

:v:

i'm just loving around writing a scrabble thing but got caught in a bunch of nested loops: https://github.com/djmcgill/Rubble/blob/master/src/main.rs

i might legit try something like https://github.com/TeXitoi/rust-mdo to let me nest loops without increasing indentation which i could do with a bunch of and_then idk

VikingofRock
Aug 24, 2008




gonadic io posted:

:v:

i'm just loving around writing a scrabble thing but got caught in a bunch of nested loops: https://github.com/djmcgill/Rubble/blob/master/src/main.rs

i might legit try something like https://github.com/TeXitoi/rust-mdo to let me nest loops without increasing indentation which i could do with a bunch of and_then idk

I think that's a bit overkill here. I got rid of four levels of indentation by replacing your match statements with if lets. It even fits within 80 columns now! IMO this sort of strategy is the way to go when only one match arm can logically continue the function.

As for the rest of the indentation, most of it comes from nested for loops. A lot of times those can be logically separated out into an iterator, which can then be chained together in all the usual ways. For example here you could imagine making an ConnectedTiles iterator that returns all tiles connected to a given start tile and then in all_tiles_connected() just return whether your total tile count is the same as connected_tiles(arbitrary_tile).count(), or for the inner loop you could make a Neighbors iterator which gives the neighbors of a given tile.

VikingofRock fucked around with this message at 22:49 on Sep 13, 2018

Lime
Jul 20, 2004

i think using let match would look a bit nicer than if let:
code:
let (x, y) = if let Some((x, y)) = queue.pop_front() {
    (x, y)
} else {
    return tiles.is_empty();
};
vs
code:
let (x, y) = match queue.pop_front() {
    Some(p) => p,
    None => return tiles.is_empty()
};

VikingofRock
Aug 24, 2008




Lime posted:

i think using let match would look a bit nicer than if let:
code:
let (x, y) = if let Some((x, y)) = queue.pop_front() {
    (x, y)
} else {
    return tiles.is_empty();
};
vs
code:
let (x, y) = match queue.pop_front() {
    Some(p) => p,
    None => return tiles.is_empty()
};

:doh: I don't know how I forgot that. Yeah your way is much better.

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
in my opinion the all_tiles_connected method is just begging to be broken into at least 3 methods there

gonadic io
Feb 16, 2011

>>=
ty for the suggestions. the lack of early return from a mapping closure bothers me way more than i thought it would. maybe generators solves this?

VikingofRock
Aug 24, 2008




gonadic io posted:

ty for the suggestions. the lack of early return from a mapping closure bothers me way more than i thought it would. maybe generators solves this?

I recently ran into a way to get around this. The idea is you use filter_map() to end iteration early and then check a sentinel value.

code:
use std::io::{BufRead, BufReader};

// just to make this a little easier, realistically you'd have a specific error
// type with the relevant conversions
type GenericResult<T> = Result<T, Box<std::error::Error>>;

fn main() -> GenericResult<()> {
    let stdin = std::io::stdin();
    let mut readline_result: GenericResult<()> = Ok(());
    let mut parse_result: GenericResult<()> = Ok(());
    let sum: i64 = BufReader::new(stdin.lock())
        .lines()
        .filter_map(|lr| {
            lr.map_err(|e| {
                readline_result = Err(e.into());
            }).ok()
        }).filter_map(|l| {
            l.trim()
                .parse::<i64>()
                .map_err(|e| {
                    parse_result = Err(e.into());
                }).ok()
        }).sum();
    readline_result.and(parse_result)?;
    println!("sum: {}", sum);
    Ok(())
}
(playground)

You could pretty easily extend this to returning things besides Option or Result. Whether this is a clever trick or a dirty hack is left as an exercise to the reader.

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.
FB's PHP compiler to end support for PHP: https://hhvm.com/blog/2018/09/12/end-of-php-support-future-of-hack.html

gonadic io
Feb 16, 2011

>>=

VikingofRock posted:

I recently ran into a way to get around this. The idea is you use filter_map() to end iteration early and then check a sentinel value.

(playground)

You could pretty easily extend this to returning things besides Option or Result. Whether this is a clever trick or a dirty hack is left as an exercise to the reader.

lol nice
1) use the failure crate for all projects imo
2) there is an either crate too but you might have to duplicate the machinery and they're the same thing anyway so why bother

gonadic io fucked around with this message at 02:15 on Sep 14, 2018

gonadic io
Feb 16, 2011

>>=
you cna have short-circuiting iterators with generators - playground

e: although if you're writing a custom looping function I guess you can just do the same thing with options but with None and Some instead of Yield and Return

code:
run_short<A, B, I: Iterator<Item=A>, F: Fn(A) -> Option<B>(i: I, f: F) -> Option<B> {
    for a in i {
        match f(a) {
            None => {},
            some_b => return some_b,
        }
    }
    None
}
e2: and now I've reimplemented Iterator::find. poo poo.

gonadic io fucked around with this message at 02:26 on Sep 14, 2018

mystes
May 31, 2006

It must be difficult for Facebook employees to choose between not-javascript, not-ocaml, and not-PHP now.

animist
Aug 28, 2018
jonathan blow is mad about rust:

https://www.youtube.com/watch?v=4t1K66dMhWk

dont watch the video. it's way too long. it sucks

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

animist posted:

jonathan blow is mad about rust:

https://www.youtube.com/watch?v=4t1K66dMhWk

dont watch the video. it's way too long. it sucks

I'm the voice he does here:

https://www.youtube.com/watch?v=4t1K66dMhWk&t=711s

brand engager
Mar 23, 2011

People care about what that dude thinks about anything?

Slurps Mad Rips
Jan 25, 2009

There's No Guarantee

brand engager posted:

People care about what that dude thinks about anything?

yes unfortunately


Symbolic Butt posted:

I'm the voice he does here:

im the part where he unironically says "Like a lot of new programming languages are made by people who just are making small stylistic changes..." without any self awareness whatsoever :v:

VikingofRock
Aug 24, 2008




ctps: defending my dissertation today

somehow all this terrible programming paid off!

brand engager
Mar 23, 2011

lmao the first mention of it I see on my twitter feed is a thread making GBS threads on him
https://twitter.com/ManishEarth/status/1040599002557960197

MrMoo
Sep 14, 2000

brand engager posted:

lmao the first mention of it I see on my twitter feed is a thread making GBS threads on him
https://twitter.com/ManishEarth/status/1040599002557960197

I measured 30 mins for what only seemed the first 10s of her talk, though her presentation sounds a lot worse than his. Also, he's probably right.

akadajet
Sep 14, 2003

animist posted:

jonathan blow

animist posted:

dont watch

that's a given

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

MrMoo posted:

I measured 30 mins for what only seemed the first 10s of her talk, though her presentation sounds a lot worse than his. Also, he's probably right.

Jonathan blow is never right

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
I watched almost all of it, around 30min he finally gets to the main point which is this:

Jonathan Blow posted:

it seems like a little bit of Stockholm's syndrome to me where it's like "oh the borrow checker is so good because it made me program in this certain pattern. but the real reason the borrow checker is not complaining anymore is just that I managed to turn it off but I didn't realize that that's what I did"

and he isn't 100% sure if that's what's really going on, which is fine but I'm not sure why he is wrapping this query in an 1 hour long video rant

btw this is a pattern that I noticed about rust programmers before and in the end maybe he kinda has a point here but just lol at jblow

cinci zoo sniper
Mar 15, 2013




VikingofRock posted:

ctps: defending my dissertation today

somehow all this terrible programming paid off!

good luck

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Symbolic Butt posted:

I watched almost all of it, around 30min he finally gets to the main point which is this:


and he isn't 100% sure if that's what's really going on, which is fine but I'm not sure why he is wrapping this query in an 1 hour long video rant

btw this is a pattern that I noticed about rust programmers before and in the end maybe he kinda has a point here but just lol at jblow

You mean smashing keys until it works doesn't leave you with a greater understanding of what's happening underneath? Hot Take!

white sauce
Apr 29, 2012

by R. Guyovich
Hi, I'm a fng learning Java and I need help with my first set of Homework for my programming class :downs: It's very basic stuff but I have 0 experience with this and the assignment is pretty difficult.

I'll be willing to paypal or venmo you $ for the time spent helping me. Feel free to send a PM if it interests you.

Also, feel free to own me for being such an idiot and posting this in this thread. Thanks!

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
what’s a fng

white sauce
Apr 29, 2012

by R. Guyovich
loving new guy

comedyblissoption
Mar 15, 2006

Symbolic Butt posted:

I watched almost all of it, around 30min he finally gets to the main point which is this:


and he isn't 100% sure if that's what's really going on, which is fine but I'm not sure why he is wrapping this query in an 1 hour long video rant

btw this is a pattern that I noticed about rust programmers before and in the end maybe he kinda has a point here but just lol at jblow
the only way you "turn off" the static borrow checker is wrapping your stuff in abstractions like RC (like reference-counted smart pointers) though, and rust idioms typically don't require you to do this

I don't really see how jblow's paraphrased criticism is applicable, and I'm not willing to watch an hour long rant to see him ignore all the benefits of the system

edit: i guess the other interpretation here is i guess he means you start programming in a style you don't need to constantly borrow poo poo in the first place like you might in other languages? i really don't see anything wrong with this

comedyblissoption fucked around with this message at 20:02 on Sep 14, 2018

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.
*jblow voice* you really need to use a smart pointer here

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

comedyblissoption posted:

the only way you "turn off" the static borrow checker is wrapping your stuff in abstractions like RC (like reference-counted smart pointers) though, and rust idioms typically don't require you to do this

I don't really see how jblow's paraphrased criticism is applicable, and I'm not willing to watch an hour long rant to see him ignore all the benefits of the system

edit: i guess the other interpretation here is i guess he means you start programming in a style you don't need to constantly borrow poo poo in the first place like you might in other languages? i really don't see anything wrong with this

his thesis is something like "she unwittingly wrote an arena-style memory allocator to fool the borrow checker" which seems to be the usual way to go in games written in C++ anyway.

but anyway I still didn't watch the original video by the rust programmer yet but I'm beginning to suspect that she didn't really imply what he's saying she implied, that the "righteous borrow checker guided her to do the right design".

Slurps Mad Rips
Jan 25, 2009

There's No Guarantee

Symbolic Butt posted:

his thesis is something like "she unwittingly wrote an arena-style memory allocator to fool the borrow checker" which seems to be the usual way to go in games written in C++ anyway.

but anyway I still didn't watch the original video by the rust programmer yet but I'm beginning to suspect that she didn't really imply what he's saying she implied, that the "righteous borrow checker guided her to do the right design".

lol but she didn't. jblow has this terrible affliction where he opens his mouth sticks his foot into it and then blames feminism for why he's getting dunked on for his dumb as hell views. please think of this rational, clearly thick skinned, reasonable man's feelings

also, just fuckin' lol at an hour long response to a 5 minute portion of a 45 minutes video he didn't watch all the way through

(also, rust doesn't permit per-container allocators yet, so no, she did not write an arena allocator. she wrote an ecs in rust where she doesnt have to worry about an invalid entity bringing the entire system to its knees)

animist
Aug 28, 2018

Symbolic Butt posted:

I'm beginning to suspect that she didn't really imply what he's saying she implied, that the "righteous borrow checker guided her to do the right design".

iirc the first half of the keynote was in c++, she showed how traditional OO poo poo completely falls apart for games, and why ECS is good design. then she moves over to rust, and shows that ECS has a bunch of benefits aside from working well with the borrow checker.

MrMoo posted:

Also, he's probably right.

:wrong:

MrMoo
Sep 14, 2000

Slurps Mad Rips posted:

(also, rust doesn't permit per-container allocators yet, so no, she did not write an arena allocator. she wrote an ecs in rust where she doesnt have to worry about an invalid entity bringing the entire system to its knees)

He covered that, he calls it "arena" according-to-him, but not what other people (tm) may understand as that. Invalid entity is fairly mild and Blow says a crash would be better than hiding it because you can go debugging and fix it quickly. The allocator scheme she creates allegedly does not eliminate an incorrect but valid entity being presented due to possessing a stale reference and so the language is not really helping at all and required the same development strategy other languages require too.

Sapozhnik
Jan 2, 2005

Nap Ghost
What is an ecs

Adbot
ADBOT LOVES YOU

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Sapozhnik posted:

What is an ecs

entity component system

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply