/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous Thread:

Other urls found in this thread:

cors-anywhere.herokuapp.com/https://a.4cdn.org/g/catalog.json').then(a=>{a.json().then(b=>{b.forEach(c=>{c.threads.filter(d=>d.sub).forEach(d=>{d.sub.includes('/dpt/')&&(window.location=`https://boards.Sup
github.com/godotengine/godot/issues/16020
the-eye.eu/public/Books/IT Various/Effective Java, 2nd Edition.pdf
nim-lang.org/docs/tut1.html#advanced-types-arrays
wiki.c2.com/?SufficientlySmartCompiler
llvm.org/doxygen/LoopIdiomRecognize_8cpp_source.html#l01161
twitter.com/SFWRedditVideos

Op is a nigger

Neat little /dpt/ bookmarklet you can save in your browser which will take you to the first /dpt/ found in the catalog.

javascript:(()=>{fetch('cors-anywhere.herokuapp.com/https://a.4cdn.org/g/catalog.json').then(a=>{a.json().then(b=>{b.forEach(c=>{c.threads.filter(d=>d.sub).forEach(d=>{d.sub.includes('/dpt/')&&(window.location=`https://boards.Sup Forums.org/g/thread/${d.no}`)})})})})})();

You have 10 seconds to name the best Linux distribution for elite programmers.

What are some good books about advanced stuff in java?

It turned out I know shit.

>/dpt/ actually doing something useful

Doesn't werk moit

swedish user?

Arch Linux

New thread:

fix'd, works only on Sup Forums tho
javascript:(async _=>{const pages=await(await fetch("p.threads.forEach" target="_blank">p.threads.forEach(({sub,no})=>sub&&sub.includes("dpt")&&(window.location=`https://boards.Sup" class="external" rel="nofollow" target="_blank">a.4cdn.org/g/catalog.json")).json();pages.forEach(p=>p.threads.forEach(({sub,no})=>sub&&sub.includes("dpt")&&(window.location=`https://boards.Sup Forums.org/g/thread/${no}`)))})()

fix'd, works on any site now.
javascript:(async _=>{const pages=await(await fetch("cors.now.sh/p.threads.forEach" target="_blank">p.threads.forEach(({sub,no})=>sub&&sub.includes("dpt")&&(window.location=`https://boards.Sup" class="external" rel="nofollow" target="_blank">a.4cdn.org/g/catalog.json")).json();pages.forEach(p=>p.threads.forEach(({sub,no})=>sub&&sub.includes("dpt")&&(window.location=`https://boards.Sup Forums.org/g/thread/${no}`)))})()

Which one should I focus on, Sup Forums?
I'm undecided between C#, C, C++, Java, Python, Julia, Coq, ADS2, ML, Haskell, OCaml, Idris, Crystal, Nim, Rust and Pony.
I spent the last 2 years trying to figure out which one was the best, and because of that I didn't actually have time to actually sit and learn one.

Learning C++:

Given two positive integers, a and b (a

It's not "better" per se but this would also be possible

const char* words[] = {
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine"
};

for (int i = a; i 0 && i < 10) {
std::cout

NixOS as you have consistent envs

Threadly reminder that leaking memory and crashing is a valid side-effect because it's not a result. Rust DOES NOT compile programs that produce unintended output and other invalid results, unlike C++.

Been posted already years ago, and oddly enough last thread's fizzbuzz reminder me of it.

Unless you are a sperg that uses unsafe just for the sake of it

That's right. If you don't use unsafe like a C++ retard, your program simply won't compile if it produces invalid results like incorrect output thanks to Rust's revolutionary type system. If it compiles, it works.

Trying to learn C.. I wanted to convert an int to binary and output it. But this just outputs blank and I can't figure out why.


char convertToBinary(int number) {
int n, c, k;
char binStr[32];

for (c = 31; c >= 0; c--) {
k = n >> c;

if (k & 1)
binStr[c] = "1";
else
binStr[c] = "0";
}
return binStr;
}

>fetch

This is new to me... I haven't really looked at JS for a few years. I want to get back into it and going to start with React.js and maybe the MERN stack or Meteor framework.

I bet you are rust shitposter.

Nope... Never used rust.

My main is just printing 0 every time...

#include

char convertToBinary(int);

int main(void) {
printf("Binary Conversion of 23: %c\n", convertToBinary(23));
return 0;
}

char convertToBinary(int number) {
int n, c, k;
int x = 0;
char binStr[32];

for (c = 31; c >= 0; c--) {
k = n >> c;

if (k & 1)
binStr[x++] = '1';
else
binStr[x++] = '0';
}
return *binStr;
}

What the hell is 1d incremental smoothing and how do you do it on a 2d array?

You aren't terminating your string. And you're returning one character from the string.

How do you run this?

Its a bookmarklet.

Create new bookmark, name it whatever and out that javascript snippet as the address.

put it in the address bar

doesn't work in Firefox if i just simply put in the address bar and click enter.

saving it as bookmark and clicking the link i have pic related

>someone bumps old thread

Okay then, so I added the terminating character then I realized what you meant by returning 1 character. I made some changes but still having issues.

>return *binStr;
Segmentation fault
>return binStr;
(null)

#include

char* convertToBinary(int);

int main(void) {
printf("Binary Conversion of 23: %s\n", convertToBinary(23));
return 0;
}

char* convertToBinary(int number) {
int n, c, k;
int x = 0;
char binStr[33];

for (c = 31; c >= 0; c--) {
k = n >> c;

if (k & 1)
binStr[x++] = '1';
else
binStr[x++] = '0';
}
binStr[33] ='\0';
return *binStr;
}

Is char (0) a different character to '/0'?

Remember indices start from 0.

So I now have it at a point where the binStr printed before the return is accurate, but the return just returns null all of the time?

Your return is still returning just a character. Unless you've changed that line since then.

binStr[33] = {0};
for (int c = 31; c; c--) {
binStr[c] = k&1? '1' : '0';
k = k >> 1;
}

That's a really odd way of doing this but this should work.

#include

char *convertToBinary(int);

int main(void)
{
printf("Binary Conversion of 23: %s\n", convertToBinary(23));
return 0;
}

char *convertToBinary(int number)
{
int n, c, k;
int x = 0;
static char binStr[32];

for (c = 31; c >= 0; c--) {
k = n >> c;

if (k & 1)
binStr[x++] = '1';
else
binStr[x++] = '0';
}
binStr[32]='\0';
return binStr;
}

>If it compiles, it works.
Until you learn why this is false, you will be a shit programmer only suitable for pajeet-tier work.

>k&1? '1' : '0'
(k&1)+0x30

>t. too dumb for rust
probably a c++ "programmer"

They're identical. Whether you can have one inside the middle of a string at all... well, that depends on the language and/or the string library.

Hey guys

why not rewrite the Godot game engine in Haskell?

github.com/godotengine/godot/issues/16020

Rust isn't magic, even ATS, Idris, Liquid Haskell/Dependent Haskell (future) requires tests as type systems can't catch everything.

Oh and each of these catch more than rust can ever hope to. "It compiles so it's correct" is bullshit unless you enjoy writing full proofs in your type system. Even then it's not 100% fool proof.

So I was putting the * directly after 'char' in the procedure declarations, is this just style preference between peers?

Using a static keyword increases the variable or function scope to the file it is in right? Why do that, can you not chain procedures in order to pass through variables?

Once I added static and returned binStr instead of all the other things I was trying, it worked.

I am curious about the odd comment, is what I am doing a poor implementation of a solution?

for (int c = 31; c; c--, k>>=1) {
*(binStr+c)=k&1+0x30;
k = k >> 1;
}

Also thank you;

gcc main.c -o ./bin/test && ./bin/test
Binary Conversion of 3: 00000000000000000000000000000011
Binary Conversion of 23: 00000000000000000000000000010111
Binary Conversion of 8885888: 00000000100001111001011010000000

>probably a c++ "programmer"
Says the incompetent who hasn't learned yet what the limits of type theory are. General safety theorems simply can't show the correctness of all programs, not at be tractable at all. For example, Rust doesn't prove that you've implemented your floating point arithmetic correctly. There's a whole world of correctness properties beyond what you can prove with Rust's type system, and necessarily so in order for the compiler to be able to compile things in a sane amount of time.
Of course, you're about to claim that this is because correctness doesn't mean getting the right answer, but that'd be the sort of answer that marks you as a stupid faggot who should stick to coding login pages.

It doesn't matter on my compiler. Variables are local and discarded and he returned a pointer to something that will be discarded.

How the heck it works if function is not even using the value it received?

>is this just style preference
yeah, but consider that in
char* a,b; declaration, b is char, not a pointer. So it kinda makes more sense to separate * from char in here to underline that these two variables do not share the same type, and the pointer symbol refers to only one.

>t. pluslet who doesn't understand class theory

Oh I removed 'n' in favour of using 'number' - I realized when I put the print statements back in in place of adding 1 or 0 to the array and it was just outputting 0's.

I originally did it all in main and used scanf(&n) but then moved it into a function and forgot to refactor the way the input worked trying to get it to return the char array.

Why don't you actually reply to the man with something other than a shitty meme you brainlet.

How many layers of nesting deep do you go before you start to feel uncomfortable/your code begins to get unreadable?

If it is any more than about 4 I will start seperating parts into functions for readability.

Because there's no point talking to undereducated pluslets. You're simply in denial and don't understand the borrow checker.

c++ is the greatest language of all time

You are a moron. If you can't see why you'd use Horner's rule to evaluate a polynomial rather than the direct approach, you won't even comprehend why you might be thought of as a moron. (Pro-tip: Rust will find both approaches to be type-correct. Because they are, but only one is actually correct.)

Who likes programming? Hahahaha

>when pluslets try to make an argument
Are you worried about your job security, brainlet? You know Rust is making your language obsolete, right?

Good rule of thumb that. Occasionally I'll go deeper if it lets me split at a very good place. Refactoring isn't just about chopping away at code with an ax.

the-eye.eu/public/Books/IT Various/Effective Java, 2nd Edition.pdf
i don't even know java btw

I need to do some drawing in Windows. Is Windows GDI really as obsolete as Microsoft claims and should I use Direct2D?

Also how is doing 2D stuff with OpenGL? I might as well waste my time on something that supports more than one platform.

the generated code is quite good, for example

int count(unsigned int x) {
int v = 0;
while(x != 0) {
x &= x - 1;
v++;
}
return v;
}


compiles to

(func $_Z5countj (; 1 ;) (param $0 i32) (result i32)
(i32.popcnt
(get_local $0)
)
)


which is then compiled by firefox to

wasm-function[1]:
sub rsp, 8
popcnt eax, edi
nop
add rsp, 8
ret


webassembly is sand boxed, everything is tracable, you dumb fuck.

I enjoy programming and learning new things, I just wish there was a good newbie course which gave you projects to do with requirements and didn't completely spoon feed, but nudged and guided you.

Should I continue with C or start picking up Go... Or both?

>You know Rust is making your language obsolete, right?
It doesn't even run on my hardware, brainlet. But hey, keep on making yourself look like a pajeet. Your code is going to be unsafe and will get people killed if you ever try to use it for control systems. All because you have no idea about program correctness.

Why not try also praying to the Omnissiah for the machine spirits to make your code correct? That's about as likely to make a difference as relying on the Rust compiler to catch everything for you. You're such a moron and you think that asserting that I just don't get the borrow checker (I've written my own optimizing compiler; borrow checking is meh) when I'm asserting that there's whole levels of critical program correctness that you're ignoring. All borrow checking does is solve some types of memory management problems by enforcing a particular limited coding style. It doesn't prove that you've still got numerical significance in your answer. It doesn't prove that you've selected the correct item from a collection. It doesn't even prove that your algorithms terminate...

I recommend SDL for it's cross platform and easy primitives for 2D graphics
2D with OpenGL is difficult if you're not already familiar with OpenGL

>both
This. And more too. Why learn only one when you can learn lots of them? Make sure you include functional and logic programming in that, for the different perspectives on programming they give.

>Your code is going to be unsafe and will get people killed if you ever try to use it for control systems. All because you have no idea about program correctness.
this is what c++ programmers actually believe lol. i can smell the insecurity... you know rust is much better and safer for embedded platforms, right? or maybe you're even a cnile

>you know rust is much better and safer for embedded platforms
I could explain why you're wrong, but it amuses me to just say "lol nope, brainlet". (Also, C++ isn't very good for lots of embedded platforms either; the standard library is really bloated.)

But tell me, how suitable is it for cryptocurrencies? Have you got the approval of John McAfee for coding them in Rust yet?

>I've written my own optimizing compiler; borrow checking is meh)
I've written several optimizing compilers for real, and you don't know what you're talking about. Stick to C++. Rust is above your level.

Both GDI and Direct2D are pretty mediocre and outdated APIs
But doing all they do in raw OpenGL takes weeks/months of writing your own drawing library
Personally I'm using my own 2D drawing library which works with raw pixel buffers and only uses GDI to present

>Stick to C++. Rust is above your level.

>in char* a,b; declaration, b is char, not a pointer
cniles will actually defend this

>cniles will actually defend this
Nah. It's horrible, but we're stuck with it.

If the first element in an array is index 0, what index is the zeroeth element?

sane, reasonable replies
in my dpt?

yeah, backward compatibility: many benefits, but oh such costs too

0 index is shit, but we're stuck with it because too many people are stockholmed to it.
And no i don't even use 1 index langs, but you know in your heart it's more logical.

-1, obviously
just ask python

Rust's borrow checker is irritating. Would rather have full linear types than that garbage.

>Being happy about your compiler literally cucking development
Enjoy not being able to leverage stdout piping because rust doesn't want you to.

arbitrary index range master race
nim-lang.org/docs/tut1.html#advanced-types-arrays

type
Direction = enum
north, east, south, west
BlinkLights = enum
off, on, slowBlink, mediumBlink, fastBlink
LevelSetting = array[north..west, BlinkLights]
var
level: LevelSetting
level[north] = on
level[south] = slowBlink
level[east] = fastBlink

>Because I don't have an educated response, and you've found me out
ftfy

ptr+idx is why and not due to many riding it as if it's the latest and greatest.

how I wish for a
wiki.c2.com/?SufficientlySmartCompiler
and two separate types: 0idx, 1idx
with no implicit conversions
that can be optimized (for compile-time calculable) from 1idx at source level to 0idx at binary level at no extra runtime cost
and with an extra addition for non-compile-time-known index bases
might as well wish for a pony in the meantime

That's a contrived example imo, this is only due to the fact there is a specific heuristic which checks for this loop in llvm. This isn't really showing anything other than web assembly has a popcount instruction.

llvm.org/doxygen/LoopIdiomRecognize_8cpp_source.html#l01161

wrote a python program that outlines images through finding derivatives

Option Base 1

Scheme > CL > Clojure > Racket

>it's more logical
No it isn't. I can represent 10 indexes with a single digit vs 2. 0 Indexing inherently makes more sense.

Now implement it in GLSL.

1-based indexing falls apart when you consider negative indices.

I'm a fucking mathematician and I know nothing about computer assisted theorem proving. I do like lisp and enjoyed building up the language from lambda that one time though.

Which language should I choose to delve into the peano proving autism?

There is no zeroth element. Why would you need to index something that doesn't exist?

Expand it so that it returns the timestamp of appearances, as determined by outline, of evil uncles in his videos.

>you consider negative indices.
which should not be part of a language in the first place.

You didn't even post an example of your code in action though user.

>I can represent 10 indexes with a single digit
which literally does not matter.