/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

hackernoon.com/why-i-like-coding-as-a-12-year-old-cdb19e87d57f
gcc.gnu.org/projects/cxx-status.html
gcc.gnu.org/onlinedocs/libstdc /manual/status.html
x10-lang.org/
godoc.org/golang.org/x/tools/cmd/stringer
twitter.com/SFWRedditVideos

A homework assignment and I can't figure out to organize characters by frequency and alphabetical order

Is there a more better way?
int xpos = 0;
int ypox = 0;

void move_north(void){
++xpos;
}
void move_south(void){
--xpos;
}

etc

Structs. Read the C++ guidelines before posting here again

void move(int x, int y) {
xpos += x;
ypox += y;
}

I'm assuming this is C, not C++

struct vector {
int x, y;
};

const struct vector NORTH = { 0, 1 };
const struct vector WEST = { -1, 0 };
const struct vector SOUTH = { 0, -1 };
const struct vector RIGHT = { 1, 0 };

void move(struct vector* pos, const struct vector* direction) {
pos->x += direction->x;
pos->y += direction->y;
}

// example
struct vector pos = { 0, 0 };
move(&pos, &NORTH);

Assing constants like north, south and so on. Have one move function that takes one of these directions and moves based on which one it was.

Is the "Big Nerd Ranch" book still the best book to learn Android programming?

I'm writing a game server and have been working on TLS for as of late. I wonder: should I generate a new private and public key on the server for every connection, or use a global one?

What I am really wondering is, are there any downsides to having a single public and private key set on the server side. After all, each key set takes 64 bytes of memory, so that's a lot more to store per client.

You lose one key, and all communication is compromised.

I guess that's a good point, yeah. Cheers.

const int DIR_DX[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int DIR_DY[] = {-1, -1, -1, 0, 1, 1, 1, 0};

typedef enum {DIR_NW, DIR_N, DIR_NE, DIR_E, DIR_SE, DIR_S, DIR_SW, DIR_W} Dir;

typedef struct {
int x, y;
}Vec2;

void move(Vec2* vec, Dir dir) {
vec->x += DIR_DX[dir];
vec->y += DIR_DY[dir];
}

// e.g. move(&v, DIR_SW);

As a bonus, you can conveniently iterate through a position's 8 neighbors.

AAAAAAAH FUCKING FUCK PIECE OF SHIT CODE
I SPENT 30 HOURS FIXING SHIT WITH ONLY 3 HOURS OF SLEEP

int xpos = 0;
int ypos = 0;

#define MOVE_NORTH() (xpos++)
#define MOVE_SOUTH() (xpos--)

moving in a grid is one of the great unsolved problems in computer science

Only brianlets code like that. Here's a better alternative:
int p[2] = {0};

#define MN() (++p[0])
#define MS() (--p[0])

pls explain user

double xpos;
double ypos;

static inline void
move_position(double units_north, double units_west)
{
xpos += units_north;
ypos += units_west;
}

take a look at this thread

>t. no-move brainlet

Learning Scheme nanopass

#define MOVE(dir, pos) void move_##dir(void) { pos; }

MOVE(north, ++xpos)
MOVE(south, --xpos)

I want to create a program that is able to download all past and incoming videos from a user's profile. Where should I begin? I know Java, C++,HTML/CSS/PHP and a bit of Python. The program is written in Java (I think).

It's already possible for me to download the videos using a packet sniffer to retrieve the M3U8, but that method is far too tedious.

>this is how cniles actually code

Don't target just android.
Write cross platform application YOU FOOL

With what? Xamarin Studio?

It's fine to not support iOS.

Source highlighting for compiler diagnostics in Rust using termcolor.

that's where all the money is though

my employer is forcing me write static html sites and they call that programming, send help

write them on COBOL you fool

Write an HTML transpiler for your favorite language.

use drag and drop builder

gayfaggot

Go is fun.

what are working on with it?

I am still learn, I am reading the The Go Programming Language by Alan Donovan and Brian Kernighan, but I play on writing my first non-trivial program soon. The first thing I program with any new language is an A* search algorithm for a game to get optimal results. Afterwards, I plan on creating a mafia IRC bot.

Wrong. Try again.

good luck, ESL-kun.

I see you've adopted a new shilling tactics, Rob, since "fun" is a subjective matter no one can argue you're wrong.

...

unsigned int fizz;
void foo() {
if(fizz == 1)
fizz = 2;
}
void bar() {
if(fizz == 1)
fizz

Are you compiling with optimization flags?

yeah with -O3

check gcc.godbolt.org

>Go is fun.
Go is about as fun as shoving needles up your dickhole, but at least it's better than Rust.

well if fizz == 1 then fizz

What's a fun programming language then?

forth
nothing is more exciting and fun than a healthy dose of reverse polish notation

>What's a fun programming language
Agda, Prolog, Smalltalk, various Lisps, Forth. I don't see what's fun about learning another generic curly brace language.

>Lisp
>fun

> useless shit from the 70s is fun
Found a hipster.

>it's better because it's new

glsl, smalltalk, pixie

>t. brainlets

fuck opengl, though

Shit that's good.

>it's better because it's old

nobody implied that you fucking inbred retard.

How do I become better at a given language? I can read books and write programs but I'd like advice on the language from people with more experience. Otherwise I feel like I'll just stagnate in my bad habits.

I'm talking about C++ specifically.

Coq

> I'm talking about C++ specifically.
Effective C++
Effective STL
Effective Modern C++

I've read them. I just think I'll internalize the messages in those books better if I see them being used in practice.

If I forget half the things I read, I won't remember them unless I re-read the books. If I see them in practice, I'll think, "Oh yeah, I remember that from the books".

That said, I should probably re-read them anyway.

>a language where all you do is meta-program when languages like idris can actually do the whole package

Practice building things. Find new programming resources such as free code camp etc

warning: passing argument 1 of 'free' discards 'const' qualifier from pointer

const was mistake

>mutability by default was a mistake
ftfy

>I recall reading about a memory deallocation function in the linux kernel that took a const pointer, and someone asked Linus why, and he defended it as saying it doesn't actually modify the value pointed to, either conceptually or in practice, it merely looks up the memory block using the pointer and deallocates it. I concur with his assessment, and thus view the free() function's specification as incorrect. But alas, it is the standard.
nonconstcorrectnessbabbies btfo

Fuck off Bjarne, nobody likes sepples or const correctness.

Read up on and try out newer C++11/C++14/C++17 features. Might just save your skin.

...

>only ever use immutable and mutable
>never deal with bullshit like this

your employer is doing gods work

For any language:
Learn the syntax.
Learn how the language works.
Make a few notes to yourself about each library that could be considered the standard way to do things.
Make small working examples of a ton of stuff.
Create a new project to test something small should be done at a push of a button.
Learn the tools surrounding the language.
With c++ specifically, learn the compiler, build systems like make files and cmake,
debugging tools like gdb and valgrind, ide features etc.

Isn't any object either mutable or immutable? Or are you saying that some objects are mutable only under certain circumstances? Sorry, I'm a nub.

C++ doesn't have true immutability.
const can get fucked with by pointer wankery.

String FindAddr(const &list l);


Why would you do this? Doesn't this mean you can't modify the argument?

constexpr

Not supported by my compiler.

Is it actually safe?
come join us in the 21st century lad.

functard

mutable by default makes about as much sense as lazy by default.

It's like [bad hardware analogy].

Okay, I am making(/constructing) a class called Menu. A menu may have other (sub) menus as members. So this is going to create circular dependency and I don't want any of that.

Any advice?

If your using C++, just use a pointer or smart pointer to reference the other menus from the main menu.

how do you guys feel about launch schools program? if you've encountered it

make a separate MenuNode class that holds a Menu members, submenus (possibly parent menus as well)

>deadline this monday
>i'm banned on stackoverflow

JUST FUCK MY SHIT UP DESU SENPAI

Reset your router

you don't have to ask a new question to solve a simple homework problem fucking retard

RESET YOUR ANUS

hackernoon.com/why-i-like-coding-as-a-12-year-old-cdb19e87d57f
Do you have to be 12yo to like "coding" in JS?

Herb Sutter's GotW series
Jason Turner's C++ Weekly series
CppCon and BoostCon presentations

if you want to avoid stagnation, keep up to date with the latest standards. have a look at the proposals documents in the links below for any feature or standard library component you're not already familiar with. C++14/17 both brought some very practical and powerful (and significantly syntax-reducing) new features and components, and if you're not using them, you're missing out

gcc.gnu.org/projects/cxx-status.html
gcc.gnu.org/onlinedocs/libstdc /manual/status.html

also; experiment. step off the beaten path that is the standard set of idioms, design patterns, and commonly occurring subset of basic features that make up the average project and much of C++ literature, and try to do something you've never done before. combine features and ideas in a way you haven't seen. try something you're not even sure will be possible. start out with a rough idea and then iterate and mutate and see where it takes you. it can make for a very good learning experience, and you're bound to stumble across some interesting things

>Is it actually safe?
constexpr values are computed at compile time, and are naturally inlined, so they generally get folded into the calls and computations where they're used as constants and don't show up by name in the binary. if it's possible to mutate one outside of a constexpr context, i've certainly never seen it. the compiler depends heavily on constexpr functions/values being provably deterministic

How do I become a 10x programmer?

by programming in x10?
x10-lang.org/

First of all, stop wasting your time on Sup Forums.

>The core object-oriented features of X10 are very similar to those of Java or C#.

>def sum0(a: Rail [Long]):Long {
var result: Long = 0;
for (var X:Long = 0; x < a.size; ++x)
result += a(x);
return result;
}


Wow, this is almost worse than Rust.

Yeah but instead (((safety))) the goal is easier programming for distributed systems and HPC.
I kind of like Chapel way more though because it compiles native executables instead of targeting JVM.

Readr/programmingcirclejerk every day

The move stuff in c++11 is pretty nice desu

godoc.org/golang.org/x/tools/cmd/stringer
>The recommended way to implement conversion-to-string methods in Go is to use a separate tool to generate Go code that implements the conversion
How come Go devs are so open to code generation and recommend it regularly, while the rest of the industry considers it evil?

Programming language is tool. If you need generate code then the language is not expressive enough, it's shit and should not be used.