/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1548414484386.jpg (1024x1530, 867K)

Other urls found in this thread:

docs.microsoft.com/en-us/dotnet/fsharp/language-reference/active-patterns
bell-labs.com/usr/dmr/www/chist.html
youtu.be/-J8YyfrSwTk
blog.robertelder.org/building-broken-c-parsers/):
gcc.godbolt.org/z/XZYX9w
repl.it/repls/NimbleMaroonFolder
ghostbin.com/paste/frk5d
en.wikipedia.org/wiki/K-d_tree
en.wikipedia.org/wiki/Quadtree
en.wikipedia.org/wiki/Binary_space_partitioning
twitter.com/NSFWRedditImage

I love you all, anons

Attached: 1486600557343.jpg (852x973, 475K)

>tfw people ignore your post
Please give me the (You)s:

Been programming in C for a while now.
Is C++ worth any looking at?

first for
C U T E
U
T
E
robots

Attached: cuteaf.jpg (3000x1998, 458K)

I read your post, I just didn't really have anything to say about it. Here's a (You)

Attached: 1547399947119.gif (648x720, 484K)

>book is only available on google play
>not available in my country
who the fuck does this

Attached: 1491497250534.jpg (1000x1166, 983K)

If you get good at C++, you will never want to program in C again.

How good is /dpt/ at math? I remember having difficulties even remembering derivative and integration rules.

Do I see it correct that you first save all numbers and filter then out the even ones? Why?
I dont know this language

Is that F#?

dependent types

Attached: coq_de_paulus_1913.png (800x894, 1.09M)

do you love to program in coq?

Attached: 1553682269137.jpg (720x720, 99K)

;)

Attached: ;).jpg (803x688, 141K)

looks like ocaml, looks fine except you may want to watch 'effective ML' on youtube to use pattern matching as ur frend and avoid wildcard _ when possible

>literally me but with .net

Attached: 1519960122281.jpg (640x1129, 226K)

how smart and more importantly how autistic are you
if the answer to both is very you will enjoy sepples

dumb frogposter

what the fuck
how can anyone defend a language that evolved like this

Did you read your Software Foundations tody?

Yessir.

Yes, it first gets all the fibonacci numbers, then filters out all the odd ones.
There's no good reason for it, it's less efficient than leaving them out altogether, but i'm far from "fluent" in the language yet so I prefer solving problems bit by bit.
I also think smaller, single-responsibility functions are more idiomatic F# because they are easier to compose, although it doesn't matter for such a small program.

I will accept your offering of one cute anime girl!

Every other language (except for Pascal) was the same. I don't know much, but I heard early Lisps also had a lot of shitty design choices.
Wirth was (or still is) the only guy who knew what the fuck he was doing with language design.

No, Agda is easier and more fun.
I also made my own but it sucks.

Yes

Attached: ProofGeneral-splash.png (310x350, 65K)

Yeah I wasn't sure how to avoid the wildcard.
Maybe an active pattern could work somehow...
docs.microsoft.com/en-us/dotnet/fsharp/language-reference/active-patterns

Where can I go find out more about old C?

What should I read to learn about shit like data structures, virtual machines, etc? I know jack shit about abstract CS stuff beyond how linked lists work.

Types could have prevented this
>f : CorrectSpellingEnglish "tody"
>compiler error

Cunny++

Attached: 1554971273763.png (1024x768, 525K)

I have a big EXE file. In it, there's a function that I want to study how it works with a fuzzer.
I'm using Linux. What's the easiest way to do this?

nothing wrong with this
This seems reasonable considering their resource constraints. Not like they added in stuff that would turn out to be a pain later on.
C99 is the closest we will ever get to a perfect language.

bell-labs.com/usr/dmr/www/chist.html
past ebin / UAQaWuWG

I love c++ now

C is far FAR from the perfect language.

This is 'effective ML' youtu.be/-J8YyfrSwTk
I use it for most OCaml/ReasonML things, like the part on making illegal states unrepresentable is a good idea. Likely applies to whatever other func lang
They have a good style guide too like appending in to let one-liners

interesting argument

Attached: 1539800883999.png (943x171, 8K)

Flawless. Why isn't it perfect?
I can come up with some features it lacks, but if you try and fix those, you get worse problems. It would take many years of studies to make something better.

>flawless
lmao
C cult is fucking delusional

C was a language perfect for the compiler writers of some garbage-tier computer in early 70s, not for the end user. Note "was", because shit like this is a vaid C, according to the standard now (blog.robertelder.org/building-broken-c-parsers/):
void fun(struct foo {int i;} a){
fun(a);
}

int main(void){ return 0; }

I spent the afternoon hacking together this thing which plays audioclips whenever you plug and unplug an USB device. Currently gathering a library of hentai moans for it

declaring struct types in parameters? what's wrong with that?

What flaws does it have then?
Pre-ANSI C, maybe. C99 or C11 is perfect for programmers today.
>fun(struct foo{int i;}a)
I don't see the issue. Function pointers are confusing, but it's one of those "fix A break B" type of things.

nice trips

Attached: 1555051452281.jpg (713x670, 224K)

how can i program these fuckers? Pic related.

Attached: 140322-megaman002.png (512x448, 2K)

Sine waves.

based

>Function pointers are confusing
false
>but it's one of those "fix A break B" type of things
false

Something like unique_ptr should be added to C desu

>Thompson went a step further by inventing the ++ and -- operators, which increment or decrement; their prefix or postfix position determines whether the alteration occurs before or after noting the value of the operand. They were not in the earliest versions of B, but appeared along the way. People often guess that they were created to use the auto-increment and auto-decrement address modes provided by the DEC PDP-11 on which C and Unix first became popular. This is historically impossible, since there was no PDP-11 when B was developed. The PDP-7, however, did have a few `auto-increment' memory cells, with the property that an indirect memory reference through them incremented the cell. This feature probably suggested such operators to Thompson; the generalization to make them both prefix and postfix was his own. Indeed, the auto-increment cells were not used directly in implementation of the operators, and a stronger motivation for the innovation was probably his observation that the translation of ++x was smaller than that of x=x+1.

C haters BTFO

C, proper abstractions should be added to C, which makes std::unique_ptr just a simple library feature.

>"""smart""" pointers

Attached: 1534328667960.jpg (680x680, 76K)

sine waves are not enough i think.

>Beguiled by the example of PL/I, early C did not tie structure pointers firmly to the structures they pointed to, and permitted programmers to write pointer->member almost without regard to the type of pointer; such an expression was taken uncritically as a reference to a region of memory designated by the pointer, while the member name specified only an offset and a type.

struct foo {
int foo_x, foo_y;
};

main(argc, argv)
char **argv;
{
5->foo_x = 1; /* Valid early C code */
return EXIT_FAILURE;
}

D-Did you know that JavaScript rocks?

Attached: 1465186594954.jpg (693x1039, 116K)

Is the destructor-feature implied by raii not a "proper abstraction"?

It is, but you implied adding smart pointers as a language feature instead of just adding the necessary abstractions to make it a library feature.

Nothing wrong with this.
Yeah, but it would make stuff complicated as hell. You'd have to find every possible way the pointer can go out of scope, you'd essentially be trying to re-implement Valgrind.
No, I want C, not C#.

Exposing those abstractions instead of build it into the language is how you get eleven string types that you can't add together.

a = [0,1,2,3]

for a[-1] in a:
print (a[-1])

#0
#1
#2
#2

No, I did not.
Thank you for letting me know, user :3

Attached: D2OytmhU4AAI0BD.jpg (1200x681, 110K)

>You'd have to find every possible way the pointer can go out of scope
No. You just insert destructor calls at the end of scope, any other exit points out of the scope jumps to that same code.

There are several things wrong with this
It's the entire reason C has the -> operator instead of letting you use . on a pointer to a struct and automatically dereferencing the pointer

Any good language should have at minimum 2 string types: owned and unowned.
The other string types are just wide char versions and the legacy char pointer that no would should ever, EVER, use under any circumstance ever for strings.

still trying to learn cmake

Attached: 1480825347726.jpg (720x663, 44K)

Yeah, so now we get a new layer of indirection we didn't request. Thanks.
But . means something else. If I have a struct (not a pointer) then struct.member gives me that member. It's like asking why "asd" + "asd" != "asdasd".

>new layer of indirection
That's the point and it has no more overhead than manually destructing your resources.

Yeah and he's saying that p.x where p is a pointer-to-struct should be syntax sugar for (*p).x
The C compiler already internally overloads operators for different types so this is no challenge.

codeblocks

Attached: 1448453529488.jpg (884x903, 101K)

It does, though. Manual destruction is one mov and one call to free(). Magic "going out of scope" jump is another layer.

No. If anything, make it a finally() block like in some languages. But really, you can implement this yourself in C.
int myfun(size_t n)
{
# define MY_RETURN(k) do{free(ptr); return (k)}while(0)
char* ptr = malloc(n);
if (ptr & 1)
{
MY_RETURN(1);
}
else
{
MY_RETURN(2);
}
}

I just think it's disgusting and adds complexity. What if you don't want to destruct it?
Okay, so what if you want the address of element x in struct* p? &(x.p)? Looks disgusting.
Overloading would just be confusing, we tried this with char* already and that's one of the most confusing and controversial parts of the language.

>Manual destruction is one mov and one call to free()
And so is auto destruction.
You do realize the ONLY difference is the compiler put the call there instead of you, right? You do realize that right?

No. The compiler puts in a jump that isn't there if I do it manually.

>What if you don't want to destruct it?
Move it or don't use a smart pointer.

>Okay, so what if you want the address of element x in struct* p? &(x.p)? Looks disgusting.
Why would the operator precedence change? Syntactic sugar is an AST-level transformation, not a lexical transformation. C already does this exact thing for function pointers and you can see for yourself that it works just fine.

If the compiler is smart enough to turn "x = 2 + 2" into "x = 4" then it's smart enough to remove redundant jumps.

Is .NET that bad?

You really don't know what you're talking about do you.
gcc.godbolt.org/z/XZYX9w
In fact it actually looks like the C one is worse.

Time for more "I have no idea what I'm doing" F# code. Project Euler 3 this time.
I decided to make the union type Integer because it kept giving me grief about conversions between int and int64, and explicitly converting them back and forth looked ugly.
I'm sure there's a better way of doing this though. All methods of Integer have the same behavior regardless of whether it's int or int64 so there must be some way to generalize it.
Also I stole the sieve from "Learn F# in Y minutes", arrest me.

repl.it/repls/NimbleMaroonFolder
(It's slow as balls on repl.it, but instant on my computer)

>&(x.p)? Looks disgusting.
Ctards have no right to complain about disgusting code

>Overloading would just be confusing
then stop overloading all the arithmetic operators for ints and floats too. Oh and * for multiplication and deref, & for bitwise and and address taking.

Backblaze has free bandwidth to Cloudflare. Cloudflare has a free plan.

Wonder what happens if I serve 200TB/month?

Attached: consider.gif (500x281, 466K)

They will bill your ass. Or ban it.

Am I retarded? How the fuck am I supposed to read this? Should be easy enough to set all the offsets to 0 but I want to know how to read them.

Attached: picrelated.png (836x230, 16K)

A nibble is 4 bits (half a byte).
So you have 8 nibbles to set, that's 4 bytes.
Convert the offsets they give you to binary and you're good.

I have no idea what I'm looking at btw, but it's not hard to understand.

I'm doing research and writing a program in Lua that correlates the runtime metrics of a profiled program to git blame output. Lua is super comfy

>correlates the runtime metrics to git blame output
So ... finding who in your team is writing the shitty slow code?

Can someone sanity check something I'm doing.

I need an artificial namespace system in python so that different scripted plugins get their own set of variables to use and don't end up unintentionally sharing variables with another plugin.

Should I do this by making plugins use variables that are contained within a dict of dicts, where each plugin gets a dict of it's own variables within the larger dict?

Or should I be treating each plugin as it's own object?

i love state machines

How do you like to implement them, user?

I just like writing [spoiler]C____[/spoiler]

How could someone like dolls and have such a poor taste in programming languages?

Attached: haskell.jpg (562x1000, 154K)

I was trawling through my router's firmware looking for ways to (hypothetically) boost its transmission power. One of the formulas in the firmware is
actual txpwr = maxtxwpr of antenna - regulatory offset for wifi band. If I zero everything out something might happen.

Someone made a super simple 3d engine for love2d (most of my experience is with doing wii homebrew pretty much from scratch in c++, but the last thing I made was a pc game using love2d) so I'm rushing together a really really REALLY bad doom clone with it to like familiarize myself with it. I've got the engine pretty figured out, but it's super bare bones. Like it doesn't even support mipmapping or fog. Neat tho.

Attached: mood.png (1280x720, 328K)

That's a danger, yeah. We're trying to use mature open-source software to avoid those issues, but that's a threat to validity. Software quality and efficiency of implementation are a different problem to solve.

state machines don't love you back

How do I make this cleaner?
ghostbin.com/paste/frk5d

Here's the main loop too
int main (void)
{
board_init();
prog_init();
chip_init();

state = SM_start;

while(1)
{
timer_start(); //start 100ms clock

key = get_key();
if(clock_active) keeptime(&dt);
if(timer_active) timertick(&timer);
check_alarms();

tick_sm();

//if( !TIMER_RUNNING ) PORTA |= 0x02; //OPTIONAL - set LED IF not everything could complete in 100ms
while( TIMER_RUNNING )
{
if(alarm_ring)
{
avr_wait(1);
PORTA ^= 0x01;
}
} //wait out rest of the 100ms
}

FWIW this is the standard approach in Lua. Since there is no "proper" module system and functions are first-class, the way libraries are implemented is that everything is contained in a table that you include when you want to use the library. It sounds like this type of approach, a dict being the contained namespace for each plugin, could solve your problem, Python details notwithstanding.

I've been designing a 2d platformer game engine.

I have a question about object collision.

Every time I move i need to detect if I have hit something.
I have three options that I can think of:
1. Store every object in the same array and search starting at the beginning.
2. Create numerous arrays that each cover a specified area. This means that objects that span over two or more arrays must be in each of them, which means more memory taken. Also the previous and next arrays must be searched to prevent falling through when you pass over the invisible lines. So 3 arrays searched.
3. Store every block in the same array but it's also a BST to speed up search times. (Most difficult to implement but probably best option).

Thoughts?

1. O(n)
2. O((n/(number of arrays))*3) + more memory taken
3. O(log n)

I have basically implemented 2 at the moment.

Use a quadtree or something similar.

Take a look at k-d trees or quad trees. Or, more generally, space partitioning trees.

en.wikipedia.org/wiki/K-d_tree
en.wikipedia.org/wiki/Quadtree
en.wikipedia.org/wiki/Binary_space_partitioning

Ok. Another question governing the same problem.

Plugins will contain arbitrary code that obviously cannot be predicted ahead of time. Should I treat these plugins as strings to exec() (which I know is generally bad practice) or should I import them as modules containing functions. The problem with the latter is that, as they contain arbitrary unknown code, I will need to pass every variable that exists to them, and return every variable that exists, just in case it does need or change a variable.

Or is there some system in Python whereby arbitrary module functions can correctly be handled?