/dpt/ - Daily Programming Thread

What are you working on?
Previous:

Attached: lain-mods-her-computer.jpg (640x455, 72K)

Other urls found in this thread:

pastebin.com/AG0QzaM8
programarcadegames.com/python_examples/show_file.php?file=move_with_walls_example.py
p.sicp.me/nLwzT.c
github.com/SadError256/okay
twitter.com/NSFWRedditGif

Reserved for OP's favorite langs
C and C#

Is there a difference between multithreading and multiprocessing on the dev side of things? If you're using a modern language do you use threads exclusively?

what DBMS do you use?

I guess you could just use multiple processes when you can trivially do things in parallel, ie. batch convert 1000 images files. If you want one single application to use multitasking, you should use threads.

javascript is the language of the future

>look at code
>see a mysterious method
>no idea why it's there or what I was going to do with it
>too afraid to delete it in case it's actually important
>at the same time have no idea what I should use it for

Attached: 4f934ba2b5b779b2f81b2c1e9a8c72f9--coding-we-have.jpg (700x979, 83K)

>ctrl shift f to see if you ever invoke it
wow that was hard

It looks half finished, so I must have stopped midway. But I don't know if I was actually onto something or just doing something really dumb, because I can't tell at all where I was going with it

Attached: 1523207067434.jpg (500x500, 54K)

Multiprocessing is a property of a system. Multithreading does not necessarily imply multiprocessing. From the dev side, modern languages are tending towards green threads or "tasks" rather than OS threads.

>too much of a brainlet to remember own code
>posts brainlet memes to mock others

>From the dev side, modern languages are tending towards green threads or "tasks" rather than OS threads.
"green threads" are completely different to OS threads. They are not mutually exclusive. Green threads is just a concept and happens inside of real OS threads.

>From the dev side
As in, what the developer is probably going to want to use.

I was mocking myself because I'm a dum dum, don't worry

Attached: 023136f6.jpg (1920x1440, 349K)

Also
>modern languages
You can do "green threads" with C and C++ with a bit of platform specific assembly

The OP asked about modern languages.

Not him, but excuse my autism. I thought you were insulting him.

gitlab's pretty nice, I think I prefer it to github actually, though I don't use much functionality besides just cloning and pushing. But maybe I would, gitlab's UI is pretty slick. Free private repos too, and the group stuff feels more natural. Also a web IDE haha, but I'm not sure if I'd ever use it, just kind of interesting since you can commit right there (to master or other branch)

i want to build and deploy a website. i know how to write the code, but i don't know how to set up the environment and deploy.

i've decided to use the following:

html/css/angular front end
java/mongodb back end
spring boot - dunno what this is but i'll figure it out
heroku - dunno what this is but i'll figure it out

is that everything i'll need?

I started doing that sort of thing on heroku but eventually just got a $5/mo VPS on digital ocean that I'm very happy with.

I need help with my c program
pastebin.com/AG0QzaM8
The string isn't being properly copied from one array to the other and therefore not printing, there are more details on the comments I already have on the code.

Attached: 1481424600840.png (696x455, 16K)

Think of multithreading as the software side, and multiprocessing as the hardware side

>pastebin.com/AG0QzaM8
im not gonna do your homework, but i'll tell you that you haven't initialized shit

>using statically defined arrays

what are all of the tools/frameworks that you're using? i can't find any goddamn tutorials that list out everything. something like

maven - build tool that does X
spring boot - Y tool that does Z
heroku - where you deploy (?)

in a class Person that simply defines an object we can move around with arrow keys, why do we define the position in the constructor but the velocity outside of the constructor!!! I don't get it..... :(

How do I traverse through a huffman tree? in other words, how do I print out all the nodes in the tree?

What hasn't been properly initialized?
Those are the only ones I know of.

>i can't find any goddamn tutorials that list out everything
Actually, this was finally the selling point on just getting a cheap digital ocean space haha. They have really great tutorials.

Some of the things I've played with are nginx and apache, frameworks like rails and ramaze, might finally get into haskell/yesod. Static page generation in particular hugo. SQL stuff, doing more advanced stuff than I usually do with git, basically whatever I'd be messing with locally now I can play with how it works on a server.

But you're also expressing a kind of frustration that made me just get completely fed up with web shit. It's always endless shit that feels like it's trying to wedge itself in and the stuff that's 2 weeks old somehow comes across sounding like it's 10 year old tech that you need to be using 10 years ago. Anyhow, good luck.

Picked up a book called Blue Pelican Java
Someone told me to go from that to C# then try Unity once I learn things. This is going to be a nightmare learning from the bottom isn't it

Attached: I1stlbk3o1_250.gif (250x250, 47K)

On average, I'm spending 4 hours a day, 7 days a week, to learn something, give or take a few hours depending on what is occurring that day. With this amount of time, does an unpaid internship sound reasonable in 9 months or so, or would I need to bump up my hours per day significantly?

i'm honestly just doing it to buff my resume cuz getting a job as a new grad is fucking retarded. thanks tho

As long as you have something to show on your portfolio you should be fine

considering its your career, i'd take it much more seriously than 4 hours.

Does anyone know the easiest way to pull video file info from a video using c#? I know there are ffmpeg wrappers online but I need something more lightweight. All the solutions I've found online are like 6 years old or more and no longer work.

well if you go the digital ocean VPS route, you've got a lot of options open. Mail server, cron stuff, user access, dealing with logs, using ssh. I promise I'm not shilling DO, because I could give a referral if I was which I won't. I just think that's what I'd do for experience and resume padding as a new grad.

Thanks, I know it depends on person to person, just wanted to get a ballpark.
I try to get as much in as I can during a given day, just can't get in more than 4 hours some days.

I should get into a more niche area of programming that is resilient against new buzz things. I wonder what that would be. My instinct says low-level, and heavily math-based. I have no experience with low-level but it doesn't sound unappealing, and I have a lot of experience with math and I'm into that.

Just trying to read about new web shit and thinking about how I can get myself enthusiastic about even finding out what it is makes me want to jump in a lake

I'm trying to self teach myself python here. I feel like I have a decent understanding of it.

However, could anyone quickly look at this and tell me when the "update()" function is used in the player class?

I really don't see HOW it's used, or even WHEN it's used. I can't see anywhere the function is explicitly referenced to the player

programarcadegames.com/python_examples/show_file.php?file=move_with_walls_example.py

stop programming on xanax

Learn Perl 6

Attached: p6-book-flowchart.png (1361x1123, 689K)

If you have a boolean and have an if statement for that boolean without assigning it true/false, does it automatically assume it to be true? Or does it need a predefined value for the if statement to run?
boolean gameOver;
if (gameOver){
//Something here
}

True.

You can do something like:

while gameOver:

and it will be same thing as while gameOver == True:

literally no need.

bitmask your game states, lad.

booleans generally default to false if you don't specify a value

I think this depends on the language, am I wrong?

once you try Perl 6 it will be very hard to go back to Python/Ruby/Perl 5

>implying i use script shit
I can already make quick programs with not-c shit.

I'm working through K&R. I'm not new to programming, nor am I new to C. I'm just doing the exercises to sharpen myself up.

My problem is that I over-think things, and spend way too long analysing a problem in my mind before writing out any code.

I'm currently doing Exercise 1-21, which, while it's on chapter 1, is a lot harder than it looks:

>Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab. When either a tab or a single blank would suffice to reach a tab stop, which should be given preference?

For the exercises, I'm restricting myself to what has been covered in the corresponding chapter. In this case, I'm restricting myself to whatever is covered in chapter 1, which means no extra library functions or pointer arithmetic or pointer use, except implicit pointers through strings.

Fuck.

Thanks, I'll try and look it up, utilizing Java right now.
Not sure, but thank you for letting me know that's a possibility! Like I said, I will look it up.
I am not nearly proficient enough to make any sort of game, I'm just using it as an example as I'm trying to get down how parameters and arguments work.

Why should I use pearl 6 over the languages you just mentioned?

K&R is a tad outdated. You should only use as it as reference guide. Working through exercises is almost pointless.
I'm reading and working through this.

Attached: 515ZB90pn6L._SX376_BO1,204,203,200_.jpg (378x499, 37K)

>What are you working on?
Decided to try to dive into programming again to be able to develop a game to compete with someone else's project purely out of pettiness and spite.

>working through exercises is almost pointless

Not at all.

Here's my detab program, for example, which replaces tabs with spaces:

p.sicp.me/nLwzT.c

Which program is best and free to start out with?

what are u asking? program to do what? browse the internet? i recommend netscape.

Alright that makes sense.

github.com/SadError256/okay little project I'm making. Has a programming language, a full text editor with WIP syntax highlighting, the idea is to make a program that does everything. Pretty cool I guess

I want to eventually create a 2D game

Can someone extrapolate to me if anything looks wrong with this code? Trying to run it in Eclipse, but I get an error when I first call on displayHighScorePosition on line 7.
public class highScores {


int player1Score = calculateHighScorePosition(1500);
displayHighScorePosition ("Andrew", player1Score);

int player2Score = calculateHighScorePosition(900);
displayHighScorePosition ("Bobby", player2Score);

int player3Score = calculateHighScorePosition(400);
displayHighScorePosition ("Larson", player3Score);

int player4Score = calculateHighScorePosition(5);
displayHighScorePosition ("Donny", player4Score);


public static void displayHighScorePosition(String playerName, int position){
System.out.println(playerName + " managed to get into position " + position + " on the high score table.");
}

public static int calculateHighScorePosition(int playerScore) {
if (playerScore > 1000) {
return 1;
}else if (playerScore > 500 && playerScore < 1000) {
return 2;
}else if (playerScore > 100 && playerScore < 500) {
return 3;
}else {
return 4;
}
}
}

you're not calling those functions with an object or classname

yeah, that’s raw code in a class body

Wait, fuck, is it because I don't have main public static void main (String[] args) listed? I am a fool.

it’s because you can’t just have code sitting outside of a function body, my dude

if it’s a function to print all player’s scores then why not make a method for it and put it in there?

I think I understand, it's just sitting in a body without being in an actual function so it's just silly when I could make a method that actually uses the information presented from displayHighScorePosition and calculateHighScorePosition, correct? And the answer to your second question is because I have no idea how to go about doing that, or how to combine the two methods into one.
t. brainlet just starting

it's a secret :3

What is happening in here? Why does it print garbage instead of "xxxxx"?
#include
[spoiler][/spoiler]
void f(char** in){
*in = "xxxxx";
}
int main( ){
char input[] = "hello";
f( &input);
printf( "%s\n",input);
return 0;
}

when is dynamic typing ever good?

Because C doesn't have strings. = doesn't do what you think it does. Use strcpy.

never.
don't let lisplets tell you otherwise

>Use strcpy.
nah, the code wasn't meant to do anything, just to activate my almonds

it isn't

char input[] is not the same as char** input

player is a subclass of sprite
all_sprite_list is a list of sprites, presumably gathered somehow by the pygame group function

on every game loop each sprites update function is called

all_sprite_list.update()


you'd want to inspect the pygame.sprite.group class if you wanted more specifics

why?

char input[] is a pointer to an array of chars (lets not sperg out over the semantics)
char** input is a pointer to a pointer
basically the first is
>pointer -> chars
and the second is
>pointer -> pointer -> chars

it became popular in a time when """"expressiveness"""" in code was seen as a good thing
it's never good

ok, but we're passing a pointer to a pointer to an array of char in f( &input);

i think whats happening is it's assigning the address to the beginning of the array
if im right then it should ouput an 'o' at the end

yeah not sure what it's doing but it's probably undefined behavior

then why do programming languages include it?

because they want to be cool and modern like javascript and python

no static typing -> shit programming language

that's dumb

>because it saves time!
>because muh faster prototyping!
>because who needs to worry about types!

And then they waste 3 hours debugging and refactoring just to not get flooded with run time errors and actually keep their application open.
Though implicit type casts are fine in common sense scenarios if you count those as dynamic types.

>Though implicit type casts are fine in common sense scenarios
Are there any advantageous cases for it over explicit type casts though?

strlen gives you the number of characters in a string. Because indexing arrays in C starts from zero, if you index with the number you get from strlen, you're pointing at the character right after the word. In C string are null terminated, which means that the character right after the word that the user inputs is '\0'. scanf adds this automatically to the input it received. In your program you copy that null character as the first character of your Result array. Your printf call stops printing when it sees the null character. Because you copied he null character right to the beginning of Result, it's the first thing printf sees so it stops immediately.

Saves a lot of time, and a lot of grunt work, especially in FPL's where there's a lot of behind the scenes stuff you don't really need to worry about. Implicit type casts only become a problem if the cast is dangerous and unorthodox like the wonderful world of javascript. Having to explicitly cast everything by hand would be a nightmare because you'd have 100x the LOC, and it'd be as bad to read as sepples.

Perl is only for those who wish to watch the world burn, Master Bruce.

Are you maybe exaggerating just a little bit about the time, grunt work and LOC that would be involved in only using explicit type casts and never using implicit ones?

of course.
but it's still terrible.
Try doing a project with absolutely zero implicit casting.

Ah! So the "garbage" data I was worried about was the \0
Okay I made some modifications and the program runs perfectly, thank you so much

Attached: 1400909414722.jpg (892x565, 151K)

what's the difference between:
char foo = 0;

and
char foo = '\0';

in C or C++?

I really don't think that would be a problem for me

There is no difference, but it may be useful for readability. The former is the integer 0 and the latter is the null character. They both have the same value but the intended meaning is distinct, like the NULL pointer macro.

Some weird fuck could probably make a non-standard OS where the null character isn't 0.

Also, in C++ the types of the two values are different. 0 is an expression of the type int, while '\0' is an expression of the type char. This can affect overload resolution.
In C they both have the type int. Such things are relatively unimportant in C.

Do you really save time in the end when you're stuck digging through a mound of code to troubleshoot an error that you eventually realize was just due to a variable being the wrong type at some point.

Your term make me think of using multiple processes against multiple threads.

Threads share program data memory, because they are nested in the same process. Therefore you can do things more trivially but have to be careful e.g. of shared counters, because all threads will increment the *same counter*.

For multiprocessing, you will have to duplicate all data because data ownership is not shared, i.e. if you want to operate on file all process need to open it. But you can have less programming complexity due to that, no counter are shared for example. If your program is trivial and does not require exchanging a lot of information between computing units, then multiprocessing is a good pick. On the other side of things, multiple processes is very wasteful in terms of resource usage (memory notably, computing power also if too many signals need to be sent).