/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

tour.dlang.org/
wiki.dlang.org/Books
dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes
x86.renejeschke.de/html/file_module_x86_id_201.html
gustedt.wordpress.com/2011/11/05/chasing-a-phantom-checking-the-return-of-malloc/
github.com/tobixen/thrash-protect
hackage.haskell.org/package/lens
twitter.com/NSFWRedditVideo

>he doesn't have a mechanical keyboard
>he hasn't even gone to best buy to try them out

I don't know why you'd do this, but here's an example.
(defmacro caref (2darray cxn)
`(aref ,2darray
(realpart ,cxn)
(imagpart ,cxn)))

(caref (make-array '(2 2)
:initial-contents '((1 2) (3 4)))
#c(1 1))
; returns 4

I wrote this program that crashes your computer and doesn't get caught by the linux OOM killer.
#include
#include
int main(void )
{
size_t sz = 1;
size_t total = 0;
while (1)
{
malloc(sz++);
printf("%zu += %zu\n", (total += sz), sz);
}
return 0;
}

so this is the power of c ...

>Posted before the bump limit
Kill yourself OP, you fucking faggot.

Threadly reminder that dlang-chan has RAII; she's quite fast in execution and compilation; and she's super duper cute! Say something nice about her, /dpt/!
Also, Andrei's a cool guy.

>Tour
tour.dlang.org/
>Books
wiki.dlang.org/Books
>GC
dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes

Well yeah. Try running it as a normal user now.

>slut
yeah, great language you got there

I did run it as a normal user.

I don't believe you. Give me a root shell on your system so I can verify it.

If you want to crash your computer there are easier ways
#!/bin/bash
cat /dev/urandom > /dev/fb0 &
cat /dev/urandom > /dev/mem &
cat /dev/port

Trying to go in-depth with Python and the ecosystem after being deep in JS/Node for awhile. Am I missing something, or does Node actually get package management really, really right? Having package installation and dependencies handled by one tool (npm/package.json) and having all of your dependencies in a project-specific folder (node_modules) seems so easy and straightforward. Compare that to having a requirements.txt that may or may not specify versions, a package manager that is only kind of aware of this files existence, and a per-python-installation site_packages that requires you to set up all that virtual environment non-sense. I get that Node gets a lot of shit (deservedly so), but am I crazy to think that npm/package.json isn't so bad?

...

>he categorically accuses everyone with the misfortune to read his post of not owning a mechanical keyboard
>he hasn't even met all these people

I bought one in cherry mx red and I hardly ever use it because I don't have a proper desktop and I do all my programming on my thinkpad.

Really, it's my fault for falling for stupid memes, I could have bought a bigger SSD or maybe some girly clothes instead.

The Surface Pro I ordered has a mechanical keyboard. Checkmate.

i am building a webapp with django to serve as a leaderboard system for my shitty video game i'm developing in C + openGL

at this point i'm hardly learning anything and merely following tutorials to get done what i need

is the malloc call being optimized out?

>at this point i'm hardly learning anything and merely following tutorials to get done what i need
that's fine. web dev really isn't worthwhile. just do what needs to be done and prioritize your game dev

No, it is not.

I know I shouldnt but I really want to run this.

>write random junk to main memory
It's not catastrophic for you most likely.

Is there an x86_64 instruction to move a byte to a specific address?
mov BYTE[0x12345678], 0xc3
can be successfully assembled but
mov BYTE[0x1234567812345678], 0xc3 can't.

x86.renejeschke.de/html/file_module_x86_id_201.html

What do you think of my solution.
(defvar coins
'((hundred . 1e4)
(twenty . 2e3)
(ten . 1e3)
(five . 5e2)
(dollar . 1e2)
(quarter . 25)
(dime . 10)
(nickel . 5)
(penny . 1)))

(defun make-change (money)
(loop :as (coin . worth) = (rassoc-if (curry #'> money) coins)
:as n = (floor money worth) :collecting (cons coin n)
:do (decf money (* worth n)) :until (zerop money)))

out
* (make-change 1488)

((ten . 1) (dollar . 4) (quarter . 3) (dime . 1) (penny . 3))

I traced the process and it's exactly what I expected: malloc is failing to allocate memory due to my ulimits, but your program doesn't bother to check the return value. All it does after allocing 768MB is incrementing sz, adding it to total, and printing their values.

nobody writes software expecting null pointers after a malloc call, does openbsd really let you get away with silent out of memory errors?

what a pile of shit

Sorry, if you don't check that malloc(n) != NULL then you are an idiot and you shouldn't be allowed to write software.

>nobody writes software expecting null pointers after a malloc call.
That's one of the most basic things you do if you want robust software. If you're gonna have this attitude just use Java, ocaml or some shit.

What is even the point?
Can you even recover from an out of memory error without crashing?

>nobody writes software expecting null pointers after a malloc call
Some people actually try to write robust software, you know.
If you're writing something, and there really is nothing sane you can do with an OOM error, it's usually a good idea to write a function which wraps malloc and does the check for you.
void *xalloc(size_t n)
{
void *ptr = malloc(n);
if (!ptr) {
fprintf(stderr, "Allocation of size %zu failed\n", n);
exit(1);
}

return ptr;
}

>Can you even recover from an out of memory error without crashing?
Some programs can just try fall back to their main loop and try again later.

Thanks. Does that mean that there's no way to directly put an immediate at a specific 64bits address?

Yes.
You simply don't allocate more memory and look for memory you can reuse. If you absolutely need more memory that is. If not you can select algorithms that work in place or simply thrash non-vital systems.

But it's usually the case that if you want really robust software you allocate all the memory you can upfront. And you do your memory management in full control.

Look into how space shuttle code is written. It's C.

in the real world it's almost never necessary to check it

Yeah a simple example; until malloc(n) != NULL: print a message, send yourself SIGSTOP. Wait for the user to add some swap space or raise their ulimits and send SIGCONT.

how often does this actually happen in real software?

That's a fucking shitty attitude to have when it comes to systems programming.
It's people like you that cause fragile software.

Depends on the goal.
If you're perfectly fine with crashes all the time then sure, don't check for any errors. Just have everyone run your software through a bash script that's an infinite loop with your program doing blocking execution in the loop.

PS
I hear the webdev crowd actually advocates similar strategies. They let their nodejs servers crash on error and just restart themselves.

jesus christ the autism
kill yourself

reminder that it's summer and you have programming101 newfags sperging off with their hot dunning-kruger opinions

This would not be a common approach. This is the sort of behaviour that would be nice to see in a potentially long-running, non-interactive process. A linker, perhaps. The usual approach is to simply err(), as another poster mentioned above.

Exceptionally useless post user.
Its eternal simmer user. We have newbies all the time.

gustedt.wordpress.com/2011/11/05/chasing-a-phantom-checking-the-return-of-malloc/

I don't know what to say. That author sucks so much at C.

...

if checking malloc for errors every single time (and checking everything else for errors because 99.99% of other things would be more important to check than malloc) is a valid concern to you then you're clearly working on less common applications with very specific requirement. you brought up the space shuttle for crying out loud.

Filthy code monkey.

...

Don't understand me wrong, but he wrote an article to save one production line of code by doing the needful.

i hope you don't put malloc everywhere in your code. especially since you're supposedly doing super reliable long running applications you should be using a custom allocation scheme to avoid memory fragmentation.

>no smug loli tier

I can do that without even trying in Haskell.

1gb/s - 1gb/s = 0

>no side effects
>crashes your computer
what did she mean by this?

I do it by accident all the time. It happened most recently when I was trying to create an Arbitrary instance for a recursive data type.

ahahahahahaha haskell is such useless trash

hi guys, rooms all set up. Got all the furniture and put it in. Got some ethernet cables. Have plenty of desk space. Have my bong.

Oh btw, snack and drink on me.

I'm going to wait on plugging in the tower for now, yet again, because I don't want to be disappointed by something right now. I will be at this for a few hours, I hope.

>recursive data type

Has programming gone too far?

...

Yeah, I know, I should've defined it in terms of Fix instead of using explicit recursion.

Actually, we have IO now.

Only a complete shitlang would have IO, so obviously.

I don't know if you're memeing or not, but I practically killed my linuxbox recently by using Emacs + Idris. I have 8GB RAM and on some particularly hairy code I had my emacs eating 3 or it and Idris, running inside emacs, another 5. As a result, I had no free memory left for my system, which switched to swap, meaning it became unbearable slow. I spent next 5 minutes starting a terminal and killing the Idris process. I don't know by which I'm more annoyed, by the leaks in Idris or by the inability of Linux to deal with it.

>Posting the reddit version

>memeing
Fuck off, retard.

It's optional. Nobody's forcing you to use it. Just be careful of accursedUnutterablePerformIO.

So main is optional? I can compile and run an executable without it?

No memeing. This happens to me all the time. Currently running this and hopefully it works: github.com/tobixen/thrash-protect

Just finished v0.1 of a nice little graph database API thing and came to Sup Forums to brag about how cozy I am now.

>memeing
Use

>So main is optional?
Yes

>I can compile and run an executable without it?
No

an executable is an io

I prefer desu.

>No
In other words it's not optional? I see, so the language is shit indeed.
Nope.

Did you not read the other half? Main is optional.

I don't want your kind nearby. Piss off.

It is optional.
You can compile a library.

Not being able to run a program without it is hardly "optional" by any sane person's judgement.
I don't care about what you ""coders"" call "libraries". I use executables.

>memeing
Use

Interesting, I'll try it too.

did you know that main is optional in C too!?

An executable performs IO.

I couldn't care less about C. Don't mention that garbage ever again.
This is blatantly wrong and retarded.

Now you're shifting the goalposts. You can write pure function and evaluate them in the repl without any IO. In fact, that's what Haskell programmers did before they got IO.

Why do you hate IO so much anyway? Did `launchMissiles` kill your parents?

He has nothing better to do.
Every day he logs onto the basement computer and posts the same fucking thing.

>exited with non-zero status

Try harder next time.

>You can write pure function and evaluate them in the repl without any IO
I'm pretty sure the REPL executes everything in the IO monad. That would mean every single program I write will instantly get defiled.
>Why do you hate IO so much anyway?
It's what shit programmers use as a crutch. I don't want to be associated with them.
Also I despise the way every single platform handles it.

Is this Pythonic

def fibonacci(n):
l = n
ln = [0, 1]
while l:
ln.append(sum(ln[-2:]))
l -= 1
return ln[:n]

>pythonic

thanks dude. I just finished taking a few rips and I'm now I'm contemplating whether I should work on some guis on eclipse or maybe make some part of my game on unity.

Of course I may also turn on the tv and play my xbox one or ps4. I'm not sure yet. I was playing street fighter 3 3rd strike from my ps4 yesterday through the playstation now system. It lets me play some of the popular ps3 games.

I bought some xbox money and ps money earlier today. I'm hoping to buy Hyper Light Drifter for ps and maybe subscribe to an mmo or something on the xbox. If I want anything from these consoles, it's satisfaction.

Also, ran into this most beautiful woman at target again today and she was especially helpful and not just pretty. Turns out I see her there because she works there. I always just figured it was lucky timing. But to think that worked there the whole time...I really should've made some small talk.

while loops, short variable names, and increment/decrement operations aren't pythonic

What the fuck is even the use of this.
I'd seriously like to see a moderate example with explanations.

Functional references

hackage.haskell.org/package/lens
scroll down

>loops
How does it feel to be a barely sentient being?

So, is functional programming in Haskell far superior to Scheme's?

Yes

What is ``Functional programming"?