/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Old thread: Introduction to Haskell: youtube.com/watch?v=3U3lV5VPmOU

Attached: budgerigars.jpg (1280x720, 126K)

Other urls found in this thread:

leetcode.com/problems/sum-of-two-integers/
gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
twitter.com/NSFWRedditImage

I have computer organization and design MIPS and RISC-V edition. Which arch I should learn first or there is no difference?

Stress testing a parallel entity component system I'm working, with a bullet hell game. Can handle ~15k bullets on-screen @ 60 fps, with collision detection + rendering. Probably good enough.

Attached: blow.png (800x450, 117K)

learn a bit and then whenever you think "I wonder if I could do this in Haskell", try
Soon, Haskell will have (full) dependent types, and then Idris is just Haskell with a shit compiler and no libraries
PatternSynonyms are polymorphic 0-cost data inspectors/constructors
DerivingVia extends the type class deriving mechanism to be so sick you never have to manually write an instance again

Ruby!

RISC-V might be more relevant in the future, but from the standpoint of studying architecture there's no difference and you're more likely to find help for MIPS.

Idris will be deprecated by Blodwen anyway.

Adding buffering to a video player.

*pattern synonyms are pattern synonyms

>Ruby!
no

>soon haskell will have full dependent types
>soon c++ will have modules, concepts, and be the small neat language claimed to exist inside the current mess
>soon d won't need gc for non-trivial uses and won't be dead

pretty much this, haskell will be playing catchup yet again

if anyone knows fortran 90 or what to call the following problem please help
do a = 1, nion
do b = a, nion
dist = sqrt((pos(3,b) - pos(3,a))**2 + (pos(2,b) - pos(2,a))**2 + (pos(1,b) - pos(1,a))**2)
print*, dist
end do

so the code print's 0.00 many times since b never initiates to a according to gdb. what do you call this bug? if i knew I could fix it

dependent types aren't worth 30 years of ecosystem and compiler development

>tfw transcended if statements
#include

int factorial(int i){
int base(void){
return 1;
}
int recur(void){
return i * factorial(i -1);
}

int (*cases[2])(void) = { recur, base};

return cases[i == 0]();
}

int main(void){
printf("%d\n", factorial(5));
return 0;
}

How would I go about creating a GPA to Grade % calculator??

I could use switch statement like
0 = 60
1 = 70
2 = 80
3 = 90
4 = 100

BUT I'm supposed to be able to calculate the percentages in between like
3.75 = 97.5

i don't even think throwing away 30 years of mistakes and bad libraries is a bad thing

it's just a linear function ya goof

grade = gpa * 10 + 60

uhhhhh is this a troll? Just GPA/4 if you have a 4.0 scale.

is it faster than using if-statements?

im bad at math

It's a linear function the fuck are programmers to bad at basic math? How can you look at that and not instantly see Grade = 60+10*gpa fits?

when i were a wee bairn mathematics were a requirement for reading computer science

>went to sleep at 9pm because I was tired as shit
>woke up at 2am
read me The C Programming Language to sleep onii-chan

Attached: serveimage.png (300x168, 7K)

am I going to make it? how fucked is this disgusting shit

Attached: ggg.jpg (2367x1263, 343K)

holy shit it works

Attached: out.png (1000x1000, 218K)

nice serpinski yo

that vertical line in your editor is there for a reason, user

why would you not use pastebin or equivalent

most important thing to do to improve that is to reduce the duplication for first unit, second unit, etc.

Could you clean this up with small loops?

This is actually pretty similar to @. and ` in J:
fact =: 1:`(* $:@

If b = a then their distance is 0, I don't get the problem

the problem is why b isn't 1 when a = 1. when the loop starts b always starts at 0 and then goes to a

How do people even read this shit

Do you ever get to a point where you can actualy read J like a normal language without having to look up one of the 600 symbols, or spend 10 minutes figuring out dimensions?

setup your editor holy shit

What's the preferred max line length? I know a lot of people use 80 for some reason, but I prefer 120.

Why doesn't C have lambdas?

as long as my screen

Depends on the language. C-like langs, I go with 80.
With Haskell I stick below 60.

Needless syntactical sugar, you can do the exact same with normal methods and pointers.

People who don't know programming would say the same about even 'normal' languages like c.
Yes, although it takes longer than learning the syntax for a normal language.

thats as much as a non-parallel system, congrats on falling for the meme

It's a jump table. Of course it's slower for only two branches.

Why the fuck are you using GNU extensions you fucking idiot?

How the fuck do you use descriptive names/self documenting code when you limit it to 60/80? A good name of something non trivial would be around 15 chars, if you need to type it with a non trivial type name that can be another 25 chars, calling a nib trivial method with one parameter, another 30, that's already 60 chars with 0 indentation and all you did was call 1 method and store the result. Is this 80 char max meme for people who write shit like int bg = DfDg.Up(temp)?

>Needless syntactical sugar
just use assembly then

Do not reply to homework posts.

Because I only care about platforms targeted by GCC

Unless he's learning programming in grade school that's not homework.

So do I but you're still a complete fucking idiot for using GNU extensions.

long type names are an OOP thing

You underestimate the stupidity of first year compsci students.

>assembly
t. Brainlet who can't into binary

binary isn't a language

Then why use 80 in C?

Ctards have no right to complain about needless syntactic sugar, as their own language is full of it.

I call things by their function and use modules/namespaces. One rule I have is to never name something 'object/manager/service/factory/component'.
Those are usually a sign of mental laziness.

I want to make a chatting application with Django and Firebase. Should I have Django use Firebase's database or separate databases? In other words should I store account information on Django or Firebase?

because it's tradition and they're idiots I guess?

I'm in fourth semester and half my assignments are shit like "calculate the area of a circle"

now with color

Attached: out.png (1000x1000, 205K)

you're going to have to perform some impressive mental gymnastics to avoid using even the world 'object' in object names

newfags cant serpinski

>Those are usually a sign of mental laziness.
Except for when they aren't, of course.
So I'm not sure why you made that a rule, it's almost as if you're the actual retarded one or something.
Oh wait, you are.

You have a method that configs and returns a Security Token, what do you call the method that's under 15 chars?

loli_manko()

here's mine

Attached: ss.png (1538x1015, 165K)

How do you solve this for negative numbers? leetcode.com/problems/sum-of-two-integers/ Is it really an "easy" question?

class Solution {
public:
int getSum(int a, int b) {
if (b == 0) return a;
return getSum(a^b, (a&b)

SecTok, the fact that it's configuring it is obvious, and the chance of anything else starting with Sec----- Tok----- is almost none.

shit it's so equilateral and the green is actually the correct brightness
might as well kms

Not really. Does BoxObject really give you much more information than just Box? People are just afraid of giving simple things simple names.

Why 15 chars?
SecurityToken get(Config) ?

Are you referencing some specific benchmark(s)? There is some extra stuff going on in mine and it's not just simple circular collision geometry. There is still a lot to optimize too.

15 was just a nice number to show how you can't code in 60/80, since you can have 1 type name, 1 veriable name, 1 method name, and one parameter name and already be over 60 chars

What the hell is this site

How the fuck am I supposed to even know that?

Like I couldn't even grasp that if I tried. And I passed with a 100

They put me from algebra straight into C++. No other math courses. No trig. No calc. Nothing.

>Calculate the sum of two integersaandb, but you arenot allowedto use the operator+and-.
Use a for loop?

What about in C where you don't have modules/namespaces? inb4 don't use C

I let it wrap. The intent of the 80 char limit I lint to is to discourage lines that are complex, calling a method on an object with one argument and descriptive names is easy to understand. Similarly, returning a long string for an error with multiple variables templated in, it's long but understandable.

Now some mess with a ton of shorter identifiers, multiple calls, multiple arguments, and a ternary or two ... if that hits 80 chars it's time to break it up.

I don't see how that's useful unless you're thinking of using --/++ which is using the + and - operators and not allowed.

Operator++ is not the same as operator+

>The intent of the 80 char limit [...]

Actually it exists because IBM punch cards were 80 slots wide. Fuck the 80 column limit, do whatever you want. Unless your job requires something specific.

I'm at column 33 with this:
// method
security_token auth(config);
// use
auto token = auth(config);

perhaps I'm missing something?

looking for profitable forex trading strategies using python and some CSV data

I'd argue it's worth it to scratch my head and get out the thesaurus to avoid having something as generic as a 'BoxObject' in my codebase. Code isn't mainly for machines to read, it's for people to read (including yourself, later). The right name for a key type makes the whole thing readable, the wrong thing makes it dense.

It's a different case if 'object' has some specific meaning in your domain, like a renderable thing in a 3D engine.

if(!high) sell;

it's literally just a shorter way of doing a = a+1
the question is obviously intended for using bitwise operators

Thinking about writing a GBA emulator

That's with space partitioning into a quadtree or something? Do they collide with themselves, walls, or only the player?

Because you either have to allocate heap memory, or do something like: gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
Theses use stack trampolines that dynamically put machine code on the stack, which while cool, is bad for security.

Inline assembly
int getSum(int a, int b) {
int c;
asm("movl %1,%0;"
"addl %2,%0;"
: "=r"(c)
: "r"(a), "r"(b));
return c;
}

If null pointers cause such an issue because they can be of any type, why don't they define languages like this
double* p = null;
//p is a double type null
int* q = null
//q is an int type null
long* r =supernull
//behaves like your regular null

Attached: 1515521069535.png (207x243, 14K)

Retard.
int sum(int a, int b) {
asm("addl %0, %1" : "+rm" (a) : "ri" (b));
return a;
}

Stop writing inefficient code.

new languages have dropped null, thank god.

post the code?

You can log(exp(a) * exp(b)), but it'll fail on big numbers.

Also, you LITERALLY have a working solution. It's just that you have to cast them to unsigned because their runtime is bitchy. That's just how 2's complement works. You don't have to have a different calculation scheme for signed integers - it just werks.

class Solution {
public:
int getSum2(unsigned int a, unsigned int b) {
if (b == 0) return a;
return getSum2(a^b, (a&b)

wait a minute, these birds aren't anime!

double * p = 0;

this should become /dpt/ meme

recc me libs to draw with so i can serpinski. i've never done it before.

a++ is actually faster than a=a+1 as there is a dedicated assembly command that increments or decrements a value by one

Looks like we have a time traveler from 1972 in this thread.