/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

godbolt.org/g/QqSVPj
godbolt.org/g/sCsYNM
isocpp.org/wiki/faq/cpp14-language#extended-constexpr
youtube.com/watch?v=hErD6WGqPlA
godbolt.org/g/zRAQq5
cplusplus.com/doc/tutorial/
paste.debian.net/1009763/
github.com/AltraMayor/XIA-for-Linux/blob/xia/README
twitter.com/NSFWRedditVideo

godbolt.org/g/QqSVPj
>2018
>GCC is still unable to do such a simple optimization like turning a long chain of if-else statements into a jump table

Meanwhile in Clang: godbolt.org/g/sCsYNM

just finished up the third milestone on a contract. had to integrate a third party library into the system to perform a specialised calculation on health data. third party component is supplied as several windows dll files. ended up writing some c++ to load the dlls and wrap a particular function in some serialisation, piping it through stdin/stdout. cross-compiled for windows, running with wine on linux, using a pool of processes that kill themselves every 100 operations to avoid a leak in the vendor code.
fucking happy this module is finished, and i hope i never have to look at it again.

>2018
>using jump tables unironically

Isn't a switch case is for?

So if you want to do it that way it doesn't assume anything and lets you?

Got something against performance?

You can't dynamically generate a switch at compile time with templates, while you can generate a chain of if-else statements at compile with templates.
>So if you want to do it that way it doesn't assume anything and lets you?
That's an incorrect attitude for a compiler to have.
If something is equivalent and it is faster, then it should do it.
If you REALLY don't want it to generate jump tables, then tell GCC explicitly by passing it a flag or using an attribute.

>2018
>muh performance

>Look at me I'm a dumb script kiddie.

Why does constexpr force recursive code? Just look at these ugly hacks:

template
constexpr Int isqrt_pt2(Int n, Int res, Int bit){
return (bit) ?
(n >= (res + bit)) ?
isqrt_pt2(n-(res + bit), (res) + bit, bit)
: isqrt_pt2(n, res, bit)
: res;
}
template
constexpr Int isqrt(Int n, Int res=0, Int bit=Int{1}

That's only in C++11
C++14 constexpr functions are MUCH less restricted.

>unironic performance kiddie calling anyone else a script kiddie

template metaprogramming is disgusting

>Hating performance this much
Do you stick for (volatile u64 i = 0; i < 0xffffffffffffffff; i++); in every function in your programs or something?
That's of course making the assumption that you actually program.

If you're referring to , it's only that disgusting in C++11.
C++14 fixed it.

What changed in C++14?

constexpr functions aren't limited to a single return statement anymore.
You can declare variables, use loops, etc.
isocpp.org/wiki/faq/cpp14-language#extended-constexpr

That's constexpr, not template metaprogramming.

Constexpr in C++14 and C++17 is pretty nice though. I hold that it's one of the features worth using sepples for.

Teaching myself Python after my failed attempt to teach myself C. A lot of the learning websites are alittle garbage so I gotta apply myself.

--Fizz buzz program
fb :: Int -> String
fb x
| (x `mod` 15 == 0) = "FizzBuzz"
| (x `mod` 5 == 0) = "Fizz"
| (x `mod` 3 == 0) = "Buzz"
| otherwise = show x

main = mapM_ print $ map fb [1..100]

Hope I didn't fuck up the tags. What do you lads think?

Just realised that I got fizz and buzz around the wrong way. Oops.

I don't see how you fail at something memory based unless you have a faulty memory.

pretty good
you can also do
mapM_ (print . fb) [1..100]

What lang is that? Looks simple.

Training a deepfake network...on my laptop's CPU. How futile is this Sup Forums?

Thanks, user.

Haskell

I wanted to learn it long time ago, but got job in something different, now it would be better if I didn't got a job.

>now it would be better if I didn't got a job
Why?

More like
>2018
>Can't switch over strings
HAHAHAHAHAHAHAHAHAHAHAHAHAAH C++ cucks defend this

>The first thing cs majors try is double exponential recursion.

Is this a popular strawman or are cs majors really so terrible they can't see any better way of doing it without being told so?

It's just the straight forward transformation of the recursive definition into code.

Makes sense that most people would do that first.

I haven't written code for a few years now. I have fair knowledge of C++ and Java, but it's muddled and scattered.
What book and language would people suggest to learn programming from this weird and fragmented place I'm in?

that seems like a pretty bad way to do the Fibonacci sequence, you're going to check those if statements everytime aren't you?

That's not Vim he's using, is it?

> INSERT
> --INSERT--

why is he holding that rope

Fibonacci is pretty much the go-to problem for introducing recursion and dynamic programming. When they see code like this in class, the point isn't to immediately jump to the best solution, the point is to learn a new concept that they haven't seen yet.

>runtime fibonacci
what a pleb

Playing around with python and tensorflow. Any ideas for a project that could keep me busy for at least a couple of weeks? (aka not something completely trivial)

You are retarded.

>C++98 TMP
Please, never again.
constexpr
unsigned fib(unsigned x)
{
if (x

>youtube.com/watch?v=hErD6WGqPlA
Nobody would write a recursive fib function just like nobody would find a minimum spanning trees by comparing all 2^E edge selections. They would carry 2 temp variables in a loop and calculate bottom up.

And nobody would implement memorization by template specialization rather than appending to a std::vector when needed.

And using floating point to get a linear algorithms is downright disgusting when the 2x2 matrix and repeated squaring approach is so much clearer and trivially generalizes to bignum classes.

Then again, it's a hipster that codes in vim so of course he will fake knowing what he's doing...

enlighten me
I might have overflown a bit, but still

You are retarded as well.

What is recursion?

Not what you have there. You have iteration.

When I took the data structures and algorithms class, we were also told to implement fibonacci recursively and then properly and compare the timing of them.
I think a lot of people thinks this mean to never use recursion, but this is the wrong lesson.
The lesson is that it is bad to calculate the same thing over and over again.

this is why haskell is the most powerful language

Yes, yes, I do. That was the joke.

Like I said, teachers aren't trying to find the best solution to a specific problem, they're trying to teach a new concept. It doesn't matter how people would realistically write Fibonacci.

godbolt.org/g/zRAQq5
the fuck happened here

>he can't write a helper function with a simple map of inputs and outputs to implement dynamic programming
wewing at you plebs

-O3 magix

just start writting code my dude

The lesson in general is "recursion is another one of your tools".

Though realistically, recursion is only feasible if the maximum depth of recursion is small.

what said.
Start a small project, or something you want to make.
Keep google close by and you'll be fine.

sry for off-topic software question.

I'm trying to find the best duplicate pic detector. I've found 2, but I've been told one of them has bloatware.
Duplicate Photos Fixer Pro or Visipics?
which one is better.

>Θ(φ^2^|n|)

>Θ(2^|n|)

Θ(|n|):
template
class M22{
public:
T m[2][2];
M22(T m00, T m01, T m10, T m11) : m{{m00, m01}, {m10, m11}} {}
M22(const M22& b) {
m[0][0]=b.m[0][0];
m[0][1]=b.m[0][1];
m[1][1]=b.m[1][1];
m[1][0]=b.m[1][0];
}
M22() {}

M22 operator*(const M22& b) const{
const M22& a = *this;
M22 c;
c.m[0][0]=a.m[0][0]*b.m[0][0] + a.m[0][1]*b.m[1][0];
c.m[1][0]=a.m[1][0]*b.m[0][0] + a.m[1][1]*b.m[1][0];
c.m[1][1]=a.m[1][0]*b.m[0][1] + a.m[1][1]*b.m[1][1];
c.m[0][1]=a.m[0][0]*b.m[0][1] + a.m[0][1]*b.m[1][1];
return c;
}
M22 operator^(T n) const {
M22 c{*this}, result{1,0,0,1};
while(n>0){
if(n&1)
result = result * c;
c = c * c; //magic happens here
n>>=1;
}
return result;
}
};
template
T fib(T n){
M22 m{1, 1, 1, 0};
return (m^(n-1)).m[0][0];
}


You could avoid some needless data copying if you worked harder but this is the best approach.

Yeah but coding in a unrealistic bad way is pointless. Nobody covers factorial sort or Sup Forums sort in algorithms classes.

A "realistically" bad recursion would be f(n)=f(n-1) + f(n-2) - f(⌊√n/8⌋) where you might try recursion to solve it since it's not obvious how to iterate it (without full dynamic programming).

How accurate is this?

You should try getting an O'Reilly book, thats how I started, also find some interesting proyects to practice, like making a bot for Dircord,skype or youtube, or maybe try django. For example I did a pdf converter to convert all the pages of Berserk manga, which I have in a jpeg format for each chapter. Good luck user.

1st should be scheme, 2nd C, and 3rd C++

templates in C++ being implicitly inline was a mistake

C is the easiest desu

What did they mean by this?

>not using std::map, mapping strings to function pointers

Totally not paid promoting

I see people always recommending books for learning C++ but what about sites like cplusplus.com/doc/tutorial/ ?
Are they any good?

>mfw it's real
It's okay, though. Anything is better than C++. Even Rust.

learncpp.com is pretty good

These tutorials explain the C++ language from its basics up to the newest features introduced by C++11. Chapters have a practical orientation, with example programs in all sections to start practicing what is being explained right away.

Introduction
Compilers

Basics of C++
Structure of a program
Variables and types
Constants
Operators
Basic Input/Output

Program structure
Control Structures
Functions
Overloads and templates
Name visibility

Compound data types
Arrays
Character sequences
Pointers
Dynamic Memory
Data structures
Other data types

Classes
Classes (I)
Classes (II)
Special members
Friendship and inheritance
Polymorphism

Other language features
Type conversions
Exceptions
Preprocessor directives

C++ Standard Library
Input/Output with files

Quick getting started guide. You need more practice if this is your fist time programming and you need more reading for advanced c++.

I heard that particular site has a lot of mistakes.
If you're looking for a good site to quickly learn the basics of the language, I'd recommend learncpp.com.
Once you are done with that tutorial, look up cppreference.com. It hosts an extensive documentation about the standard library and the language, with examples. I visit it every single day when I'm working with C++.
Of course, that one is not meant to be read from start to finish. Simply look up what you need when you need it.

The head_starts_at_zero arg for ax.arrow in matplotlib.pyplot does nothing, right?

Hello fellow pajeet,
Lets make India programming powerhouse in /dpt/.

I bet you've never written a program where performance actually mattered

Lisp is the most powerful programming language.

Powerful in what ways?

The most powerful at being useless

power level

keep Sup Forums shit out of /dpt/, thanks

>he doesn't know

How did Python become so popular when it's so shit?

shills

brainlet friendly

Building a snake game with Allegro to learn C. I want to use train a ML algorythm later using it

Not as powerful as its descendant Kernel. Lisp is a mediocre lisp.

unordered_map vs open-addressing with quadratic probing paste.debian.net/1009763/

Could someone explain this to me?
It looks like an iot network architecture. Is it just hype?
github.com/AltraMayor/XIA-for-Linux/blob/xia/README

how about programming language that delete whole source code of your program if compilation fails

Single translation unit or LTO?

Hey i'm in community college and they use Java. I haven't really used Java in about a year, what's the best way to review and get back up to speed?

>Not as powerful as its descendant Kernel
This is technically true, but the motivations behind Kernel seem to be more autism-related than practical. What do you do with vau besides implementing roll-your-own versions of features that decent Lisp dialects already support?

>Single translation unit
Do you mean shoving your whole project in one translation unit? That's infeasible for any project of nontrivial size.

Should be pretty easy to use incremental builds during the development cycle and only glue it all into a single TU for release, right?

There's more than just $vau. One of my favorite features is first class environments which enable you to run code with access to only a limited set of bindings, rather than just adding to a set of global static bindings or the current environment.
($remote-eval (some-expr other-expr)
($bindings->environment (some-expr ...) (other-expr ...))
Also encapsulation types are great for defining custom types.
I tend to write kernel in a purely functional style. Instead of mutating an environment, just define a new one with additional bindings in it and the current environment as its parent.

Reposting because only got one retard reply on the last thread:

Hey /dpt/tards, anyone work with, or write supporting software for cryptocurrency stuff?

I have a good chunk of software experience from college classes but took a job after graduation that's more on the hardware side. I'd like to bolster my skills and push my way into SWE.

Up till now I've struggled with finding motivation to write my own shit out of interest, but I've become deeply entrenched in crypto and figure I should just start there. Not least of which because I've gotten multiple job alerts from companies clamoring for the "blockchain programmer" meme. Where should I start? Maybe learn some JS or something and integrate a lil payment applet into a wordpress blog or something? I want to build my more general programming skillz, so I'm not sure jumping into Solidity and making meme tokens and SMuRT CONTRAKTS is the best option because it's too specific.

If it helps I should mention all my experience is in: mostly Java; some Python, and I derped around in some C for our operating systems class. I'm sort of trying to write a trading bot for the bittrex API in python right now, but I'm not the greatest trader to begin with and so am kind of dead-ending any trading algorithms. I've started attempting to just make a GUI with wxpython, and think I might just make an interface to do simple stuff like batch trades, with drop-downs for trading pairs and sliders for choosing the % of your stack you want to sell or whatever, and sending all that on over to the API. But that's going slow too. My friend tells me I should take my time, do the dry stuff and learn best practices and fundamentals, but codecademy and the like never really did much for me. I work best just jumping into something and figuring it out as I go. Should I just keep on with this bot for now to have at least one solid project to show on my github?

Interesting. Maybe I'll try it out, just for the hell of it. Can you actually do anything with it?

Where should templates be instantiated then? In an already compiled compilation unit?

Not really. There's no complete implementation with a fully working FFI. klisp is mostly there, but no longer developed. It's OK for writing simple CLI based scripts, and file IO works.
There are unsolved issues with performance due to some unavoidable overhead in operative calls. and the language can't be compiled. Bronze-age-lisp attempts to improve performance by writing some parts directly in assembly.

I'm working on a Starcraft: Brood War bot in C++.