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
Venuz Patrol
Mar 27, 2011

fleshweasel posted:

c tp s: can someone help me

just use your hand

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

Bloody posted:

nah not super noice they generally wind up not hiring me lmao

me in an interview

"we want you to write a function that returns all possible combinations of a list of lists, any language"

so like, any? echo {a,b,c}{d,e,f} in bash stuff

"yes any language"

ok, here's it in prolog: comb([],[]). comb([H|T],[X|O]) :- member(X, H), comb(T,O).



i only found out later that one of them left the interview and asked around the office to find someone who knew prolog to check it

tef
May 30, 2004

-> some l-system crap ->
"can u reverse a linked list"

ok here it is in python using tuples, i think the free-list + refcounting will ensure that it's effectively fixed memory usage

"what"

no seriously, ugh do you want it in another language

"yes"

fine here is a java one

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

tef posted:

me in an interview

"we want you to write a function that returns all possible combinations of a list of lists, any language"

so like, any? echo {a,b,c}{d,e,f} in bash stuff

"yes any language"

ok, here's it in prolog: comb([],[]). comb([H|T],[X|O]) :- member(X, H), comb(T,O).



i only found out later that one of them left the interview and asked around the office to find someone who knew prolog to check it

lol

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

tef posted:

me in an interview

"we want you to write a function that returns all possible combinations of a list of lists, any language"

so like, any? echo {a,b,c}{d,e,f} in bash stuff

"yes any language"

ok, here's it in prolog: comb([],[]). comb([H|T],[X|O]) :- member(X, H), comb(T,O).



i only found out later that one of them left the interview and asked around the office to find someone who knew prolog to check it
i'm going to guess from their reaction that you did not get the job, or hopefully that you did not accept that job

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?
ooh! ooh!

now do APL!

edit: Rosetta code to the rescue:

pre:
A[I]←1+I←(0⍷A)/⍳⍴A←('FIZZBUZZ' 'FIZZ’ 'BUZZ' 0)[2⊥¨×(⊂3 5)|¨1+⍳100]

eschaton fucked around with this message at 10:40 on Dec 3, 2016

Xarn
Jun 26, 2015
c Java s: Netbeans just told me that I will have an infinite recursion and it was right. If it keeps being helpful, I might actually start liking it. :v:

redleader
Aug 18, 2005

Engage according to operational parameters
recursion? uh, this is the terrible programmer thread

Soricidus
Oct 21, 2010
freedom-hating statist shill

eschaton posted:

no see this should tell you that you're doing something entirely wrong by even thinking of using popen

this is kind of my point. you want to do a high level thing in c, and there's a convenient, obvious, high level function that does almost what you want, but not quite, and also it's got other serious flaws that mean you shouldn't use it anyway. so you're left flailing around in a sea of hard-to-use primitives, each of which introduces more exciting gotchas.

tef
May 30, 2004

-> some l-system crap ->

anthonypants posted:

i'm going to guess from their reaction that you did not get the job, or hopefully that you did not accept that job

i needed money and worked there until i was made redundant after 11 months, during that time i had seven different managers and three written warnings (all dismissed)

http://thedailywtf.com/articles/The-Difference-Between-Better-and-Less-Bad may run very close to the original environment for screen scraping. i wrote a python replacement and somehow convinced a MSSQL/C#/Windows shop to deploy a linux/python web service

they still use my code, or at least in a ship of theseus way, almost 9 years on

Arcsech
Aug 5, 2008
what does "key" mean in sql/innodb? like, not "primary key" or "foreign key", just "key". is it just an index?

specifically the ones here

this is loving impossible to google because of everything talking about primary or foreign or whatever keys

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
from the mysql doc for the create table syntax

KEY | INDEX

KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY can also be specified as just KEY when given in a column definition. This was implemented for compatibility with other database systems.


so yeah it seems it's just another way to say index. "normally" anyway, whatever that means

Bloody
Mar 3, 2013

how do I find remote contract work I want to make side cash

Luigi Thirty
Apr 30, 2006

Emergency confection port.

how is it this hard to save a drat 48x32 rectangle into a memory buffer and load it back again each frame with the Amiga blitter aaag

Xarn
Jun 26, 2015
c Java s: Java enums are sweet. Not being able to make ArrayList<int> less so. Having to reason about this mess
Java code:
ArrayList<ArrayList<ArrayList<Integer>>> butts = new ArrayList<>();
ArrayList<ArrayList<ArrayList<Poop>>> poops = new ArrayList<>();
ArrayList<ArrayList<Integer>> turds = new ArrayList<>();
sucks rear end. Especially since the same index is used to index each of them at different places. :suicide:

Soricidus
Oct 21, 2010
freedom-hating statist shill

Xarn posted:

c Java s: Java enums are sweet. Not being able to make ArrayList<int> less so. Having to reason about this mess
Java code:

ArrayList<ArrayList<ArrayList<Integer>>> butts = new ArrayList<>();
ArrayList<ArrayList<ArrayList<Poop>>> poops = new ArrayList<>();
ArrayList<ArrayList<Integer>> turds = new ArrayList<>();
sucks rear end. Especially since the same index is used to index each of them at different places. :suicide:

ouch. I generally take deeply nested collections like this and write a goddamn class that represents the actual thing you're working with instead of the data structure used to store it. it's not 1996 any more, adding another class isn't going to hurt performance.

fritz
Jul 26, 2003

redleader posted:

recursion? uh, this is the terrible programmer thread

'doing a recursive implementation when there's a perfectly good imperative solution' is primo terrible programmer territory

fritz
Jul 26, 2003

eschaton posted:

I still don't understand how Python has taken off here rather than Maxima

maxima's for symbolic manipulation but these eigenvectors aren't going to find themselves

ComradeCosmobot
Dec 4, 2004

USPOL July

Xarn posted:

c Java s: Java enums are sweet. Not being able to make ArrayList<int> less so. Having to reason about this mess
Java code:

ArrayList<ArrayList<ArrayList<Integer>>> butts = new ArrayList<>();
ArrayList<ArrayList<ArrayList<Poop>>> poops = new ArrayList<>();
ArrayList<ArrayList<Integer>> turds = new ArrayList<>();
sucks rear end. Especially since the same index is used to index each of them at different places. :suicide:

isnt type erasure fun???

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

fritz posted:

'doing a recursive implementation when there's a perfectly good imperative solution' is primo terrible programmer territory

the recursive solution is sometimes easier to reason about and if your language has a non-lovely compiler they will get optimized into the same thing anyway.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

LeftistMuslimObama posted:

the recursive solution is sometimes easier to reason about and if your language has a non-lovely compiler they will get optimized into the same thing anyway.

well, it will if it's tail-recursive. i don't know of many compilers that will transform a recursive algorithm into an iterative one with an explicit stack.

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
i optimized my tail calls by putting your moms number on speed dial

FamDav
Mar 29, 2008

uncurable mlady posted:

i optimized my tail calls by putting your moms number on speed dial

quoting a post from 2014

Xarn
Jun 26, 2015

LeftistMuslimObama posted:

the recursive solution is sometimes easier to reason about and if your language has a non-lovely compiler they will get optimized into the same thing anyway.

If its able to optimize general recursion into iteration, thats some mighty fine compiler you've got there.


I needed to generate all bitmasks of length N with exactly k bits set.

Mao Zedong Thot
Oct 16, 2008


uncurable mlady posted:

i optimized my tail calls by putting your moms number on speed dial

Xarn
Jun 26, 2015

Soricidus posted:

ouch. I generally take deeply nested collections like this and write a goddamn class that represents the actual thing you're working with instead of the data structure used to store it. it's not 1996 any more, adding another class isn't going to hurt performance.

Thats what I am doing, but first I gotta unravel this mess.

--- edit ---
There are also 5 more similar collections in that class and that is after I split the original monster class into 3 logical units that aren't overly interconnected. :v:

Xarn fucked around with this message at 09:12 on Dec 4, 2016

redleader
Aug 18, 2005

Engage according to operational parameters

Xarn posted:

Thats what I am doing, but first I gotta unravel this mess.

--- edit ---
There are also 5 more similar collections in that class and that is after I split the original monster class into 3 logical units that aren't overly interconnected. :v:

how long until you get pulled up for spending time refactoring instead of hacking new features x, y and z in?

redleader
Aug 18, 2005

Engage according to operational parameters
c++'s const correctness stuff seems pretty cool on the surface

Xarn
Jun 26, 2015

redleader posted:

c++'s const correctness stuff seems pretty cool on the surface

Yup. Its infectious though, which can make introducing it in existing codebase painful.

Its also a massive pain to provide all the right overloads without using const cast, if the logic is nontrivial:
C++ code:
struct butt {
    void shart() & { ... }
    void shart() && { ... }
    void shart() const & { ... }
    void shart() const && { ... } // this one is basically nonsensical, but :shrug:
};
And as a bonus, const means that the object is either read-only, or just internally synchronized (ie it uses mutex to synchronize with mutating accesses).

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

FamDav posted:

quoting a post from 2014

mods never made it thread title... a shameful mods

Xarn
Jun 26, 2015
c Java s: Erased generics can still go suck a dick.

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo 💋 ðŸ™Â
Taco Defender
whats the point of lvalue reference qualified member functions?

Xarn
Jun 26, 2015

Illusive gently caress Man posted:

whats the point of lvalue reference qualified member functions?

So you can specify different behaviour for lvalues vs rvalues. :shrug:

In reality there are some use cases, but so far this is quite obscure, so I don't have any examples of people using this in their libraries handy.

tef
May 30, 2004

-> some l-system crap ->

LeftistMuslimObama posted:

the recursive solution is sometimes easier to reason about and if your language has a non-lovely compiler they will get optimized into the same thing anyway.

lol

Bloody
Mar 3, 2013

worrying about recursion compilation at the whiteboard is premature optimization

Jerry Bindle
May 16, 2003
i have found that recursion in programming is great for programs about mathematics like induction with peano numbers and as an idiomatic way to process lists in scheme-like langs. one of the lambda papers notes that there is an isomorphism between peano numbers and s-exps, which explains why it feels natural to program that way in scheme. racket has better and more powerful ways to process lists that are named like they are imperitive things like for/list, for/set, the syntaxes aren't explicitly recursive but they might be macros over a recursive something. but thats my idiot spare time opinion, at work i use java and have only found one use-case for recursion: linearizing a list of javafx tree items entries. the tree represents a ui menu, so the assumption is that the walk won't take a significant portion of the heap.

brap
Aug 23, 2004

Grimey Drawer
tps: what am I misunderstanding about std::thread such that running my workload with 1024 threads is faster than running it with 2 threads on a dual core machine? it's just computing a mandelbrot set by dividing up rows of pixels to compute amongst threads.

Xarn
Jun 26, 2015

fleshweasel posted:

tps: what am I misunderstanding about std::thread such that running my workload with 1024 threads is faster than running it with 2 threads on a dual core machine? it's just computing a mandelbrot set by dividing up rows of pixels to compute amongst threads.

More info needed, there is nothing weird in std::thread and Mandelbrot set an IO bound task aint.

brap
Aug 23, 2004

Grimey Drawer
I'm representing the bitmap with a std::vector<std::vector<int>> which could be bad. I pass a pointer to the vector in with the thread start arguments for each thread as well as the index into the outer vector that the thread should start inserting into the inner vector. I ran it with Instruments on macOS which made it look like half of my time is being spent in cabs though (absolute value of a complex number).

I feel like there's probably something really stupid going on causing threads to block each other or something. Running it with 2 threads is actually slower than my single threaded implementation without std::thread.

posting code because why the gently caress not

code:
#include <iostream>
#include <complex>
#include <vector>
#include <chrono>
#include <thread>
#include <SDL/SDL.h>
#include "sdl_helpers.h"
#include "mandelbrot_common.h"

struct thread_params
{
	std::vector<std::vector<int>> *set;
	int min_x;
	int max_x;
	int width;
	int height;
};

void mandelbrot_thread(thread_params *p)
{
	for (int i = p->min_x; i < p->max_x; i++) {
		std::vector<int> column(p->height);
		for (int j = 0; j < p->height; j++) {
			double x_norm = (double)i / p->width;
			double y_norm = (double)j / p->height;
			int iters = mandelbrot(std::complex<double>(x_norm, y_norm));
			column[j] = iters;
		}
		(*p->set)[i] = column;
	}
}

std::vector<std::vector<int>> mandelbrot_set(int width, int height)
{
	constexpr int num_threads = 1024;
	std::cout << "Number of threads: " << num_threads << "\n";

	auto set = new std::vector<std::vector<int>>(width);
	std::vector<std::thread*> threads;

	int slice = width / num_threads;
	for (int i = 0; i < num_threads; i++) {
		struct thread_params *p = new struct thread_params;
		p->set = set;
		p->min_x = slice * i;
		p->max_x = slice * (i + 1);
		p->width = width;
		p->height = height;

		std::thread *t = new std::thread(mandelbrot_thread, p);
		threads.push_back(t);
	}
	for (std::thread *t : threads) {
		t->join();
		delete t;
	}

	return *set;
}

int main(int argc, char **argv)
{
	std::chrono::system_clock clock;

	auto before = clock.now();
	auto set = mandelbrot_set(MAX_X, MAX_Y);
	auto after = clock.now();
	std::chrono::duration<double> diff = after - before;
	render_mandelbrot(set, diff.count());

	return 0;
}

Adbot
ADBOT LOVES YOU

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
cases in which you need recursion:

  • traversal
  • mathy poo poo
  • ????

  • Locked thread