/dpt/ - Daily Programming Thread

What are you working on Sup Forums?
Last thread

Other urls found in this thread:

arstechnica.com/gadgets/2016/04/the-ars-guide-to-building-a-linux-router-from-scratch/
github.com/enigma424242/RPG/blob/master/textbasedrpgtest.py
github.com/Warzone2100/warzone2100/blob/master/lib/netplay/netplay.cpp#L3303-L3356
twitter.com/NSFWRedditImage

Recommended text/videos/MOOC/whatever to learn C?

>muh algorithms
>muh data structures

first for rust

>first class environments

Found out the modem distributed by my ISP has a backdoor, what do?

arstechnica.com/gadgets/2016/04/the-ars-guide-to-building-a-linux-router-from-scratch/

Trying to program a new text hud for my game, this engine makes huds kind of tricky.
The new hud is almost done.

Darkstar (Tribes version).

Is there anyway I can "wipe" the "OS" that is in that router and follow that tutorial?

Game development is not programming.

...Is that show seriously a thing or is that a photoshopped sub?

Yes, this show does exists.
And no, the sub is not photoshopped.

Game development is programming, when you do not use premade engines and shitty drag and drops.

Of course the subs are fake.
Very few shows even mention anything programming related, and none of them actually go into real detail.
It's just an extremely shitty short series about some insecure fag.

I need help, guys.
I have an image and a list of colors, and I need to find out for any given pixel in the image, what the closest color in the list is. They're all in tuples.

You're not programming

How many years have you been posting here?

His post said he was using a shitty premade engine.

>Of course the subs are fake.
He asked if they were photoshopped, not if they were fake.

Sure, but claimed that "Game development is not programming", something which is wrong in many cases.

Right. I'm posting on Sup Forums at the moment.

Since back when gnome was good, at least

The engine was already there, but there's still programming involved

>Since back when gnome was good
Gnome was never good.

Nice theme, senpai-a-lam.

>Gnome was never good.

Wowee, can't wait to hear what your preferred DE is.

Back then and until relatively recently it was KDE. Nowadays it is openbox.

>using a DE
i3 all the way bby

Reposting muh budget tool

Looks like it's gonna be hermit mode for a while

vending machines help with structure, after that its tables and the operations and you're set to really explore

puts = mapM_ putStrLn
plot n f = range (range . point)
where
range = flip map [-(n-1)/2 .. (n-1)/2]
point ny x = bool ' ' '*' (f x (-ny))

circle stroke r x y
= abs (r - mag x y) < stroke
mag x y = sqrt (x**2 + y**2)
cross x y = abs x == abs y

*Main> puts (plot 9 cross)
* *
* *
* *
* *
*
* *
* *
* *
* *
*Main> puts (plot 14 (circle 1.75 5))
****
********
**********
************
**** ****
**** ****
**** ****
**** ****
**** ****
**** ****
************
**********
********
****

This man knows what he's talking about

I feel like its one person posting this retared webm

neat
but at least show the source code for stroke

Stroke is a parameter of circle.

hasklel fags making everything complicated

simple, actually

My bad, I just noticed.
Yeah, i'm trying to understand, but I can't see how it works.
How did you derive this?
Can you make other shapes?

How bad is it that I never use virtualenvs for my Python projects?

I can't understand how char * arr[20] creates an array with 20 pointers to char, somebody pls explain

and also char (*ar) [20]

[] has a higher precedence than *.
So when you do char *arr[20]
>char *arr[20]
>char *(arr[20])
>arr is a array type with 20 elements
>char * is the element type

>char (*arr)[20]
>arr is a pointer type
>it points to a char[20]

There are several different ways you can look at C declarations to see what type it is.

The shape it plots is a function f that given two coordinates x and y gives a boolean if the (x, y) is in the shape.

Any shape you can represent as a function from points to bool, you can plot.

*Main> let outside f x y = not (f x y)
*Main> puts (plot 11 (outside (cross 1.5)))
*******
*****
* *** *
** * **
*** ***
**** ****
*** ***
** * **
* *** *
*****
*******

thats pretty neat, wow
can you please make a swastika

>bool ' ' '*' (f x (-ny))

*Main> let (f \/ g) x y = f x y || g x y
*Main> puts (plot 21 (cross 1.5 \/ outside (circle 3 7)))
*********************
****** ******
***** *****
***** *****
****** ******
** *** *** **
* *** * *** *
* ********* *
* ******* *
* ******* *
* ********* *
* ******* *
* ******* *
* ********* *
* *** * *** *
** *** *** **
****** ******
***** *****
***** *****
****** ******
*********************

Sorry, forgot the import Data.Bool (bool)
bool f t x = if x then t else f

Okay, the .cs filenames suggest you're working in C#, but the keywords in this suggest something else. What language are you using for this project?

.cs is for computer science

can you make a letter function that plots a given char?

I'm asking here because I want the opinon on programmers.
I'm beginning my first CS class this semester and I'm looking for what is, in your opinions, a great 10 to 11 inch netbook that can run visual studio 2015, and can also have the ability to add more RAM

CuteSharp question:
Let's say I'm creating an object X, then subscribe to one of the events of X in this way:
X.Activated = myEventHandler;
Now the object X is left unused and will be GC, should I unsusbcribe to the events when I know I'm not gonna use that object anymore?

>visual studio 2015
Why? No actual computer scientist uses this trash.

And just get a x220.

Fuck, the operator should be the compound assignment. So "+=" instead "=".

What are they saying? :3

An easier way to read declarations is to understand that they're expressed just as they're used later in code.

So char *(arr[20]) is used as *(arr[i]) = 'a' for example, and char (*arr)[20] as (*arr)[i] = 'a'.

The thing with C declarations is that they don't map variables to their types directly, but describe how base types can be accessed from the variable. So "char *s" doesn't mean s has type char *, but *s has type char. If you think otherwise, you're prone to mistakes like "char* s, t;" which assigns t to type char, not char *.

>this thread
>programmers

>actual computer scientist

c number sign is from around 2000, this engine is from 1998. .cs files use a custom scripting language unique to this engine. We usually call it tribes script or the tribes scripting language. It is similar to the language used by the Torque game engine.

In C is there a way to make variables in scope to functions called later? I cannot place these variables as global or statics because they are function calls that are not available at compile (as they are based off console width and height).

#include someLibrary

void doesStuff(void);
void doesStuff2(void);

int main(void){

functionThatSetsUpScreen(); //this is located in someLibrary

while (!end) {
doesStuff();
}

}

void doesStuff(void) {

int w = height(); //this is located in someLibrary
//now go on to use w in this scope of doesStuff

doesStuff2();
}

void doesStuff2(void) {

int w = height(); //this is located in someLibrary
//now go on to use w in this scope of doesStuff2
}

The general idea is just to clean things up, rather than calling the same fucking function in each function. It can't be const/static'd because I get 'initializer element is not constant' errors. GCC, gnu c99 if that makes any difference.

It's what we're using in my class. I'm learning C++ and I'm told it's most compatible pls no bully

>It's what we're using in my class
What's your college?

>I'm learning C++ and I'm told it's most compatible pls no bully
It's not the most compatible, MS is always behind in the standards. GCC and/or Clang would be the most compatible.

Well if it is called Tribes Script, why not use a .ts file extension? Makes more sense.

What are function parameters?

>tfw tribes died

Void when calling height(); it returns something (obviously).

int screen_height(void) {
return screen->height;
}

screen is a structure in the library.

Guessing it's futile.

I assume when the Dynamix guys were working on Tribes, they decided to make the scripting language a sort of "c-script", or .cs. I don't have any reason to change the extension from what it is now.

package main

whereas func main(){
notwithstanding thetruthofthematter println("/dpt/ - Daily PHAGGOT Thread" despiteallobjections)
}

is there ever a use for not having breaks in some of the cases of a switch?

To fall through, for example a case might "map" functionality for some data. For example:
swtich (var)
{
case 'A':
case 'a':
doAFunction();
break;
}

Loop unrolling with Duff's device. Kind of outdated now that compilers can do it.

The other would be to do the same thing for multiple cases like so:
switch(x) {
case 0:
case 1:
do_foo();
break;
case 2:
do_bar();
}

If you want a variable to be visible to another function, you have only two options: pass it as a parameter, or make it available at file/global scope. If you want a variable to be available only some of the time, you can either write multiple functions (one for when an argument is provided, one for when one isn't), or you can let the parameter be represented in two ways. For example, taking a signed integer as argument, but letting negative numbers represent a lack of an argument, if the value is expected to be positive, or using a pointer as an argument, and using NULL to represent "ignore".

oh duh, yeah that makes sense.

the wikipedia for Duff's device is a bit over my stupid head but okay.

Anyone up for helping a newb improve his work?
I know my data structures can use some improvement but, what else? I built a little engine based on the same idea from ex43 of Learn Python the Hard Way. Should I treat Character() like a module even though it's mutable? You can make fun of it as long as you supply some constructive criticism.
>creation=True ???
It's there because you can pop back to those two menus after the character creation.
github.com/enigma424242/RPG/blob/master/textbasedrpgtest.py

Don't worry about it. As I said, the compiler can do the same thing nowadays.

so I'm watching a tutorial on C#, and I have a little experience with Java. And basically, I can't tell a difference at all. Am I expecting there to be too much of a difference after looking at hipster languages? Did they just call it a new name and everyone plays along?

Option 3: I'm not far enough in the tutorial to find out what's so different

I Don't do Java, but a friend said they were pretty similar. Though C# syntax seems more succint and less retarded.

putplot n f = mapM_ putStrLn (plot n f)
plot n f = [[pt x y | x feq 1 x 1.5 || feq 1 y (-2) || circle 0.5 5 x y
*********
*** ******
*** *** ***
** *** **
** *** **
* *** *
** *** **
*********************
*** *** ***
*** ******
*********

Thanks, options look limited enough.

what is that supposed to be
also, is that all the code you have regarding plotting?

That's generally how "scope" works in most languages. I mean, some languages have closures to allow an anonymous function to "close over" variables inside of another function (the one it is created within), but honestly, it's probably just passed some sort of pointer to an activation record as an invisible parameter under the hood anyways.

this needs to be in that 'just graduated' meme github.com/Warzone2100/warzone2100/blob/master/lib/netplay/netplay.cpp#L3303-L3356

>case 40: index += snprintf(buf + index, bufSize - index, string, ints[0], ints[1], ints[2], ints[3], ints[4], ints[5], ints[6], ints[7], ints[8], ints[9], ints[10], ints[11], ints[12], ints[13], ints[14], ints[15], ints[16], ints[17], ints[18], ints[19], ints[20], ints[21], ints[22], ints[23], ints[24], ints[25], ints[26], ints[27], ints[28], ints[29], ints[30], ints[31], ints[32], ints[33], ints[34], ints[35], ints[36], ints[37], ints[38], ints[39]); break;

I want to be at your level some day.
Reading lyah right now, but what I really need to be doing is exercises, as everything in your code is something I've been taught, but I haven't actually messed around and done stuff like that.

Did you think it would be more than that?

>no annotations
reads like vomit

its too sphisticated for it to have only those lines
can you post the rest?

you should create a library that does all those meme programming excersises

why is this gay crossdressing anime character the programming thread's mascot?

The code doesn't reference anything outside of what was posted. That's all there is to it amigo.

>try to zoom out to see the whole thing
>browser hangs

Crossdressing helps improve code. Try it out.

Wearing gf's panties and shorts atm.

Couldn't they just use vsnprintf?

I hate every build tool I've used other than Make itself. Maybe I should make my own makefile generator tool?

What's supposed to stop the for loop in this method? When c is no longer a digit?
I tried doing this example, but my program is getting stuck on that for loop, I put a print statement before and after the for loop and only get as far as the print statement before the for loop.

try out Plan9's mk, it's an even better version of Make

Hime isn't gay

It should be any cond inside that if statement that conditionally returns 0. Maybe the stdio input has restricions?

What is getch() for a function?
Does getch() halts the program until input is entered?

>What is getch() for a function?
>Does getch() halts the program until input is entered?
This is what happens when you learn to program on Windows.

It could be an ncurses function so doesn't have to be windows specific but unless getch() halts I don't see why the for-loop shouldn't end.

You could try printing c inside the for loop for debugging.

I'm looking for an image of a trap getting skirt lifted, there is a thought bubble with a star above an elephant.

Also what should I learn first Scheme or common lisp

been building shitty combinators on top of Clang ASTMatcher.
auto VarBind = [](std::string binding)
{
return declRefExpr(to(varDecl().bind(binding)));
};

auto DVarBind = [](std::string binding)
{
return hasDescendant(VarBind(binding));
};

auto MatrixBind = [](std::string binding)
{
return arraySubscriptExpr(
hasBase(hasDescendant(arraySubscriptExpr(
hasBase(DVarBind(binding + "Base")),
hasIndex(DVarBind(binding + "Row"))))),
hasIndex(DVarBind(binding + "Column")));
};

auto VectorBind = [](std::string binding)
{
return arraySubscriptExpr(
hasBase(DVarBind(binding + "Base")),
hasIndex(DVarBind(binding + "Index")));
};

auto BinaryOperatorBind = [](std::string operatorName, std::string binding, auto injectLeft, auto injectRight)
{
return binaryOperator(
hasOperatorName(operatorName),
hasLHS(injectLeft),
hasRHS(injectRight)).bind(binding);
};

naturally there's more,

It was the OP image for the /dpt/ before the previous one.

And I say Haskell.

Here, I rewrote it in Javascript for you.


function range(from, step, to, f) {
for (var a = [], x = from; x != to; x += step)
a.push(f(x));
return a;
}

function putplot(n, f) {
plot(n, f).forEach(function(line) {
document.write(line.join('') + "\n");
});
}

function plot(n, f) {
return range(n, -1, -n, function(y) {
return range(-n, 0.5, n, function(x) {
return f(x, y) ? '*' : ' ';
});
});
}

function feq(eps, a, b) {
return Math.abs(a - b) < eps;
}

function mag(x, y) {
return Math.sqrt(x * x + y * y);
}

function circle(w, r) {
return function(x, y) {
return feq(w, r, mag(x, y));
};
}

function smashlogo(x, y) {
return feq(1, x, 1.5) || feq(1, y, -2) || circle(0.5, 5)(x, y);
}

putplot(5, smashlogo);

Great meme.