/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

pastebin.com/ah9MTspA
youtube.com/watch?v=uiJycy6dFSQ
washingtontimes.com/news/2017/mar/7/berkeley-removing-20k-free-educational-videos-afte/
oodesign.com/
vincehuston.org/dp/
lostechies.com/wp-content/uploads/2011/03/pablos_solid_ebook.pdf
twitter.com/AnonBabble

D a best

First for C.

fuck off terrorist scumbag.

Nobody ever talks about SQL here. Why is this?

Thanks for your concern, shlomo

Eureka! Perlin noise terrain generation in my minecraft clone.

Anyone remember me posting about this about a year ago? I haven't worked on it until a week or so ago.

The terrain generator runs like dogshit right now because I coded it as lazily as possible and I'm also running it in interpreted mode but whatever. I can add memoization and not recompute the same values over and over again pretty easily.

here's the code: pastebin.com/ah9MTspA

The actual render loop runs really well.

FPS: 59.999999
Frametime: 16666667
OpenGL "FPS": 1657.577616
OpenGL Frametime: 603290

But she has the quoran on her hands. Why so mad.

Python Power

Please stop making minecraft clones its the year 2017.

>yfw Knuth wrote the Quran

It's not a general purpose language and is only technically Turing complete after a recent release, or so I read. But it seems like a well rounded programmer should be versed in SQL beyond the basics. I'd like to get gud with it but currently lack the motivation.

So this is a question from ignorance on my part. Trying to figure out proper memory management in C. Below is some code I wrote up to illustrate a point.

char* TestFunction(int Length){
char *PointerZero = malloc(Length*sizeof(char));
char *PointerOne = malloc(Length*sizeof(char));
/*
Do something with Pointers
*/
free(PointerZero);
return PointerOne;
}


So long story short, provide a value to this function and it'll fuck around with to char pointers. This function must return PointerOne. When this function exists, what happens to PointerOne memory wise? It bothers me that there is no free(PointerOne) here to match the malloc. However, doing so before PointerOne can be returned sounds like a good way to fuck up results. On the other hand, won't TestFunction just eat memory if it is constantly called since PointerOne is never being freed?

Uh, so what is the best way to handle this??

Making some stuff with golang to learn it.

When you call free you've given up your rights to the memory. The system reclaims it. It's like selling your house then coming back a month after the new owners move in and trying to take a shower.

When you call TestFunction you have to remember to free the result of it yourself. Welcome to non garbage collected languages. Memory management is a bitch.

I seems like you've run into the issue that is "pointer ownership". Which is basically to say, who is responsible for calling free()/whatever on this.
There are many ways to do this, and some make more sense than others in certain situations.
If you're expecting the caller to free the pointer, you should document that.

A common thing people do is:

void testfunction(char * result, int len) {
char * ptr = malloc(length * sizeof(char));
// do something with the two pointers
free(ptr);
}


This way you can make non pointer globals, locals, and struct values so you don't have to remember to free them. And when you need a real dynamic malloc'd pointer, you can malloc it yourself.

Stop posting muslims on blue boards

At least he's doing something
Not like you, lazy fuck

C is the best breast size and programming language.

Because SQL is dead?

Seriously, if you still use a relational database in 2017, you should neck yourself.

Stop posting homophobia, racism, sexism, antisemitism and hate speech in general on blue boards.

Are you suggesting everyone to continue to spam mongo everywhere when it's clearly not necessary?

/dpt/
in C, is it bad practice to write an ADT like this?
int create_greeter(char const *);
void destroy_greeter(int);
char const *greeter_message(int);

The implementation file would then have static pointers for each member of the ADT, pointing to dynamic arrays all the same lengths, and creating and destroying would both work by realloc'ing the pointers.

>when isMainModule:
# test the new ``*`` operator for sequences:
assert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9])
Absolutely dropped. I should have known when I saw top level functions

Fuck off back to your ANTIFA safe space you CIA nigger faggot!

C doesn't have ADTs. Own up to it and upgrade to a language that requires higher level of IQ

I don't really see the advantage of that over just handing the struct itself back.

You are not civilized. Learn some manner.

Only board that matters on Sup Forums is Sup Forums. Get over it.

@61269284
(You)

>C doesn't have ADTs.
>he said, regarding an implementation of ADTs in C
>while also managing to not answer the question

>safe space
You were the one on the verge of tears because the girl on OP's is (presumably) a Muslim.

Also, hate speech is against the rules, you dipshit.

Not him but why don't you fuck off to your containment board then?

>Only board that matters on Sup Forums is Sup Forums. Get over it.
FTFY

The advantage is it wouldn't be an array of structs, it would be arrays of fields, thus saving padding space
As advantages go, it's pretty retarded

Remember to report mudslime posters

You go back to YOUR containment board, faggot

If you're trying to be funny, it's not working.

>thus saving padding space
Not necessarily, if you pack your structs correctly.
I don't really know how this data is going to be used, though.
I'll list some disadvantages that come to mind
- It's non thread safe
- It's not type safe

/r/ is not a containment board, you should immediately fuck off to your daycare board, autist

Fucking redditor, piss off.

How do I into IO in Scala (or Java)?

I have an idea, how about SJWs stop creating new threads 100 posts early with trannies and muslims so we can actually discuss programming for once.

>/dpt/
>programming

Don't use Scala

>100 posts early
The other thread was autosaging already, faggot.

>trannies and muslims
Stop sperging out about minor details.

Go away SJW

Make me.

>subhuman race that thrives on destroying western society by fucking your daughters and make rape babies with them
>minor detail
Go back to /r/marchagainsttrump already

You don't come to someone's home and tell him to get out

Sup Forums is slow as fuck, you don't create new threads until it's page 10. You know that, but you do it anyways because you're either a paid shill or a retard who gets off on ruining threads.

I'M WORKING ON KILLING ALL ANIME
KILL KILL KILL KILL KILL

>islam
>race

Hi, newfriend. How's your first day on Sup Forums going?

Enjoy your ban, shill.

Why not

It's awful.
If you want to use Scala, use Haskell instead.

I am certain that most of your hatred towards mudslimes are created by *ews, in which case I am not surprised.

It says muslim in you fucking nigger learn to read.

Posting in Rust thread.

...

W E W
E
W

>Come to the new thread
>It's an episode of a Sup Forums autist having autistic meltdown because of the OP picture
Considering the fact that most of Sup Forums users are school girls, they sure are quite edgy.

is reading sicp a meme like boku no pico and hipoints?

I have zero programming experience

>is reading sicp a meme
No, but it's definitely useless unless for academic purposes.

>I have zero programming experience
Then you surely won't be able to appreciate the reading.

I think you have to go back.

>wikitionary
Nice try, shariablue

You have zero chance to take a gf. End your life.

I wish I could go back to the time when Sup Forums was not mainstream because of fucking cancerous phoneposters

wasn't it written to teach programming? if it's for academic purposes wouldn't that be perfect for someone learning?

take a gf? what does that mean my indian friend?

>cancerous phoneposters
Like you?
Also, that time was a time when you didn't even exists. Even in your parents' plans.

Why is it awful

>wasn't it written to teach programming?
Yes, but it failed at that and is now used to teach symbolic systems.

>if it's for academic purposes wouldn't that be perfect for someone learning?
Oh it's great for learning. Doesn't mean what you learn is going to be useful.

>be me
>be playing a game called hackmud
>in hackmud you code in javascript and use other people's code
>compete over monopoly money using le code
>in hackmud you have limited char count
>but ininite read and write access to a database
>pfft
>write bytecode interpreter
>write program that converts whitespace into strings so it doesn't count against char count
>now writing a forth to convert strings into bytecode
>forth has full macros
>can achieve the syntax of any language
>shit will be so cache

here is the common link
youtube.com/watch?v=uiJycy6dFSQ

#include
main(){
char *p = 0;
while(p++) *p = 127;
}

>run this code
>pc crashes

nice language c tards

Why would I want to go back to the time that sets me up in a condition that I am not already familiar with?

I know your type is typically "slow" but you have to sacrifice all your brain cells to reach this level of retardation.

Not an argument.
And you're not funny at all.

Clearly a fault of your OS user.
But if a language couldn't produce this same issue i don't think it's worth using.

Why do you keep posting muslim females?
Can't you understand you are not welcome here?
We don't want diversity and more strong womyn in tech.
So go back to your gender and intersectionality studies and leave us alone.

interesting, I will have to do more research. should I select another book for lisp or pick a language with a large learning community like python?

He doesn't know what he's talking about. Scheme is great and wonderful. He probably just used the barebones interpreter that was recommended by the book.

was written in a mix of Scheme and C.

to be very honest.
All I want is competent people who are not dysfunctional fuckwads.

So why doesn't someone else make a thread, before OP?

When does it make sense to start to split up my C project into multiple .c source files? Right now I have a single .c with a few structs defined before the main function and 7 functions. Should I put the struct definitions in a separate .h? Should I leave the functions in my main .c?

There is no right answer to that question. It's up to your judgement.
However, 7 really isn't that many. You'll be fine leaving it as it is.

Functional programming, despite having advantages, too often serves as a vessel for the aggrandizement of vapid establishment pablum.

main = print (the first (number `besides` 1 `such_that` (it_is_odd `and` it_is_square))))

the = id
first = head
number = [1..]
such_that = flip filter
it_is_odd x = x `mod` 2 == 1
it_is_square n = sq * sq == n
where sq = floor $ sqrt $ (fromIntegral n::Double)
and f y x = (f x) && (y x)
besides list x = (filter (/= x)) list

How do I get a feel for OOP?

I understand the basic concepts, but when it comes to integrating them into a larger project I'm hopeless. I just wrote the world's shittest game of pong with only one class and the code is filthy.

post code

I see, thanks. Is it bad form to leave struct definitions before my main function as opposed to in a separate .h file?

Read pic related.

Can we not have pictures of whores in the op, please?

And then read this.

I want to become more proficient in automation and writing scripts on Linux. Should I start with bash scripting or Python?

washingtontimes.com/news/2017/mar/7/berkeley-removing-20k-free-educational-videos-afte/

>was going to watch the brian harvey lectures while reading sicp
>all the videos have been removed

wow

Bash

bash

oodesign.com/

vincehuston.org/dp/

lostechies.com/wp-content/uploads/2011/03/pablos_solid_ebook.pdf