/dpt/ - Daily Programming Thread

What are you working on Jow Forums?

Last thread:

Attached: code_master.png (1164x1738, 2.17M)

Other urls found in this thread:

medium.com/@felipedutratine/iterative-vs-recursive-vs-tail-recursive-in-golang-c196ca5fd489
rules.sonarsource.com/c/RSPEC-925
en.wikipedia.org/wiki/MISRA_C
github.com/golang/go/issues/28671
github.com/golang/go/issues/28484
github.com/golang/go/issues?utf8=✓&q=is:open is:issue label:Performance optimization
github.com/golang/go/issues/22624
github.com/orlp/dev-on-windows/wiki/Installing-GCC--&-MSYS2
twitter.com/NSFWRedditImage

nth for nim!

Second for C.

3rd for Rust might actually make it.

O for Ocaml

First for Go

Attached: Oface.jpg (599x617, 28K)

Can we have an autism free thread for once, please?

Attached: angry.png (454x762, 448K)

We did, until you arrived.

what are you working on lad?

Attached: [Coalgirls]_Yuru_Yuri_06_(1280x720_Blu-Ray_FLAC)_[F8694A5A].mkv_snapshot_21.17_[2018.07.11_11.39.11] (1280x720, 1.27M)

post yer code

Attached: scrot.png (534x748, 14K)

Didn't you post this spaghetti in the other thread?

I am learning me some erlang for great good!

Attached: cheeky_anime.gif (500x281, 389K)

Drunken port of some shitty C code I wrote way back, spoiler alert, the C version was way simpler to write, even though it ended up with more or less the same line count.
C version also supports input arguments.

Attached: shit.png (484x984, 60K)

>erlang
good lad.

i like tidy neat code
nice

Also, nice 80 rule

It's not neat nor tidy, but I do tend to follow 80 column.

JavaScript rocks!

Attached: js_rocks.png (1433x779, 473K)

Huh, never heard of the 80 width rule. Cool.

did more work on my web framework language. I reworked the way it handles unknown identifiers in preparation for function declarations, fixed a bug in the tokenizer, and improved the error handling so that most syntax errors throw a meaningful error instead of just throwing an assertion failure.
Wrote a test framework as well, just some preprocessor magic and a makefile. Wrote 50-something tests for it, and managed to squash some bugs as a result.
Designed the syntax for describing page layout, fonts, etc.
Current todos before I can hit my next milestone:
- let expression
- cons expression
Everything I need in order to implement them is already there, I just need to decide how I want to deal with forward declarations. The entire precompiler/interpreter is just a stack machine with a handful of little bells and whistles, so it would take 2 passes to be able to deal with forward declarations. I might set it up so precompilation will reorder stuff in a way that makes execution require only a single pass.

based and redpilled

Go BTFO

this is a joke, right?

It's almost as old as computers are.

Nope, I didn't go to school for CS. I still try to get keep from using long lines of code. It triggers my autism.

I did take a computer architecture, but I don't remember learning that.

based
var passFunAndApply = function(fn, x, y, z) {
return fn(x, y, z);
};
var sum = function(x, y, z) {
return x + y + z;
};

alert(passFunAndApply(sum, 3, 4, 5)); // 12

>var
Drink bleach and hang yourself.

>he doesn't know the difference between var, let, const and let
>he thinks we should use let for everything
>he thinks in this small example we must follow strict rules

kys

most languages do this

I'm trying to fall for the functional meme but there are things I still don't get. From what I understand when you're doing operations on lists you're supposed to chain functions. You use map, filter, fold, etc.
Simple enough but how do you use those functions when you need to access not just the current elem in the enumerable but also the previous one for example I just did this in plain old C++
auto theta_sum{ .0f };
for (int i = 1; i < rec_vecs.Num() - 1; i++) { // start from index 1 since ( 0 - 1 ) for u makes no sense
const auto u{ rec_vecs[i - 1] };
const auto v{ rec_vecs[i] };
theta_sum += angle_between_normalized_vectors(u, v);
}
return theta_sum;

How would you program that in any fp language without using for loops?

>>let for everything
Retroactively terminate your family tree.

>How would you program that in any fp language without using for loops?
Recursion.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

typedef int64_t int_t;
typedef array node; // bdd node is a triple: varid, 1-node-id, 0-node-id
typedef const wchar_t* wstr;
template using matrix = vector; // used as a set of terms (e.g. rule)
typedef vector bools;
typedef vector vbools;
class bdds;
typedef tuple memo;
typedef tuple exmemo;
#define er(x) perror(x), exit(0)
#define oparen_expected "'(' expected\n"
#define comma_expected "',' or ')' expected\n"
#define dot_after_q "expected '.' after query.\n"
#define if_expected "'if' or '.' expected\n"
#define sep_expected "Term or ':-' or '.' expected\n"
#define unmatched_quotes "Unmatched \"\n"
#define err_inrel "Unable to read the input relation symbol.\n"
#define err_src "Unable to read src file.\n"
#define err_dst "Unable to read dst file.\n"

>harder to reason about code
>slower
>uses more memory
why

>his language doesn't have termination checking

Literally all wrong

TCO exist for a reason. Mathematically speaking it's very easy to reason recursive algorithms. It's actually dead simple.

>curly bracket initialization
jesus christ C++ is hideous
you would do it recursively, just like how you would if dealing with 1 element at time, or 2, or 10. In haskell I can match a list to the pattern (x:y:xs), which will give me bindings to the first 2 elements, and the rest of the list. If I need to pass one or more of those single elements alongside the list again, it's as easy as (x:xs), (x:y:xs), etc

>what is tail-call optimization
how the fuck is a recursive function harder to reason about than a loop? in my experience, it's the exact opposite.

Looks like you got the for loop wrong, the last element is never going to be read.
Also, you don't need curly braces when initializing with auto, as it guarantees that no implicit conversions can happen. So just use the good old =.

right, so you'd pattern match with the first element of the list and the rest, then recursively call on the rest of the list
reminds me of working with c++ variadic templates

TCO is always slower
medium.com/@felipedutratine/iterative-vs-recursive-vs-tail-recursive-in-golang-c196ca5fd489
there's a reason all standard libraries that matter use iteration and not recursion

>benchmarking in go
Congrats, you used a shitty language with a shitty compiler.

C++ users, ladies and gentlemen

So, whats your counter argument?

what language uses iteration for its std? c? nope c++? nope golang? nope java? hell no

>what language uses iteration for its std? c? nope

Attached: 1544938358663.jpg (500x375, 92K)

C, C++, and Java do not support TCO in their standards. It's not a guaranteed feature and you should not rely on it in those languages.

I don't know about golang since it's a shitty scripting language that sucks and failed to be a systems language, but I wouldn't be surprised if it also didn't guarantee TCO.

rules.sonarsource.com/c/RSPEC-925
en.wikipedia.org/wiki/MISRA_C
>MISRA C:2004, 16.2 - Functions shall not call themselves, either directly or indirectly.

Reread what you posted in >what languages uses ITERATION for its std? c? nope
Surely you see the mistake here.

I am bit salty that this book introduced a third party library instead of just building the lisp from scratch. I find the third party library functions a bit confusing, because it seems like the author is just making you use them, and taking by faith that they will work. A shame really, this is by far the most engaging C book I have ever read. Do any of you guys any other C books that contain an interesting/final project at the end?

Attached: adalovelace.jpg (187x269, 10K)

It doesn't. The article is retarded because it's comparing O(n!) time Fibonacci to O(n) time, not just general vs. tail recursion.

counter-argument to what? his incompetence? He found a blog post benchmarking TCO using horrendously un-scientific methods, in a language with a compiler that is notorious for poor optimization.

MISRA is such a joke. I'm a C developer (mostly OS dev and network firmware) and corporate started trying to push the MISRA meme. Thankfully we were able to put that shit to bed. MISRA is a collection of obvious "you probably already do this if you're not retarded" things, alongside some wildly unnecessary bullshit that leaves me questioning whether the people who wrote the standard have written a program since punch cards died.

>He found a blog post benchmarking TCO using horrendously un-scientific methods, in a language with a compiler that is notorious for poor optimization.
Care to cite that?

I cant understand the Tower of Hanoi algorithm, somebody have an idea?

Golang does not guarantee TCO. Benchmarking TCO in a language that doesn't guarantee it is retarded. See

Wait, am I missing something here, seems like people are comparing non-TCO languages to non-TCO languages.

2 minutes is enough to find an open issue about optimization problems for x86:
github.com/golang/go/issues/28671
Or one specifically related to function calls
github.com/golang/go/issues/28484
Or any one of the 96 open issues regarding performance issues
github.com/golang/go/issues?utf8=✓&q=is:open is:issue label:Performance optimization

So, what?
Go is shit?
Nobody was arguing that.

yes, all four languages he listed technically don't support TCO. Although you may find C/C++ compilers that allow it under certain circumstances, but you really should not rely on it. It sounds like they are thinking about it in golang though: github.com/golang/go/issues/22624

The problem is TCO ruins your stack and makes debugging confusing compared to what your source code looks like.

>Although you may find C/C++ compilers that allow it under certain circumstances, but you really should not rely on it.
Well at least you read the documentation, all in all, compile with "-std=c++{insert standard here}", if you don't, you're the only person responsible for your compiler producing weird byte code.

Lisp is the most powerful programming language.

nani the fuck gcc

/usr/lib/gcc/i686-w64-mingw32/8.2.0/include/xsaveintrin.h:60:1: error: conflicting declaration of C function ‘long long int _xgetbv(unsigned int)’
_xgetbv (unsigned int __A)
^~~~~~~

Guess that's why most software is written in Lisp, oh wait.

Attached: kiara.png (900x734, 379K)

>mingw
i found your problem

post code snippet you faggot, also
>mingw

My grandfather owns a lisp machine that he took from his uni after retiring.

>mingw
Found your problem. MinGW has weird problems sometimes. I don't know what xsaveintrin is, but it's clearly making conflicting declarations of a function.

and your grandfather being a thief makes the language "most powerful" how?

and how in the fuck are you supposed to build windows binaries on linux otherwise? and it's literally a gcc source tarball from the official gnu website that i built how in the fuck is this suddenly bad

It was given to him as a gift user.

Attached: 1529978869214.jpg (821x869, 98K)

Write system agnostic code, and all system tied code, abstract and add explicit system derivatives as needed.

Uninstall everything you've installed relating to GCC.
Now, go install MSYS2.
Now, follow this guide: github.com/orlp/dev-on-windows/wiki/Installing-GCC--&-MSYS2
Windows isn't developer-friendly, period. It's always going to suck. MSYS2 happens to be the least sucky way of doing it.

i am

are you fucking retarded? i'm on linux

Made an nhentai scraper ;)

It has tag blacklisting, language whitelisting, and it can turn obnoxious titles like "[Fujikawa Satoshi] TS Panic Ch. 1-3 [English]" into "TS Panic Ch. 1-3". Downloads are done in parallel. There's random delays after random numbers of image/summary page requests to avoid throttling/breaking the service.

I'm pretty happy with it, should take about a month to finish with my internet speed. I'll probably have to stop it after a while because of ISP data caps though.

>My grandfather owns a lisp machine that he took from his uni after retiring.
>that he took
N>>i am
>eat ruse, son.
Obviously not.

clang > gcc for windows

Seriously?
Not being facetious, just, last I checked clang/llvm based tools where absolute trash on windows.

>MinGW on linux
go run your builds on a fucking windows machine if you're having a problem. MinGW sucks. There's nothing we can do to help you.

I'm working on yet another C/C++ build system because I'm fed up with all the shitty build systems and none of them fit my needs.

godspeed lad, or just change languages.

Cool. If I had enough bandwidth I'd make a ton of mirrors in case nyaapacolypse happens again to other parts of the ecosystem. Make sure to make some big ass torrent and seed it for maximum preservation.

Can't, embedded stuff for MCUs.

what do you need from your build system? I can whip up a makefile for you.

I found it to be really easy. You can build clang natively and even get binaries last time I looked. Makes for a really easy setup rather than the hoops you have to go through for gcc.

alright fags thanks for nothing all i had was to remove the function definition from the psdk header because GCC 8.x+ just ships with that function out of the box

The destination folder is like 15 GB and I've only processed about 6k doujins. Current settings are English only, and skipping ones marked "lolicon", "shotacon", "yaoi", "replaced", or "out of order".

Given that they've got ~300k, it will probably end up being over a terabyte (assuming translated doujins have become more popular over time). The vast majority so far have been skipped for being Japanese.

I'd have do some post-processing to turn each doujin into a .cbz file instead of a folder. That would decrease the total file size, and it would make the torrent file itself a reasonable size (since there wouldn't be millions of individual files)... nothing too hard. The main problem would be initial seeding of the massive torrent, given my ISP data caps.

You can build gcc natively on windows as well, the problem is that these are tools designed around NIX systems, and assume certain shit.
Sure, they work on WIN32 systems, but they are generally unstable, and unpredictable.

I want it to be able to easily download third-party dependencies (that I can also easily change) and build them on multiple host platforms for multiple targets.

Windows is included in that list of host platforms. No, whatever Linux subsystem is not an option, and neither is cygwin or MSYS2.

(If make were an option I'd already be using it, except it's terrible, it's a task runner not a build system, fuck off.)

What else would you use other than gcc or clang?

Sounds like you want cargo and rustc

MSVC, write platform agnostic code, and where you have to rely on platform specific code, abstract it and use macros to do deterministic compilation.

MSVC doesn't even support all of C99. lol stop posting horrible advice.

Sounds like you didn't read the part where it's embedded work for MCUs, my main job is Rust, I still need to use C++ here (also you're a cunt.)

Learn Lisp.

And that's the obstacle you have to work around.
Either rely on unstable tools, or work with stable tools with limited support.
Welcome to cross-compilation.

Which of the dozen dialects? I already know a bunch of them, how would that help me here?

I hate you so much.

Using clang doesn't mean you're platform dependent.

Using clang doesn't mean you're platform agnostic.

That depends, does clang support any and all language extensions used to compile the win32 library?

>unstable tools
I still don't see where you're coming with this. Clang and GCC work just fine on Windows. Microsoft has even been including Clang in all of their documentation for Visual Studio when building C projects.
>or work with stable tools with limited support.
Limiting yourself to a standard from 20 years ago is dumb as fuck and you're retarded for suggesting it. Your advice is HORRIBLE for anyone wanting to learn C or build it on Windows. Dear god you are dense if you think it's a good idea rely on a compiler that dropped C support years ago and left its compatibility in a state where I didn't even finish supporting all of C99 features. Using clang isn't going to restrict you to any platform unless you're retarded. Stop posting.

Fine, just fine.

>mingw is clang
Why don't you go back to rebbit if you're going to argue like this.