/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: DPT.png (934x1000, 389K)

Other urls found in this thread:

youtu.be/X36ye-1x_HQ
youtube.com/watch?v=4i7KrG1Afbk
youtube.com/watch?v=7Hlb8YX2-W8
dlang.org/spec/version.html
twitter.com/SFWRedditImages

they'll get inlined, you can check the assembly if you're worried

>OP

Attached: 1539188643051-g.jpg (800x999, 182K)

>i'm such a fucking brainlet i can only think in one way
wwwwwwwwwwwwwww
Cniles are funny.

>no kpop
>doesnt ask me about my emulator
its shit

Declare them as static and enable any level of optimization in your program. They'll get inlined.

How come when ncurses recieves the resize event (keycode 410), stdscr doesn't also change it's width and height?
How can I make it change it's dimensions?

>try Qt
>QApplication::desktop()->screenCount() == 1, should be 2
>virtualDesktop == false
off to a good start!

This is why you stick to backend

noice OP

JavaScript rocks!

Attached: js-rocks.png (1000x494, 369K)

I know the implication of your post and what you're trying to do.
I still stand that trying to manage memory in haskell is not a good idea because you're fundamentally fighting the language's intention.

Unironically this

fuck i mutated my program so much while trying to debug and find where the mistake is

Writing a shell in Haskell.

Trying to figure out how forking works is killing me because I can do it in C, but im such a brainlet I cant do it.

bet this nibba has no tests in his program

often when i'm finished debugging i have to remove twenty print statements with format strings like "NIGGERfdsafda %f %d %d %d\n"

why not just use a debugger instead? VS debugger is fucking excellent

i didn't before, but now i have a hundred asserts throughout (the failure of which helped me find the error). if i get it back to a working state my program will be well-tested

tfw I accidentally promote one such string
tfw I know this will live in my company version control system

i was using pdb for a little while, but its fucky when reading from stdin and asserts and prints were a lot faster

maybe stop being a retard

Best way to store .mp3 in memory in Java?
I send a music thought TCP, read it as bytes. What's the best way to store them?

.jpg

>rewrite code completely to debug something
vs
>just attaching VS debugger and setting breakpoints in points of interest

Damn, what a difficult choice to make

Attached: 1494595645505.jpg (358x513, 48K)

>just sticking a printf in there vs pissing around with a debugger
stupid VS using animeposter

>he has to remove debugging shit
>his language doesn't have a debug {} block that doesn't compile on release mode
wew laddie

>>just sticking a printf
>"fuck i mutated my program so much while trying to debug and find where the mistake is"
Anime website

Attached: 1523099107268.png (295x200, 6K)

>debugging
>not just having the language typecheck then ship straight away
wowsers laddies

uh, you mean like an ifdef?
that's not the issue

not him but you're the retard

Any language with macros can do that. But sometimes you want to print data to see if it's where the problem is and once the problem has been resolved, you don't want it cluttering your debug information.

>debugging
>not just nailing it the first time around
lmao

>typechecking removes all errors
wawserino

>uh, you mean like an ifdef?
>Any language with macros
absolutely disgusting.
and no, i literally a mean a debug block you can stick anywhere
debug
{
...
}

based

so, the exact functionality as a macro then

The difference is, it's a native part of the the language and not a disgusting macro.

I like this talk: youtu.be/X36ye-1x_HQ

Attached: 05CONFIRM1-articleLarge.jpg (600x400, 22K)

Macros don't have to be disgusting. Embrace homiconicity, user.

do macros not count as part of a language

Attached: 🤔.png (160x160, 12K)

Lisp is shit and C macros are awful.
Nim macros are okay though.
macros as a general feature do, but the mechanics you implement with them do not.

How is that any better than this?
#define DEBUG_MODE

#ifdef DEBUG_MODE
#define debug(a){a}
#else
#define debug(a)
#endif

Mechanics you implement using macros are only shit if macro support is shit.

No, they're part of the preprocessor. They're evaluated before the language is compiled by the compiler. You can have a separate non-standard preprocessor that produces complaint code.

idris talks in general are pretty great.
youtube.com/watch?v=4i7KrG1Afbk
This guy gets into some hello world-level proofs

no you dumbass

It's clean and not pre-processor hacks.

when will I be able to work with idris without using icky haskell

pls no bullie

Grow up, Cnile. Text substitution """"""macros"""""" don't deserve the name.

>#define DEBUG_MODE
So you have to edit your code to disable debugging? I thought usually you pass -D to the compiler to enable features in the build.

Doesn't having any code that's depended on the build incite the preprocessor? The only difference is one you have to spend 10 seconds implementing yourself.

I'll bully you whenever I want mah nigga

You can do that too, that was just more concise for posting.

So debugging is either evaluated at runtime, which incurs a performance penalty and binary bloat, or internally it still uses preprocessor "hacks".

>So debugging is either evaluated at runtime
you can have compile time stuff in the debug block.

How is that any different than

Because like any C macro it comes with caveats. Plus debug blocks come with levels and conditionals you can check, and then you have version blocks where you can define certain features. All require more and more implementation on your DEFINE in the C version. And by the end the C version is a monstrosity you regret even starting.

He doesn't really explain too much of what he's doing

Yeah, it's definitely not an intro video, more for people already seasoned in FP/Idris.

so let's say i have a Java object
and let's for the sake of argument imagine Java didn't have a GC

let's say this java object was made up of different java objects

when i free the object, i would also have to free the different parts right, recursively and what not

is that what the GC basically does, trace pointers, algorithm specifics aside

>write debugging function
>write macro to include function in code
>edit debugging function as needed
>macro never needs to change, just a simple ifdef

youtube.com/watch?v=7Hlb8YX2-W8
Comfiest video. Actually made me feel much better as I'm learning as even someone who's really good at programming constantly searches, makes mistakes and keeps trying

That's the issue.
You're actively working on a feature that should be a part of the language itself. But you're a C programmer, that's just life for you, so you think it normal. But it's not.

>even someone who's really good at programming constantly searches, makes mistakes and keeps trying
not me

>>even someone who's really good at programming
>not me
makes sense brainlet

i need an answer

that could be part of one approach to GC, yes

but in practice there's less "I freed this, now free it's children" and more "I know where all objects are, and I can check if any of them are no longer referenced by any living object"

like just search for "generational garbage collector"

*its

those object references may also be present in other objects
A GC typically does not identify which objects can be freed. It identifies which objects cannot be freed because they can be reached and then considers everything else to be garbage. There is an important difference.

Yes

Are "debug blocks" some automagic thing that just happen for you? No, because you mention defining "certain features". Sounds like some abstracted OOP bullshit-as-a-feature.

>Are "debug blocks" some automagic thing that just happen for you?
yes?
>No, because you mention defining "certain features".

can someone explain to me how python argument passing works?
why can't it work in the same way as C...

fuck.
>Are "debug blocks" some automagic thing that just happen for you?
yes?
>No, because you mention defining "certain features".
with version blocks.
dlang.org/spec/version.html

>10 hours straight of sitting in front of your computer programming in Python of all languages
>appears to spend half his time debugging OOP language features instead of the code and program logic itself
How can normal, non-autistic people compete with specimens like this?

geohot is a madman.
shame he's wasting his skills and autism on shit like that.

What specifically do you mean?

thank you for the answers
i'll have to figure out something

so in terms of writing a GC, a working (but naive and possibly slow) bookeeping strategy would be to maintain a "pointer tree" and when the GC is called i traverse the tree and keep what i coul access

and the rest is just garbage

Python is call by value.

Only if it's a basic type

Lists, dicts and objects are all pass by reference

In many languages, C++ for instance, classes have a destructor method that can destroys the object's contents, by calling their respective destructors. Generally, whatever an object creates in its constructor, it will destroy in its destructor.

But let's say you were to create an object 'parent', and get a reference to its internal object 'child'. If you destroy 'parent', that would destroy 'child' as well, which would make your reference invalid. (This is assuming the parent's destructor does in fact destroy the child.)

In a garbage collected language, destroying 'parent' wouldn't necessarily destroy 'child'. If you have a reference to 'child', then the garbage collector will see that it's still reachable, and won't destroy it. But after you set that reference to something else or let it go out of scope without making any more copies, the next time the garbage collector runs, it will see that there are no more references to 'child', and destroy it.

Python is call-by-value. Some of those values are references to mutable objects, but even for a list

def f(xs):
xs = [1,2,3,4]

ys = [3,4,5,6]
f(ys)
print(ys)


won't rebind ys, as it would under call-by-reference.

Should I put this shitty 100LOC game I made in LISP in a github?

Attached: 2018-10-17-182120_725x378_scrot.png (725x378, 5K)

literally wtf.
can you provide a link with indepth on this

*Call by object.
I don't think anything in Python is a value.

I got a distinction on my first programming assignment/test today at college.

so the GC you describe is in accordance with what i posted here where if a child is referenced somewhere, it will stay alive

but a poitner tree is probably a misstatement
i drew a picture

arrow pointing to you, means i am your parent and am using you

obviously deleting the lone 2 objects is correct as is deleting the blue node

is there an algorithm that traverses such a structure reasonably

Attached: program.png (640x480, 5K)

no it doesn't seem to meet my arbitrary lisp game criteria so you're not allowed.

why the fuck not

gonna take you 2100 to do that in C

first write a LISP interpreter than the game in 100 lines

To add onto the other people's answers, Python is pass by value and all values are references. Python sucks ass.

not per se, but consider the following:

C is call-by-value, where some values are pointers:
#include

void f(int *x) { *x += 3; }

int main(void)
{
int y = 7;
f(&y);
printf("y = %d\n", y);
return 0;
}


O'Caml is call by value, but some values are references (sorry O'Camlers, I can't remember how to get rid of the fucking ;;s)
let f x = x := !x + 3;;
let y = ref 7;;
f y;;
Printf.printf "%d\n" !y;;


See the distinction we're making? In any of these, if we assigned/rebound the "pointer" variable in the callee, the caller doesn't see it. It's only when we explicitly dereference it and mutate the thing behind the "pointer" that the caller observes a change.

Python just makes the dereference automatic and implicit.

Why would you allow overriding registrations in SimpleInjector?

>LISP interpreter in 100 lines
Hey, I did one! (not counting the parser, of course)

Lisp Interpreters can be made in about 7 lines.

Mine is better. That little overlay window was a pain to implement correctly. What kind of data structure did you use for the snake? If it's O(n), e.g. a list, don't embarrass yourself.

Attached: out.webm (590x362, 1.68M)

Integers between -5 and 256 are values
>>> x = 255
>>> x is 255
True
>>> y = 256
>>> y is 256
True
>>> z = 257
>>> z is 257
False
>>> a = -5
>>> x is -5
True
>>> b = -6
>>> b is -6
False

I used a list to represent it, how else can I do it?
My game allows for pausing, and for the snake to reappear at the bottom if it goes out of bounds.
I had a script to capture using ffmpeg but I don't have it anymore so I can't show you how exactly it looks.
Also, why use all that milisecond stuff when you can use halfdelay?

I just learned about builders. They're pretty neat.
public class MyClass {
// private final instance variables go here

public static class Builder {
// Required parameters

// Optional parameters - initialized to default values

public Builder(....) {
// set required parameters
}

// setters
public Builder method_0(....)
{ ...do something...; return this; }
public Builder method_1(....)
{ ...do something...; return this; }


public MyClass build() {
return new MyClass(this);
}
}

private NutritionFacts(Builder builder) {
// set all parameters using builder
}
}


MyClass obj = new MyClass.Builder(a,b).method_0(c).method_1(d).build();

damn, the private constructor should be "MyClass" obviously