/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

baptiste-wicht.com/posts/2015/07/simulate-static_if-with-c11c14.html
stackoverflow.com/questions/13799420/why-there-is-no-static-if-in-c11
services.github.com/on-demand/downloads/github-git-cheat-sheet.pdf
kickstarter.com/projects/520965826/basil-the-comprehensive-programming-language
twitter.com/NSFWRedditVideo

First for D

...

>Fag shit
Delete this thread.

I thought you abandoned us you fag ;_;

Is this lolicon?

better example

Why would I abandon akari-bbs?

Also I forgot my pic~

Hoh boy

From last thread: Currently trying out ReactJS. Horrified that a simple example app requires 1.8MB after webpack.

Going to work through Sirajology's videos on youtube and put together a HFT bot that uses Twitter sentiment analysis and Trump tweets to see if it can beat the market.

>dickbutt

Found the redditor!

>Horrified that a simple example app requires 1.8MB after webpack.
Yeah hello world is like 24k lines of JavaScript, sucks that the "right" way of doing things shifts every month in the JS land so I'm not even touching it because all the doc/tutorials are broken and outdated.

you are easily the best user in this thread

List the top 10 essential languages to learn.

chinese

what is the easiest way to draw pixels into a window?

raw XCB?
opengl?

In C, is it possible to define a macro that pastes another macro that will get expanded in that same pass of cpp?
Ex:
#define hash #
#define defmacro(X) hash define (X)

defmacro(Y 10)

int x = Y;

->
int x = 10;

?

Does this necessarily require 2 passes of cpp?
Can another method make this require only one pass of cpp?
The end goal is this:
download("website.com/file.h")
int x = FILE_Y;

into this in one pass:
/* contentes of file.h */
int x = 15;

D
D
D
D
D
Assembly
D
D
D
D

im programming a templated subroutine with a Traits object filled with compile-time static variables.

Something like

template< class Traits>
void Blah( InData in_data)
{
...
}


How do i make my function call
in_data->utils->iterate(...) if Traits::Bits is 8 and in_data->utils->iterate16(...) if Traits:Bits is 16 without having two copies of Blah() just for this one specialization?

dickbutt is a Sup Forums meme

nevermind the end goal, cpp cant download things
how do i delete posts again
I think my css hides it

Sure, tell yourself that. Maybe you're gonna sleep well after stating that, who knows?

is Traits::Bits constexpr?

ok

will?

yes.
It's
static constexpr size_t Bits = 8;

Should I bother learning SQL?

can the 8 vs 16 not be a function parameter to iterate?

Why is Python such a fag language?

If you want to do anything fun with the web, yes.

That's why you should learn Elixir instead.

no, as it's a library function outside my reach of modification.

actually wait
they're compile time static variables
templates only instantiate the one that's used

are you actually instantiating the function twice?

ones that are used*

Try SDL. OpenGL is only worth the effort if you're doing 3D shit or you need to render a lot of shit in real-time.

Everyone says D but I have honestly never seen D code posted here, or even any indication that anybody is actually using it and not just talking about it.

this isn't leading to the problem being resolved but the compile-time Traits object I am talking about does not only vary by the single variable I just told you about and will alter the behavior of this function depending on the compile-time variables inside. And I've reached a point in which I need to call one library function for 1 bit-depth, and a different one for another.

There is no compile-time conditional function either so if I was to make a big rack of if-ifelse it will still have to evaluate the cases that do not match.

There has to be a way to set an "auto" function pointer to either `iterate` or `iterate16` at compile-time based on this one variable.

If it varies by other things then how do you expect it to generate only one function?

That's because they're not.

I've been too busy this semester to do anything substantial in it
I guess I could pick up AoC and post some here

its not. that's the point of templates. It emits a completely different assembly depending on the parameters of the template argument. I get this part already. I am using a compile-time "Traits" objects to control the specific behaviors of the generated assembly. This is something the standard library does even. This is going on a completely far tangent of the original question at hand.

You're not passing it a traits object, you're passing it a traits type. You don't get multiple instances of the same type with templates. That's what constexpr and regular functions are for

Could swear I was on stack overflow for a second.

So even if you had something like this

struct Traits1
static const constexpr size_t bits = 8;
}

struct Traits2
static const constexpr size_t bits = 8;
}

You can't bring them together with templates.
You want to seperate the bits out of the template and make it a regular parameter to the function, if you only want it generating once

You clearly don't get what he's doing.

>There has to be a way to set an "auto" function pointer to either `iterate` or `iterate16` at compile-time based on this one variable.
This is probably the way if you can write a templated "pick" method that selects between the two.

Just stop. I never said I wanted it generated once and Im not bringing it together like you are.
Yes

>How do i make my function call
>in_data->utils->iterate(...) if Traits::Bits is 8 and in_data->utils->iterate16(...) if Traits:Bits is 16 without having two copies of Blah() just for this one specialization?

You're both idiots.

Without having two copies of Blah() as in not having to literally just copy-paste code and make a specialization of the entire fucking function when there is only one damn difference between them.

I know clearly that the compiler will emit the function in different ways for different arguments but this traits object/type is what statically configures the function at compile-time.

You're useless.

I'm just going to look into this:

Oh, so you meant only WRITING it out once.

Well there's this thing called an if statement

>Well there's this thing called an if statement
clearly didnt read
>There is no compile-time conditional function either so if I was to make a big rack of if-ifelse it will still have to evaluate the cases that do not match.

Yes, you will have to do a big rack of if-elses.
Or switch.

There.
Is.
No.
Compile.
Time.
Conditional.
That.
Encapsulates.
Logic.

Static-ifs were even specifically rejected.

baptiste-wicht.com/posts/2015/07/simulate-static_if-with-c11c14.html

stackoverflow.com/questions/13799420/why-there-is-no-static-if-in-c11


Just stop now.

Fixing bugs and cleaning up spaghetti code boss keeps introducing to our C++ codebase when he doesn't know C++

constexpr-if is in C++17

But I wasn't talking about constexpr-if, I meant regular if.

As in

if (traits::bits == 8) ...
else if (traits::bits == 16) ...

template void f()
{
if (T::Foo == Bar)
{
// stuff that relies on Foo being BAR
}
else
{
// stuff that doesnt rely on Foo being BAR
}
}

this is not valid code as the code that does not rely on Foo Being BAR will still be evaluated at compile-time

T::Bits is a size_t

GIVE ME SOMETHING INTERMEDIATE TO PROGRAM

Why haven't you killed yourself yet

C++ Compiler

>There is no compile-time conditional function either so if I was to make a big rack of if-ifelse it will still have to evaluate the cases that do not match.
>if (traits::bits == 8) ...
>else if (traits::bits == 16) ...

Modern optimizing compilers can perform something known as dead code elimination. If it sees something like if (0), it will never even check that section of code at runtime, and code is not generated for that section. Similarly, if (1) will not check something, it will just generate that code block.

#include
using namespace std;

class A {
public:
static constexpr const size_t Bits = 8;
};
class B {
public:
static constexpr const size_t Bits = 16;
};

template
size_t f() {
if (T::Bits == 8) return 0;
return 1;
}

int main() {
std :: cout

>intermediate

This is under the assumption that you are only keeping the template so that you can parametrise it in a later position.
Effectively it's like an implicit, static parameter.

Can I realloc() an allocated block of memory if I don't have a pointer pointing to the beginning of that block?

I'd like to write a function that inserts n characters into a location pointed to by *dest, but i'll need to grow the array first and I'm not sure if it's possible without a pointer to the original memory block.

No.

>Can I realloc() an allocated block of memory if I don't have a pointer pointing to the beginning of that block?
No. It must point exactly to the same place that malloc/whatever returns.

don't use c

I read your post in an indian accent
just letting you know

The realloc function should only be used on a pointer returned by a previous call to malloc or realloc, or else undefined behavior will result. If you have a function where you are copying data, with a source and destination pointer, along with a length parameter, you should not have that function do memory allocation.

I don't get why some retards associate C with pajeets. It makes absolutely no sense.
C is considered a "hard" language by most people, and the pajeet meme is about terrible Indian programmers who can't do anything but shit out terrible Java/C# code.

where did you get the impression of anyone associating C with pajeets? it's about the poster himself who is a pajeet

How can I shorten the following Python 3 code?
print('S'+p if d

>where did you get the impression of anyone associating C with pajeets?
I have seen it many times in the past.

so? why do you think your "experiences" are relevant here if you can't even decode a simple post?

>Python ternary statements

>Python
fixed that for you

return vector[0].map[i]

vector is a const vector, map is a map owned by each object in the vector, and i is an int that gets passed in. This should return the ith value in the map, right? It's giving me some garbage error that doesn't make any sense.
If it matters, the map is: map

What's the error?

>error: passing 'const std::map' as 'this' argument of 'std::map::mapped_type& std::map::operator[](const key_type&) [with _Key = int; _Tp = SDL_Point; _Compare = std::less; _Alloc = std::allocator; std::map::mapped_type = SDL_Point; std::map::key_type = int]' discards qualifiers [-fpermissive]|

I think it might have something to do with the fact that the vector is const.

>discards qualifiers
that'll be it

is your member function const qualified?

That's what you get for using C++.

hahaha disregard that i suck cocks

I just had to change it from map[i] to map.at(i)

map[i] can be const too

Apparently the Magi are programmed with Win32. No wonder Iruel was able to penetrate them.

>it's entirely declarations
I didn't know C was a declarative language

They make a WNDCLASS at least.

just ended up doing this thanks I'll optimize it later.

typedef std::conditional<
PixTraits::Bits == 8,
decltype(Params->in_data->utils->iterate),
decltype(Paramsin_data->utils->iterate16)
>::type IterateProc;

IterateProc* Iterater;

if( PixTraits::Bits == 8 )
{
Iterater = reinterpret_cast(&Params->in_data->utils->iterate);
}
else if( PixTraits::Bits == 16 )
{
Iterater = reinterpret_cast(&Params->in_data->utils->iterate16);
}

(*Iterater)(
...
)

CAN I WRITE AN OPERATING SYSTEM IN HASKELL

No.

What's the best git cheat sheet out there? I want to print one out.

I have these 2.

[1/2]

How does this make you feel, ruby-senpai?
char *strins(char **loc, size_t pos, const char *src, size_t n)
{
char *dest = *loc; /* realloc */
dest = (char *) realloc(dest, strlen(dest) + n + 1);
memmove(dest + pos + n, dest + pos, strlen(dest + pos) + 1);
memcpy(dest + pos, src, n);
*loc = dest;
return dest;
}

[2/2]

services.github.com/on-demand/downloads/github-git-cheat-sheet.pdf

What's the cringiest programming language? Is it LOLCODE?

it's GC so no

javascript

lolcode, shakespeare programming language, trumpscript, python, brainfuck, oog, they're all quite cringy

kickstarter.com/projects/520965826/basil-the-comprehensive-programming-language

Whatever Urbit uses.

>We should note that in Nock and Hoon, 0 (pronounced "yes") is true, and 1 ("no") is false. Why? It's fresh, it's different, it's new. And it's annoying. And it keeps you on your toes. And it's also just intuitively right.

I'm working on ripping some textures from SH3

I can rip the textures, but the 8bpp ones are displaying wrong for some reason.

Pic related, it's just the raw pixel data. 24bpp textures display 100% correct, but 8bpp and it's just vomit.

Does anyone have any idea??

import std.stdio;
import std.conv;
import std.string;

bool and(bool[] valids)
{
if(valids.length == 1)
{
return valids[0];
}

return valids[0] && and(valids[1..$]);
}

bool checkSides(int[3] sides)
{
bool[3] valids;
for(int i = 0; i < 3; ++i)
{
if(sides[i] + sides[(i + 1) % 3] > sides[(i + 2) % 3])
{
valids[i] = true;
}
}

return and(valids);
}

void main(string[] args)
{
File input = File("day3input.txt", "r");
int total;

while(!input.eof())
{
string line = input.readln().chomp();
if(line != "")
{
line = line.stripLeft().squeeze(" ");
int[3] sides = line.split().to!(int[3]);
if(checkSides(sides))
{
++total;
}
}
}
writeln(total);
}


AoC Day 3 Part 1 (I know I'm helluva far behind)