/dpt/ - Daily Programming Thread

Old thread: What are you working on Sup Forums?

Other urls found in this thread:

en.cppreference.com/w/cpp/thread
support.google.com/dfp_sb/answer/2694377?visit_id=1-636282822426307867-1365469445&rd=1
cellperformance.beyond3d.com/articles/2009/08/roundup-recent-sketches-on-concurrency-data-design-and-performance.html
www3.cs.stonybrook.edu/~rezaul/papers/TR-07-54.pdf
youtu.be/ta3S8CRN2TM
twitter.com/AnonBabble

>OOP

nth for re-implementing haskell in pascal

QUICK! WRITE A PROGRAM THAT RUNS TWO THREADS. ONE OF WHICH HAS TO BE RUNNING ON CPU0 AND THE OTHER ON CPU2.

>hey guys do my homework for me

It's the OS's job to schedule threads/processes, not mine.

>he doesn't know

>tfw no gf

I had a girlfriend for a bit and ended up spending all my time being a normie instead of coding.
Genuinely glad I'm single again now. C++ is my one true love.

Currently getting back into the groove of using C after years of nothing but GNU Octave, Python and *shudder* G. Also improving my bash scripting chops.

Following tutorials I find myself making lots of small programs. Since I get tired of typing the same includes, comments and main function skeleton over and over again I made some bash scripts to automate the process:

newc(){
if [[ -z "$1" ]]; then outfile="/tmp/newc.$(date -Iseconds).c"; else outfile="$1"; fi
echo '/* #includes */
#include
#include

/* #defines */

/* globals */

/* function declarations */

int main() {
/* local variable declarations */

for (;;) {
/* input */

/* eval */

/* output */
}

return 0;
}

/* function definitions */' > "$outfile"
nano "$outfile"
#if [[ -z "$1" ]]; then rm "$outfile"; fi
}

newpy(){
if [[ -z "$1" ]]; then outfile="/tmp/newpy.$(date -Iseconds).py"; else outfile="$1"; fi
echo '## imports ##

## globals ##

## function defs ##

def main():
## locals ##

while True:
## input ##

## eval ##
pass

## output ##

return
}

if __name__ == "__main__":
main()' > "$outfile"
nano "$outfile"
#if [[ -z "$1" ]]; then rm "$outfile"; fi
}

Call $ newc or $ newpy without additional args to create a file in /tmp, or with a filename as the arg to create that file.

Mine starts counting at 1.

procedure Power is
task Foo with CPU=>1;
task body Foo is
begin
loop
Put_Line("He doesn't");
end loop;
end Foo;

task Bar with CPU=>3;
task body Bar is
begin
loop
Put_Line("know. HEHE!");
end loop;
end Bar;

begin
null;

end Power;

I program in actionscript, which dosent support threading.
Here, have a printf clne instead.
function tracef(str:String, ... args):void
{
var newStr:String = ""; var usedArgs:Array = new Array;
if(str.indexOf("%") == -1)
newStr = str;
else {
var indices:int = args.length; var index:int = 0; var arr:Array = str.split(" ");
for(var i:int = 0; i < arr.length; i++) {
var t:int = 0;
if(index < indices) {
switch(arr[i].toLowerCase()) {
case "%i":
for(t; t < args.length; t++) {
if((args[t] is int || args[t] is uint) && (usedArgs.indexOf(args[t]) == -1)) {
arr[i] = args[t]; usedArgs.push(args[t]);
break;
}
} break;
case "%s":
for(t; t < args.length; t++) {
if(args[t] is String && usedArgs.indexOf(args[t]) == -1) {
arr[i] = args[t]; usedArgs.push(args[t]);
break;
}
} break;
case "%n":
for(t; t < args.length; t++) {
if(args[t] is Number && usedArgs.indexOf(args[t]) == -1) {
arr[i] = args[t]; usedArgs.push(args[t]);
break;
}
} break;
case "%o":
for(t; t < args.length; t++) {
if((args[t] is Object) && usedArgs.indexOf(args[t]) == -1) {
arr[i] = args[t]; usedArgs.push(args[t]);
break;
}
} break;
default: break;
}
}
}
for(var p:int = 0; p < arr.length; p++) newStr += (arr[p]+" ");
}
trace(newStr);
return;
}

why the fuck would you explicitly state a target CPU? That limits the reach of your code.
Most decent languages have facilities that can turns loops into vector operations and functors into routines. Just use that and let the OS deal with "which" CPU / thread gets used.

the scheduler can't read the programmer's mind. there are legitimate use cases for setting cpu affinity.

Two off the top of my head.
>Guaranteed non-competing threads
>All your CPUs aren't the same type

both of these cases rely on pre-existing knowledge of the target hardware. That's not your everyday programming.

>he only does everyday programming

yes.

i work in unity on a vr world i can life in.

Name one thing you don't like (hate) in your favorite language.

>he enjoys running non-portable code that will eventually become just as obsolete as the platform he targets

>Guaranteed non-competing threads
>not portable

standard library sucks
syntax is wonky at times
metaprogramming is both the best and worst thing to happen to it
still love her tho

It being Turing-complete.

C++?

To add - incredibly useless reinterpret_cast. Essentially only good for type-erasure, which can't be resolved at compile time (expensive run-time enforcement on every day code).

Lua
Lack of continue statement

C++
Lack of options and variants (will be added in C++17 though)

no "private" variables in namespaces. why the fuck do i need to make a class just to scope certain "global" variables?

...

>class

What do I read after this /dpt/?

I feel like it teaches me much of the basics but I have no idea how to create a structured package or how to do includes properly. It may be a bit dated too but I'm not sure.

I'd like to build something like rrdtool or taskwarrior as my first project, any good sources on writing a full program?

How can I pull an RSS feed (craigslist) to play around with regex on the results? Preferably using Javascript (because I need to practice JS)

I feel so stupid I can't figure this out

Nigga there are tons of libraries that do exactly that for you. Your Google-Fu is weak.

All of them are depreciated (google's, jfeed, etc), Jquery has built in XML support and I know DOM quite well for that part, I just don't understand how to ~read in~ (import, then display) the RSS from craigslist. The last error when I tried was a cross-domain error, is this something I'd just need a header option for?

Just run JS via Node as a "server-side" language rather than in the browser then use request & xml2js libraries from the npm repository you fag.

Fuck Javascript. Get it done easy and quick with Python you turbonerd.

It's actually useful for very large projects because if you do your job well you can utilise hyperthreading more effectively.

But desu I don't think anyone in this thread will write that code for production purposes in their lives.

>C++
Almost all features they've added since C99.

What's a good book on multithreading in C++?
I need examples more than anything.

en.cppreference.com/w/cpp/thread

man threads.h

Hey Sup Forums,

I'm almost done programming this SPA website with angular 2 (4 actually), it was a decent amount of work and i was hoping i could serve ads on it before i realized yesterday, SHIT ITS A SPA. also those threads today about ads aren't reassuring either.

anybody have similar experiences? do you know good affiliate networks? i was thinking i'll make an ad component that refreshes itself for CPM and some affiliate ads.

support.google.com/dfp_sb/answer/2694377?visit_id=1-636282822426307867-1365469445&rd=1

you need to allow cross origin res sharing on your server?

So what's the point of this fancy future/promise meme you have in various programming languages?
Most example use cases I see launch an "async" task only to block a few lines later to get the future, doesn't that like miss the entire point?

isn't RSS as a whole deprecated? i never got the RSS meme

most people are complete fucking retards about multithreading. mutexes, conds and atomics can go a long way if you're not retarded

I read that yesterday,
i don't really get what DFP is, an ad network that's adsense and affiliates merged?

async isn't multithreading m8

Anthony Williams' book.

class table{
var myPizza = this.pizzaService.getPizza();
(You).eat(myPizza);

//sometimes pizza is undefined because table is loaded before pizzaService,
//so you use promises or observables in order to eat an observable of myPizza
//that will only be served to you when it's actually arrived
}

class pizzaService{
var pizza;
ctor(private pizzaHut){
this.pizza = pizzaHut.orderPizza();
setPizza(this.pizza);
}

getPizza(){
this.pizza = pizza;
}
setPizza(pizza){
this.pizza = pizza;
}

}

how i indent Sup Forums

Baaad.
The standard makes the simple non-sharing case of multithreading unnecessarily complicated and makes the difficult situations inefficient or hard to deal with.
Of course you can ignore it almost completely and just use their variety of locks but you're not really helped by the library then.

Regardless this isn't what user is looking for. user is looking for materials that explain systems. He'd like something like a basic SPMC work queue example. A job system example that handles graph-like dependancies. And something like this
cellperformance.beyond3d.com/articles/2009/08/roundup-recent-sketches-on-concurrency-data-design-and-performance.html

C
Scheme
Javascript

Is there any paradigm that I am missing between these three languages?
Not really. As far as I know, it doesn't make sense to use anything else.

what is it then

//I've enclosed this text with [code*] and[/code*] (remove asterisks)

Why wouldn't I use a CV then to signal when a pizza is ready?

Who would you like to find out browses Sup Forums?

Dennis Richie

getPizza(){
return this.pizza
}
setPizza(pizza){
this.pizza = pizza;
}

}

thanks

Among the giants I presume.
Bjarne Strostrop.
He's the only one I have too little respect for to not care if he browsed Sup Forums.

Also a follow up, for instance, at least in C++, people state that it just launches a new thread, wouldn't that be extremely inefficient because effectively you would be spawning and destroying OS threads all the time and having much more threads than you can run therefore running into performance issues due to context switches? In which case what's the point of async at all if you can just do away with a proper thread pool?

fpbp

The committee thinks async in C++ was a mistake.

it's "good enough" for lazy C#-tier code monkeys

You're correct. It's one of those features the committee adds to be more friendly with the C++ crowd that has fairly casual performance requirements where their need to write code well exceeds their need to put effort in performance. That could be said for C++ at large due to the reliance on compilers to fix your code for you but it's not that strong a point since they're mostly very good at it.
>mistake
They do a lot of those. It'd be interesting to graph their mistakes to features ratio over time.
Maybe eventually features are expected to be mistakes and you can comfortably stay with an old version of the language.

They _mostly_ learn from mistakes, though, and deprecate the stuff that didn't work as intended.

i don't know what a CV is.

maybe you mean a callback? you could just do that if you prefer, promises are a one time thing i guess it's no different than syntactic sugar for people who have a hard time wrapping their head around callbacks (and also easier to debug considering it's sleeker to write),

but the observables, are like event listeners, in case of a callback im not sure you could just have it reload 20 times a cycle, observables could just listen to click events all day on your server.

as far as threading and performance implications go i'm not a c++ guy so i dont really know but for instance in c# async is slapped onto lots of things and memory wise i wouldnt even be worried about running multiple potential extraneous threads when whatever you're running has to be packing .NET...

Trying to understand this pseudo-code:

>for each (u, v) ∈ E[G] do
It's a line in a graph algorithm.
E[G] is a set of edges. u is a vertex.

Does it mean:
>for each vertex v connected by an edge to the vertex u do the loop below

>i don't know what a CV is.

user meant a condition variable.

Does C do conventional OO?
JS doesn't. I assume Scheme is purely functional.

People shouldn't use the quote feature without intending to quote someone, it's considered poor form!!!

that is some math-y looking pseudo code

why people don't write this shit in literal plain english is weird to me

It sure doesn't feel like they're making less mistakes.
>conventional OOP
Well specified. No C doesn't really do that.

Scheme is neither functional, nor functional.

>As far as I know, it doesn't make sense to use anything else.
Only if you're allergic to non-shit type systems.

It's difficult to get without context.

oh,

well in my example you could just add if (myPizza) and the code would run thinking your pizza is nonexistent and just skip the block,

if you want you could add if (!myPizza) { setTimeout(alert("go grab a coffee while i halt for your pizza"), 20000); } and that's really hardcore programming in my opinion. the point of promises is to keep a listener up for your pizza while your server can go about the rest of its business

fuck me im in a rough spot at work
codebase is trash
there are no tests, tons of coupling everywhere, hardcoded shit (ran into a hardcoded id from production database for special behavior, i mean what the fuck?)
refactoring would be hard and time consuming as fuck since theres no way to know you've broken something without manually testing everything
asking boss to rewrite some module from scratch would mean having to tell my collegue with 30 years of programming experience his code is ass

honestly just thinking of changing jobs

yes

>for each edge (u, v) in E[G] do

>why people don't write this shit in literal plain english is weird to me
Because it would get extremely verbose and hard to understand.

>∈
>in
literally one more character

do it

ass colleague will never listen,
boss can't take your word over his
you rearned your resson

In this example, but aren't you talking about why people generally don't do that?
Also ∈ has more connotations than just "in".

www3.cs.stonybrook.edu/~rezaul/papers/TR-07-54.pdf

page 17, figure B.2

Some people feel more at home with the math side of things. English is more ambiguous. In computer science programs I'm sure the math language isn't a problem.

>To whom are you referring?

>Also ∈ has more connotations than just "in".
like what

and how am i supposed to know

>implying
hello newfriend

It's basically infix for ∈ (x, y), which you can think of as a function which returns a bool. Both x and y are required to be sets.
>and how am i supposed to know
You have the internet. and obviously reading some text without having the prerequisite knowledge isn't something you should be doing in the first place.

Dunno if it helps but it helps to have other people support you when arguing.
youtu.be/ta3S8CRN2TM

Also its not necessarily the case that your college is happy with the situation he may just be content. It's not rare for long lasting projects to get messy.

#include

using namespace std;

int main()
{
for(int i=0; i

Congratulations, you're hired.

>for each (u, v) ∈ E[G] do
>not ∀(u, v) ∈ E[G]

>i=0
>i%3==0 && i%5==0
wew

It's perfectly fine. Just so you know before people complain.

Thank you

that guy constantly walking back and forth triggers me more than it should

>>i%3==0 && i%5==0
literally nothing wrong with it. the compiler will cache the result so it's actually better than doing i % 15 == 0. and i % (a * b) == 0 doesn't work correctly if a and b are composite numbers

When making sql query are hardcoded ids fine?
I ques you could also make enum for them and pass them in the prepared statement?
How should it be done?

>being triggered by walking and not his gender-specific language

can you even into social justice???

Implying you need either