/dpt/ - Daily Programming Thread

Previous thread: What are you working on, Sup Forums?

Other urls found in this thread:

css-tricks.com/snippets/css/
hero.handmade.network/episode/code/day122
twitter.com/SFWRedditGifs

node js is fun

I'm trying to configure an IR reader with my Raspberry PI. What's the best way to control GPIO pins and get analog input in Linux? I'd like to stick with file descriptors and /sys, but I'm open to APIs (in C++)

...

Are you trying to cheat in Keep talking and Nobody Explodes?

Working on my Trumps with some image manip algos.

Include your neat side projects, programming competition/hackathon participation, etc

I've been stuck trying for past 3 hours trying to figure out how to move audio files in my raw folder over to the public music folder on android. It's made worse by the fact that there aren't any built in warnings or errors anymore whenever it fails to write.

No, it was a challenge someone linked

Soup Sup Forums
I'm planning on applying for a lot of internships for this summer and I want to make a website featuring my projects (just links to github repo, what they do, maybe screenshots or something), and have it look neat
I've done very little webshit, how do I learn quick to make a nice website?

css-tricks.com/snippets/css/

Why do people refuse to learn and use JavaScript when it is the most widely used programming language?

>most widely used programming language
I'm pretty sure C beats JavaScript by device count and LoC

>making a website to link to github repos

Why don't you just link to your github?

Realistically, if you want to take this path, you're probably not going to make anything in the next couple of months that would rival the look of what you could make using Wordpress and tweaking a theme.

C beats everything by LoC

That's not a good thing

I do, and that's fine too honestly, I just think it would be neater if I made the site and it looked nice.

>C being the most popular language is a bad thing
I'm counting C++ as well (since they are pretty similar), except C++'s standard library can't be ported to embedded hardware

Linear types.

>this weak bait again
javascript is bad and you should feel bad

not exclusively, and it's not fair to count C++

>not fair to count C++
Okay, i'm not. Assuming the programmers aren't morons and they have the decency to create bounds checking (literally no reason not to), then what is wrong with using C?

Because Java is the best and most widely used programming language. You just don't see it on the github stats because it's used to make proprietary, enterprise grade software instead of kiddie web shit.

C and C++ are very different

what's wrong with C is a lack of a lot of things

...

>C and C++ are very different
The only thing I can think of that makes it vastly different is streams, but everything else (including everything you would use a stream for) can be easily emulated in C.

>streams
a single fucking library feature is the only difference you see between the two?

Everything else can be emulated or done away with. Streams can't because they are operators

holy shit you're retarded

You are dumb

Prove me wrong

Streams aren't operators, functions using streams have been defined as overloaded operators. Other C++ library features have overloaded operators as well.
You should kill yourself.

I've learned today that someone is at least dumber than me in this world of programming.

>templates
>constexpr
>enum class
>operator overloading
>constructors, destructors
>move semantics, references
>namespaces
>lambdas
>structured binding
>variadic templates
>auto

>(soon) modules, concepts, coroutines, ranges

>probably a dumb question
I'm getting to grips with functional programming.

To my understanding for a procedure or function you want to use one input at most and curry the rest of it.

Does this include constructors for instancing calls for a class/thread etc?

I'd guess you could just set the variables you need using an internal function but it just seems like that circumvents the whole point of a constructor.

Is something like this okay,

Server ticktockserver = new Server(theip, port);

versus

Server ticktockserver = new Server(theip);

Do I need to worry about the constructor's elegance? If it's just setting variables or passing references it should be O(1) right?

How much performance do you care about?
If you're not using a functional language, then returning an erased function that returns an erased function that returns the result might be a lot slower

and if your language has lambdas, and you really need a curried function, you can do it yourself, e.g

server40 = ip => new Server(ip, 40)

Well you can't directly curry a constructor. You'd have to make a curried function that itself calls the constructor.

Either node-webkit is static as fuck or I'm shit at javascript. For some reason I can't modify textareas. I'm not getting an error or anything, it's just not modifying. It's receiving the data from the server but not applying it to the element.
document.getElementById("latestdata").value += "Submission uploaded correctly\n";
That's what I'm using to try to modify it. I also tried modifying innerHTML instead of value but that didn't work either.

Averaging Algoirthm Times
I used the high resolution clock Ada provides to keep it nice and fair and compiled with -O2

> 36.861433864 sec.
long c_temp = (long)a + (long)b;
return ((c_temp / 2) +
(c_temp & 1) -
(((c_temp & SIGN_MASK) >> 62) * (c_temp & 1)));


> 62.055073110 sec.
int z = x%2 + y%2;
return x/2 + y/2 + (z + (z > 0) - (z < 0))/2;


> 39.539793202 sec.
*this didn't actually solve the problem statement, but it's here for comparison
return (int)(((double)a)/2.0 + ((double)b)/2.0);

Test this

Trying to curry everything doesn't sound like good style to me.

Does a PC really take 39 seconds to average 2 doubles or is there something I'm missing here?

>templates
define different types
>constexpr
not needed
>enum class
macros and an integer
>operator overloading
define a function that operates on the data
>constructors and destructors
define a function that sets default values, and one for destructing it
>move semantics, references
You don't need references, pointers work
>namespaces
Just precede the function with the name of the namespace
>lambdas
define it as a seperate function, and reference it with pointers
>structured binding
That's not in the standard yet
>variadic templates
just create different types, like above
>auto
typedef

In a functional language it is, everything is already curried

>
not good enough
>
not good enough
>
not good enough
>
not good enough
>
not good enough
>
not good enough
>
not good enough
>
not good enough
>
it is in the standard
>
not good enough
>
not good enough, not remotely the same

seriously have you ever even used any of those before?

Of course he hasn't, because he thinks >> and

And yet operator overloading is somehow a big distinguishing feature?

I ran it on like 4 billion numbers

>MULT_POLY(ADD_POLY(poly1, poly2), poly3)
>(poly1 + poly2) * poly3

That's probably a million or a billion tries. It doesn't make sense to time it once, because timers aren't precise enough and schedulers can make individual times report crazy numbers
I used templates, enums, operator overloading, constructors and destructors, namespaces and lambdas out of that list. I'm not saying the C version is as pretty or as OOP-like, but it works
That's because there is no direct analog in C
But they are stream operators...
>Streams aren't operators, functions using streams have been defined as overloaded operators
>overloaded operators
>operators

I'll remind everyone that Linus (creator of Linux) still makes a point of using C over C++.
So keep learning C++ please.

Also, apparently I can't read because you yourself said "define a function that operates on the data" for operator overloading. Contradictory much?

>template
>T identity(T value) { return value; }

>int identity_int(int value) { return value; }
>float identity_float(float value) { return value; }
>bool identity_bool(bool value) { return value; }
>void *identity_float(void *value) { return value; }

>The US is a square with stripes and stars
>>The US isn't a square with stripes and stars, its flag is a square that has stripes and stars
>

I don't care about OOP, none of those are OOP features (streams are, but fuck streams anyway).
Streams are just a set of library classes that happen to overload operators.

None of those features are in C.
Almost all of those features are extremely important.

>poor man's Metaprogramming to save himself some time writing this shit out while wasting probably more time total waiting for compiles
If your build times aren't sub 2 seconds you're too slow for productive programming.

fucking_type fucking_add(fucking_type A, fucking type B){
fucking_type retval;
clear_fucking_type(retval);
retval.fucking.variable = A.fucking.variable + B.fucking.variable;
return retval;
}

> +
not portable

What's the point of move semantics? I don't get it. Seems like an entirely superfluous feature to solve non-issues.

Avoids unnecessary copying and can help skip destructors, which is extremely useful for non-copyable types.

E.g. RAII

Moving is a transfer of ownership. Copying with ownership means you have to do a deep copy (or increment a reference in a shared_ptr, or something like that).

c doesn't lack anything.
c has every feature you need and c is simple.
c++ has more (((features))) than c but it makes it a terrible language because the educational material tempts you to use all of them, which creates a big mess of software.
software shouldn't be a mess, it should be simple and beautiful.
only a fool would write software which has multiple layers of inheritance, quirky operator overloading and so on, which creates a big mess of software.

anyone here know multithreading?

how would i go about sectioning off parts of an array for each thread in a parallel.For() loop?

like if i want thread1 to process index 0-25, thread2 process 26-50, ect...

I'm just curious what the functional approach/take is on constructors.

They come across as the functional equivalent of a map eg

public Server(InetAddres ip, int p, String someConfig, boolean dedicated)
{ localConfig = someConfig; inet = ip; port = p;}

Where as I could do something like this I think,
class Server {
public Server(){ init(this, someConfig) }
void init(Object server, Config b) { server.a = b; }


init I guess uses 2 inputs, but it seems the more elegant option I'd guess? I really don't know. This is all pretty new to me.

>c has every feature you need
>(((features)))
>quirky operator overloading

The functional take on a constructor is it's a function that you call that creates an instance of a class.

In Haskell, all functions are curried, including constructors. But this also means Haskell is going to optimise this sort of thing a lot more.

Constructors are no different to other functions.
If you've got lambdas you probably don't need to worry about currying most things, unless you're explicitly wanting to return a function.

Linear algebra library.
No operator overloading.
>beautiful

Well, when you add algebraic data types in the mix then you have that a fully applied constructor is a canonical element of the type.

In Haskell everything is constructors.

What return types for constructors you allow lead to really interesting properties

>languages with equality types
>letting you return an equality
quotient types, lets you say two constructors are identical

>polymorphic type
>let you restrict the type variable for certain constructors
GADTs

>allowing you to return something other than the type it constructs, or hiding constructors
lots of useful stuff like smart constructors

>parallel.For() loop?
I'm not gonna go into it but build a work queue system. Give each worker the thread 'work' which is a structure with a function pointer and a pointer to arguments for said function (that's the bare minimum anyway). The function will know how to extract the arguments from the pointer. So for instance you could have a function pointer to a multi-threaded specific version of your current implementation which takes the arguments start_index, end_index and array_pointer. Fairly certain you can figure the function out from there.

He queue part is the tough bit. But if you're just writing something small you don't need it. Manually assign your threads the work and kick them off from the main thread.
It's among the easiest ways of doing it.

If you really need a more flexible system Google multi-threaded work queue.
hero.handmade.network/episode/code/day122
Here's a very pleasant introduction to multi-threading. Subsequent episodes goes through a basic work-queue implementation.
Its all done in a very C-like subset of c++ so it's easy to follow for anyone familiar with C.

It should give you a fairly good understanding of what the pitfalls and ideas behind multi-threading. It's not that difficult if you do it right.
It's game specific but easily generalises to all kinds of systems.

Good luck. The forums accept questions on old topics.

>People unironically use
>for(;;){}

>c has every feature you need

The same could be said of assembly.

Ahh okay so the elegant approach would probably just be,

Server reindeer = new Server();

Ideally all server configuration would be declared inside the class, ie

class Server{
InetAddress ip = new InetAddress.getWhatever();
final int port = 80;
ServerConfig config = new ServerConfig();
// etc

#include

/* declare variable of type int */
int var;

/* declare a pointer to type int */
int *ptr;

int main()
{
/* initialize var */
var = 1;

/* initialize ptr to point to var */
ptr = &var;

/* display address of var */

return 0;
}


What is the correct way to print the address of "var"?
printf("address of var [ptr ] : %p\n", (void *)ptr);


or

printf("address of var [ptr ] : %p\n", ptr);


On linux (gcc) they both work.

Path constructors are a little different because you're not adding new elements to the type itself but rather adding new elements to its equality type. You're actually potentially making the type smaller when you give it path constructors.

>Path constructors are a little different
GADTs are a little different too, as are smart constructors

the casts don't do anything, arguments after the format string have no type and get interpreted by the format specifier. leave them in if you want to be explicit.

>What is the correct way to print the address of "var"?
printf("address of var [ptr ] : %p\n", &var);

>that type belongs to certain typeclasses
nothing to do with constructors

>those comments

You're missing one for the return value, and one for an explanation of what "main" is. Apply yourself.

yep, it's just a small c# assignment for a class. I was hoping to avoid doing things manually to this extent, but I suppose it can't be helped.

This video is looking interesting though, so thanks for that senpai.

Maybe try reading a book, nigger? Rather than spouting off opinions based upon your arbitrary baby duck experiences as a code monkey?

It is prefix notation that makes Lisp homoiconic and naturally suitable for metaprogramming and higher-order function application. The (car) is always the procedure and the (cdr) is always the parameters. From this foundation basically springs forth everything else. The original plan was to eventually implement M-expressions in Lisp, but nobody actually ended up wanting them.

It's fine to be ignorant and willing to learn, but the way C-niggers and ML-niggers just assume whatever they grew up with is automatically the "natural" way to organize information is shameful.

also missing one typing out the full name of the library reference.

>niggerniggernigger
opinion discarded

I'd imagine more c# specific resources exist that tell you more. They probably have some abstraction that's for just this.

If you just want to get done look for that first. But I highly recommend the videos because they're less environment specific and the Q&A's are often enlightening as many of his friends watch for fun and or it answers newbie questions directly.
>nigger
Woah man chill out.

Okay cool so I can just call the function without having to worry. Thank you, appreciate it!

>thought it was some random gymnast
>it's just the American singer-whore
Disappointing.

Also claiming Scala is the way *anything* should be done is the most laughable thing I've read in a long time.

Whoever decided Haskell, Ocaml and Java were a good mix should be kept away from computers

Ah geez guys, let me learn/take notes in my own way. The second I type that stuff out and move on to the next lesson I forget it. Verbose comments help me remember.

I thought this was a bully free zone!!!

because kernel dev is so relevant to most people

>>>/reddit/

why isn't haskell good?

Is this more to your liking user?

You must be new here.

Yeah but not much better.

>you must be new here
thats what newfags actually use
but lets not derail the thread with our shitposts

>t-that's what newfags actually use
>derail
>shitpost
>nigger
> >>>/reddit/
You need to learn to fit in.
Calm your autism, and learn to reply like a real human being.

Anybody use Unity?

Im trying to make a game now 2D just watching tutorials now