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




Slurps Mad Rips posted:

you actually did it right, its just that std::accumulate exists and you reimplemented it :v:

gently caress I was trying to pick a language that didn't already have some form of foldl somewhere in the standard library and I forgot about std::accumulate.

Ummm okay what about this (probably wildly unsafe and full of UB) C version?

C++ code:
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

void foldl(
    void *range, // input array to loop over and reduce
    size_t len,  // number of elements in `range`
    size_t elem_size, // size of elements in `range`
    void (binary_op)(void *, void *, void *),
    // ^ binary operation to apply to elements in range
    // first argument is the type of `result`,
    // second argument is the type of the elements of `range`
    // third argument stores the result of the operation
    void *result
    // ^ start with this as a pointer to the initial value for the fold,
    // then after `foldl` runs this will contain the result
) {
    while (len > 0) {
        binary_op(result, range, result);
        range = (void *)((char *)range + elem_size); // increment range
        --len;
    }
}
Usage:

C++ code:
void read_and_add(void *accum, void *read, void *result) {
    *(int *)result = *(int *)accum + atoi((char *)read);
}

int main() {
    char args[3][2] = {"1", "2", "3"};
    int result = 0;
    foldl(args, 3, 2, read_and_add, (void *)&result);
    printf("Sum: %d", result);
}

Adbot
ADBOT LOVES YOU

VikingofRock
Aug 24, 2008




free tibet and also, somewhat less importantly, my post

VikingofRock
Aug 24, 2008




Ugh writing anything remotely generic in C sucks. That template-filled C++ version was much more pleasant to write, and I'm considerably more confident that it did not have any UB.

Sapozhnik
Jan 2, 2005

Nap Ghost

VikingofRock posted:

and I'm considerably more confident that it did not have any UB.

:wrong:

cinci zoo sniper
Mar 15, 2013




in other baby coder news ive been writing issues for some microsoft os things and it's really cool to discuss them with the devs, although i do feel sorry they don't have anyone help them out with unfiltered internet "issue" flow

gonadic io
Feb 16, 2011

>>=

cinci zoo sniper posted:

in other baby coder news ive been writing issues for some microsoft os things and it's really cool to discuss them with the devs, although i do feel sorry they don't have anyone help them out with unfiltered internet "issue" flow

aardvaard
Mar 4, 2013

you belong in the bog of eternal stench

VikingofRock posted:

free tibet and also, somewhat less importantly, my post

i've got china on the line and they say they'll free tibet as long as your posts stay captive

cinci zoo sniper
Mar 15, 2013





visual studio is not launching on my commodore, please URGENTLY help, ASAP i implore u

Luigi Thirty
Apr 30, 2006

Emergency confection port.

cinci zoo sniper posted:

visual studio is not launching on my commodore, please URGENTLY help, ASAP i implore u

works4me

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
i'm porting a piece of software we wrote in javascript to go as a proof of concept and it's not a great language to write in if you don't know the shape of your data until runtime

that led me to a question: beyond p-langs are there any languages where it's not stupidly annoying to deal with unknown data without a predefined shape?

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Sapozhnik posted:

(which no two people seem to have a common definition for anyway)

gonadic io posted:

we are all that programmer
I am not a programmer. I am a rockstar developer.

unfortunately a rockstar like that guy from everclear but whatever

VikingofRock posted:

Ugh writing anything remotely generic in C sucks.

Soricidus
Oct 21, 2010
freedom-hating statist shill
tps: investigating out of memory errors. discovered that a coworker had decided that in order to make lookups o(1) instead of o(log n), it was worth doing a whole bunch of extra work up front and incidentally using o(n2) space instead of o(n)

this naturally makes the initial computation very expensive, so they also memoize the results, even though each is typically only used once, in an unbounded cache that appears never to remove entries

how did this ever work

Shaggar
Apr 26, 2006

John Big Booty posted:


I am not a programmer. I am a rockstar developer.

unfortunately a rockstar like that guy from everclear but whatever

bugs is right. logic belongs in the controller. logic in the model is asking for pain.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

logic in the view :unsmigghh:

Sapozhnik
Jan 2, 2005

Nap Ghost
well with react you just get trees of "components" and they can be either bits of logic or bits of view! or hey why not both!

youtube video: sapozhnik reacts to reactjs: its poo poo

ThePeavstenator
Dec 18, 2012

:burger::burger::burger::burger::burger:

Establish the Buns

:burger::burger::burger::burger::burger:

Shaggar posted:

bugs is right. logic belongs in the controller. logic in the model is asking for pain.

What would the argument even be for having logic in the model? It seems obvious that control logic should be in the controller.

Potassium Problems
Sep 28, 2001
control logic in the controller, business logic in a service layer, dumb models.

fite me

Shaggar
Apr 26, 2006

ThePeavstenator posted:

What would the argument even be for having logic in the model? It seems obvious that control logic should be in the controller.

making the model "smart" is stupid orm-think.

cinci zoo sniper
Mar 15, 2013




hmm, hadley is turning out to be about as insufferable as i suspected

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Potassium Problems posted:

control logic in the controller, business logic in a service layer, dumb models.

fite me

it's this

if you're not doing this you better have a good reason

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

VikingofRock posted:

IMO the simplest thing to do here is to wrap all the data in Rc / Arc (+ RefCell if you need to modify the contained data). If that's too expensive, then you need to carefully consider what is responsible for allocating / deallocating the data--this is the owner of the data. If you can convince Rust that the owner of the data will outlive the other thing (which it had better!), then you can have the non-owner contain references to the owner. If for some reason this doesn't work, then your next options are (1) have the non-owner contain some sort of key used to lookup and retrieve items in the owned data, or (2) use raw pointers. The last option is not really so bad--you can contain all the unsafety in the access methods, and then provide a safe interface by returning raw_ptr.as_ref().expect("aw crud that pointer was null").

Woohoo Rc did the trick, but I am definitely abusing it / using it improperly. Still, closures work now!

https://github.com/daviswahl/monkey_rs/blob/master/src/evaluator.rs

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Blinkz0rz posted:

it's this

if you're not doing this you better have a good reason

logic in the everywhere wired together with osgi

i mean, it's an application server so what can you do

aardvaard
Mar 4, 2013

you belong in the bog of eternal stench

Sapozhnik posted:

well with react you just get trees of "components" and they can be either bits of logic or bits of view! or hey why not both!

youtube video: sapozhnik reacts to reactjs: its poo poo

it's because everything on the front end should only deal with the presentation. it's all view. if you have business logic written in javascript, lol.

VikingofRock
Aug 24, 2008




MALE SHOEGAZE posted:

Woohoo Rc did the trick, but I am definitely abusing it / using it improperly. Still, closures work now!

https://github.com/daviswahl/monkey_rs/blob/master/src/evaluator.rs

Glad to hear it!

So I was just reading this proposal about improving Rust lifetime checking, and at the end of the article they mention a crate which might be useful to you in the case that you want to allocate everything in an Environment, and then have an AST contain references to that. Your program seemed like a likely possible use-case so I thought I would pass it along.

AWWNAW
Dec 30, 2008

Blinkz0rz posted:

i'm porting a piece of software we wrote in javascript to go as a proof of concept and it's not a great language to write in if you don't know the shape of your data until runtime

that led me to a question: beyond p-langs are there any languages where it's not stupidly annoying to deal with unknown data without a predefined shape?

Clojure is good for this, and spec can help too

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

carry on then posted:

logic in the view :unsmigghh:

drat it man, there are some things you don't say in public.

cinci zoo sniper
Mar 15, 2013




question of the day: is there, in some language or framework, a genuinely good plotting library that is not a hosted solution of some sort?

MeruFM
Jul 27, 2010
matplotlib?

Luigi Thirty
Apr 30, 2006

Emergency confection port.

LineTo(Integer h, Integer v)

cinci zoo sniper
Mar 15, 2013




MeruFM posted:

matplotlib?

well excluding matplotlib, ggplot, and their derivatives. i like matplotlib as a plotting device, but not really as a thing to set up or debug. ggplot is ok i suppose too, but i don't think ill ever come to like it. what i wonder if there's anything anywhere that's better than those, and not a web service.

VikingofRock
Aug 24, 2008




I've seen some pretty incredible stuff produced with gnuplot. I've never personally used it though, so I don't know if it itself is good or whether people have just managed to use it to good effect despite underlying terribleness.

Sapozhnik
Jan 2, 2005

Nap Ghost
could try d3js i guess

Corla Plankun
May 8, 2007

improve the lives of everyone

cinci zoo sniper posted:

question of the day: is there, in some language or framework, a genuinely good plotting library that is not a hosted solution of some sort?

if you want to make pretty pictures then there's a lot of different nice ways to do that inside of python notebooks, but if you want to make interactive things that are graphs it is a javascript hellscape at best unless bokeh is good now

MeruFM
Jul 27, 2010

Sapozhnik posted:

could try d3js i guess

good d3 is kind of amazing for how smooth it looks, but also takes more time than i would like to make a spinning circle expand on mouse over

Luigi Thirty
Apr 30, 2006

Emergency confection port.

d3 is good

game update: i got the game connected to game center AND sending turns back and forth between my busted old iphone 5 and my iphone 6. yase! gamekit owns

unfortunately my underlying code isn't very MVC but oh well it works ha ha ha ha

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

on swift 4, awful.app now stack overflows when entering the background due to core data and/or grmoustache

this is gonna be so fun to debug

tef
May 30, 2004

-> some l-system crap ->

Shaggar posted:

bugs is right. logic belongs in the controller. logic in the model is asking for pain.

how do you feel about stored procedures shaggar

brap
Aug 23, 2004

Grimey Drawer
i thought that "view" was your render template, "controller" contains the methods that get called when clients make requests, and "model" is literally everything else. I do very simple kinds of parsing of URL query parameters in controller methods and otherwise delegate poo poo out to another layer.

Blinkz0rz posted:

i'm porting a piece of software we wrote in javascript to go as a proof of concept and it's not a great language to write in if you don't know the shape of your data until runtime

that led me to a question: beyond p-langs are there any languages where it's not stupidly annoying to deal with unknown data without a predefined shape?

I don't know how you can write a program that operates on data whose shape you know jack poo poo about unless it's serialization or tree traversal or something else that really doesn't care how many attributes there are on a particular node or whatever, it just slurps them all up.

basically, if you can't represent the kind of program you're talking about in typescript without using `any`, something seriously hosed up is going on.

Shaggar
Apr 26, 2006

tef posted:

how do you feel about stored procedures shaggar

well that's where your business logic goes!

Adbot
ADBOT LOVES YOU

Shaggar
Apr 26, 2006
stored procs are the best cause they house your sql and abstract your application model from your data model.

  • Locked thread