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
VikingofRock
Aug 24, 2008




Can we talk about the elephant in the room here? What possessed everyone to use

C++ code:

/* these comments */

instead of

C++ code:

// these comments

? C99 turns twenty next year...

Adbot
ADBOT LOVES YOU

VikingofRock
Aug 24, 2008




Hey male shoegaze if you're getting exponential compilation times you should file an issue on the rust GitHub. They take solving that sort of thing pretty seriously so I'm sure they would be very interested in hearing about your case.

VikingofRock
Aug 24, 2008




jit bull transpile posted:

Looks like X really gave it to ya

VikingofRock
Aug 24, 2008




LaTeX makes me so goddamn unreasonably mad. I just wanna make a flowchart for my paper, but somehow just importing TikZ (the standard package for this AFAICT) causes my paper to no longer compile.

My hacky solution is to move all my flowchart generation to a wholly separate LaTeX project, then just include the PDF generated by that. Which isn't too bad; but it's so frustrating that I have to do that instead at all of it just working. And I guarantee that the whole problem would be fixed if LaTeX just had namespacing so that packages wouldn't define conflicting macros, but it doesn't so this sort of thing happens all the time.

(LaTeX is technically a programming language so this post is technically on topic. I'd post it to the grad students thread or the LaTeX thread but people are way too serious there)

VikingofRock
Aug 24, 2008




Corla Plankun posted:

i havent done latex in a while but when i was in grad school if i needed a chart i would make it as an svg with a more reasonable program and then include it as a pic in the latex doc

I actually have that right now. The issue is that the fonts don't match, and one of the co-authors mentioned it in review.

VikingofRock
Aug 24, 2008




pangstrom posted:

I have 2 friends who loving love LaTex and 1 who has that opinion (it sucks / is janky / causes workflow issues). Is there a Goon consensus on that because I have been using the 1 friend + laziness as an excuse not to go there.

Last time I checked, the goon consensus was "it's terrible but also better than the other options" (which I would agree with). In a lot of scientific communities you don't really have a choice on whether to use it or not though, so it kind of doesn't matter whether it's good or bad.

Honestly if it just had any sort of macro hygiene it would be loads better. But it doesn't and it's probably too late to add it now.

e: beaten by goon consensus, almost word-for-word

VikingofRock
Aug 24, 2008




gonadic io posted:

Lol what a li'l bitch

Honestly it was more of a "fix if it's not too much of a pain" sort of thing. I guess maybe this is approaching the "it's too much of a pain" point, but I do need to make a few other changes to the flowchart so I might as well see if I can get this working while I'm at it.

VikingofRock
Aug 24, 2008




Corla Plankun posted:

can you change the doc to match the svg instead?

Nah, it's gotta match the journal template.

Honestly, remaking the flowchart in a separate doc in latex is not such a hassle, and it'll come in handy anyways as I work this into my thesis (which I am writing concurrently). I just wanted to vent a little bit because, as previously stated, "latex makes me so goddamn unreasonably mad" with how brittle it is. Thanks everyone for listening to my venting and for the suggestions.

VikingofRock
Aug 24, 2008




MALE SHOEGAZE posted:

looks like i've got myself a (limited, part time, contracting) rust job and i'm very pleased. in addition to rust i'll also get to put MIT on my resume which is cool, i think.

Congrats!!! That is super cool

VikingofRock
Aug 24, 2008




cheque_some posted:

What would you recommend for someone who is a self-taught terrible devopsing p-langing programmer but want to become a non-terrible programmer


at the point where I can make a CRUD (more like cruddy) program, that does what I want it to, but how do I get to the point where it's something professional grade. like how do you learn how to architect programs and when to use a lookup table instead of just a bunch of if-statements, and architect using different controllers instead of all just in one main, and optimized code, and all that other stuff. It seems like there's tons of 'learn to program' sites like codeacademy and all that, but they never go beyond loops and if statements and arrays.

Are there any books or sites that teach you how to go from beginning to intermediate level?

In addition to what other people have said, it can be pretty useful to learn by just studying what other people have done. IMO one of the best ways to do this is to find some friendly medium-sized open source project that you are interested in, go to their issues page, and pick a bug / small feature request and start working on it. Doing so will get you going through the project's code and seeing how it's laid out and organized, and you'll learn a ton from that. Plus, you'll feel really cool when they accept your pull request and you've improved the open source ecosystem in some small way.

VikingofRock
Aug 24, 2008




VikingofRock
Aug 24, 2008




For what it's worth this RFC just got accepted so rust's Error trait should improve soon™.

VikingofRock
Aug 24, 2008




I'm surprised that Go has pointers, although I guess I shouldn't be because it's so C-inspired. It's just I've never seen pointers in a garbage-collected language before. I'm guessing this means things in Go are copied on assignment / being passed to a function, and pointers are a way to explicitly avoid that copy? Is there ever a way to get a dangling pointer in Go, or does having a pointer to an object prevent that object from being garbage collected?

VikingofRock
Aug 24, 2008




DONT THREAD ON ME posted:

this is the best info i can find really:

https://golang.org/doc/faq#Pointers

i think it's not that different from java in practice

Okay yeah after reading through that it looks like assignment and argument passing both invoke a shallow copy of the data, and there's no way to get a dangling pointer without using unsafe.Pointer.

It's been a long time since I used Java so I can't remember how memory semantics work there. The only GC languages I commonly used nowadays are Python and Haskell. I've only recently felt like I really understood Python's assignment semantics and in Haskell things are generally immutable so it mostly doesn't matter whether things are copied deeply, shallowly, or not at all.

VikingofRock
Aug 24, 2008




DONT THREAD ON ME posted:

speaking of assignment semantics, rvalue references are weird after doing rust.

other weird c++ stuff:

1. templates are not generics. they're so weird! they feel both more and less powerful than generics.
2. ugh, the class system...
3. googling for things is bad. online documentation is bad. cpp reference is the best resource i've found, and i can't imagine learning from this if I were new to programming holy poo poo.
4. exceptions look like a rabbit hole
5. no interfaces or traits, just abstract classes. i'm sure there are some more esoteric mechanisms for these things though. i really love interfaces though and cant imagine programming without them.

you can really feel the age of the language. i think i was expecting "modern" c++ to feel more modern but it really doesn't. esp the OO stuff, which was like, the original impetus for the language, but is now not really the selling point it used to be,.

I pretty much agree with all of your impressions. C++ was the first language I got comfortable with, and I basically did it by reading through an Herb Sutter book followed by one of the Scott Meyers books (this was around 2010 so I was learning C++03). Those two authors come from a specific school of C++ thought which basically says that you should pretty rarely use inheritance at all. Templates cover a lot of the same functionality that you would use traits / interfaces for; just think of the constraints as being implicit from the function that you are writing ("I use the + operator here") instead of explicit ("my arguments implement Addable").

VikingofRock
Aug 24, 2008




Also now that I've thought a little more on Go's shallow-copy-on-assignment, I'm a little perturbed by it. It seems to me like that breaks encapsulation a bit too much. For example, if I'm using a Point3D type, I shouldn't worry if internally the x, y, and z coordinates are stored as three separate member floats or as a single vector of three floats. But with shallow copy semantics, all of the sudden those are very different semantically if I pass a Point3D to a function and then mutate one of the coordinates.

Admittedly I've never used Go so it's possible I'm misreading the copy semantics or that there are idioms which mitigate this issue. But as I understand it it seems like a weird choice to me.

VikingofRock
Aug 24, 2008




CRIP EATIN BREAD posted:

c++11 has traits as part of its stdlib

Not really in the same way that e.g. rust has traits, which is what I was talking about here. C++ traits are more like type tags; in C++ terms I'm talking about concepts.

VikingofRock
Aug 24, 2008




DONT THREAD ON ME posted:

yeah, it's a very different approach. my main worry is ambiguity, it seems like you could easily have two different types that each have a "foo" method with the same input/return types but wildly different semantics. it's like duck typing.

This is exactly true, but in practice it doesn't really bite you too often.

VikingofRock
Aug 24, 2008




CRIP EATIN BREAD posted:

idk, boost's entire geometry system has a way of doing things like:

Jesus, it's their first week of C++! Don't show them boost, you'll scare them!

VikingofRock
Aug 24, 2008




stoked for pijul to hit 1.0 someday

VikingofRock
Aug 24, 2008




tef posted:

git has parts of a sensible user interface, somewhere, but it's hidden behind a bunch of other flags

git diff --cached/git diff --staged

git add -u

git log --first-parent

git pull --autostash --rebase

git push --force-with-lease

git log --branches --not --remote

git diff @{upstream}

and i forgot the other thing that you can make an empty commit as your first init commit so when you make a new clean branch it's actually empty

drat, this is good poo poo. I only knew about like a third of these.

VikingofRock
Aug 24, 2008




prisoner of waffles posted:

git has to be among the top 10 command line programs for sheer complexity of the possible valid command-line inputs.

tef or others, can you think of any others that might make the list?

find has a ton of options which I've seen used in fairly creative ways. sed always seems to have a bunch of interesting and obscure uses, too. And of course awk can be used for all kinds of things but that one might be cheating because awk is basically a full programming language.

VikingofRock
Aug 24, 2008





Neat! I actually think find is probably Turing complete too. The reason I specifically called out awk there because it was designed to be more of a full programming language than the other two. E.g. from the man page:

quote:

The awk utility shall execute programs written in the awk programming language, which is specialized for textual data manipulation.

VikingofRock
Aug 24, 2008




DONT THREAD ON ME posted:

it would not be that difficult to design some sort of shell prelude that makes f#/haskell feel a lot like bash but with types.

might be kinda fun to try it in rust.

It already exists: https://hackage.haskell.org/package/turtle

e: dammit gonadic io!

VikingofRock
Aug 24, 2008




mystes posted:

I haven't tried Turtle but it seems to just be oriented around running unix commands. I guess maybe I should try it because at the least that would make it easier to explain why it's not what I'm looking for.

It's more of a reimplementation of common unix commands' core functionalities, and instead of just doing text transformations it has Haskell's type system. So really I'd say it's less "Turtle is oriented around running unix commands" and more "Turtle often names its functions after similar Unix commands".

I've never used Turtle interactively as my main shell or anything, but I've used it to write what would have been medium-length shell scripts and it's pretty nice for that.

VikingofRock
Aug 24, 2008




mystes posted:

Do you know why the following doesn't work?
code:
Prelude Turtle> ls "." >>= mapM stat

<interactive>:25:12: error:
    • Couldn't match type ‘Turtle.FilePath’ with ‘t Turtle.FilePath’
      Expected type: Turtle.FilePath -> Shell (t FileStatus)
        Actual type: t Turtle.FilePath -> Shell (t FileStatus)
    • In the second argument of ‘(>>=)’, namely ‘mapM stat’
      In the expression: ls "." >>= mapM stat
      In an equation for ‘it’: it = ls "." >>= mapM stat
    • Relevant bindings include
        it :: Shell (t FileStatus) (bound at <interactive>:25:1)
Prelude Turtle> :t (mapM stat)
(mapM stat)
  :: (MonadIO m, Traversable t) =>
     t Turtle.FilePath -> m (t FileStatus)
Prelude Turtle> :t (mapM)
(mapM) :: (Monad m, Traversable t) => (a -> m b) -> t a -> m (t b)
Is the problem that Shell isn't traversable?

The issue is that you don't want mapM here at all. stat in this case has type Turtle.FilePath -> Shell FileStatus, so you want to just do ls "." >>= stat.

Think of Shell as being the List + IO (+ Managed). The list part is relevant here because whenever you use >>= the mapping over shell elements is already implied.

VikingofRock
Aug 24, 2008




gonadic io posted:

wait there's a bunch of list functions implemented on a shell so that makes it easier
i think the best i can do (i think, i'm just doing these off the top of my head i haven't touched a haskell compiler in months) with the same semantics is
code:
main = ls "." & (>>= stat) & sortOn modificationTime & limit 5 & fmap fileSize & flip fold Fold.sum & view
god drat i wish haskell had member syntax

p.s. if you use `flip` in haskell you're doing something wrong 100% it is only ever used for stupid golfing like this. perfect for shell scripts!

I think you've got a type error there in the fmap FileSize, since the stuff before that is a Shell [FileStatus] not a Shell FileStatus. You gotta either (fmap . fmap) the fileSize or (better yet) combine the Shell [FileStatus] into a Shell Filestatus with fmap select & join. Something like:

code:
ls "." >>= stat & sortOn modificationTime & fmap select & join & fmap fileSize & flip fold Fold.sum
which is honestly about as reasonable as the original powershell.

VikingofRock fucked around with this message at 01:56 on Sep 6, 2018

VikingofRock
Aug 24, 2008




The fmaps get pretty annoying after a while. Maybe they'll add an operator

a &| f = fmap f a

with the same precedence as &

VikingofRock
Aug 24, 2008




Luigi Thirty posted:

homemade lisp status:



:yosnice:

VikingofRock
Aug 24, 2008




Symbolic Butt posted:

maybe in 30 years someone will find a neat application of octonions in programming, it'll be rad

clifford algebras all the way imo

VikingofRock
Aug 24, 2008




gru/minion

VikingofRock
Aug 24, 2008




before posting that you oughta warn us to brace ourselves!

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

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.

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.

VikingofRock
Aug 24, 2008




ctps: defending my dissertation today

somehow all this terrible programming paid off!

VikingofRock
Aug 24, 2008




today I saw how to make (& wrap) a burrito with 44 different recipes on my reddit feed and at first glance assumed it was a rust monad tutorial

VikingofRock
Aug 24, 2008




Kilometres Davis posted:

I've been using VS Code and just run cargo from the terminal. Often the syntax highlighting is a little slow but I spent years working on systems that were further apart than the earth's radius so I hardly notice it. I'd still it to be better ofc. I might give Intellij a try.

Is clippy any good though? I haven't used it because, you know, clippy.

clippy is very good and you should run it on all of your rust projects. not only will it help you catch a lot of subtle errors, but also it's great at pointing out "there's an easier way to do that", especially with iterators and option / result.

VikingofRock
Aug 24, 2008




Are there reverse zip bombs? Like where a reasonably-sized input has a gigantic zipped form. I know that by the pigeonhole principle there are inputs with zipped forms that are larger than the original input, but my guess would be that there is an upper limit on this potential growth.

Adbot
ADBOT LOVES YOU

VikingofRock
Aug 24, 2008




cinci zoo sniper posted:

okay, the last two lines are a warcrime.

if you don’t care about order

tmp.append(''.join(split)) inside and tmp = list(set(tmp)) outside loop

if you care about order, do the same with tmp but outside

result = []
[result.append(i) for i in tmp if i not in result]

before loop: tmp = {}
inside loop: tmp[i] = None
after loop: tmp = list(tmp)

e: assuming that this is in Python 3.7+, where dicts are guaranteed to preserve insertion order. Otherwise, make tmp an OrderedDict at first

VikingofRock fucked around with this message at 02:49 on Sep 29, 2018

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