/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: urhkmezc0vnz.png (1200x1198, 1.03M)

Other urls found in this thread:

pastebin.com/a2WG1NK9
smallcultfollowing.com/babysteps/blog/2018/06/15/mir-based-borrow-check-nll-status-update/#polonius
netlib.bell-labs.com/sources/contrib/steve/other-docs/struct-regex.pdf
twitter.com/NSFWRedditGif

First for Tech Workers Coalition!

Attached: DJkR7J1VoAAGRDE.jpg:large.jpg (2000x1125, 341K)

Who thought Rust was a good idea?
Who the fuck looked at the most disgusting parts of sepples and thought, yes, we need a more expansive and robust type system based entirely around this. We certainly shouldn't throw it out and adopt a completely different kind of type system that's already better without any work necessary or anything (e.g haskell, ML).

The Rust founder was an Ocaml fan.

Justice for what?

The Rust type system is pretty much just Haskell lite plus lifetimes.

You literally have no idea that you're talking about, Rust's type system is basically that of Haskell minus HKT plus linear types, it has nothing to do with C++, hell, it's not even OO.

somebody with experience in ? Because I cant make it work
Im trying to make a simple 3 thread program whitch fills a common vector with the divisors of 3, one thread is computing odd numbers and the other the pair numbers and a control thread to tell when to insert each computed value(3, 6, 9,12, 15 ...), problem is the program has no output, but does not crash.
And because of pthread I cant debugg the program
pastebin.com/a2WG1NK9

Doesn't really show.
Good god that's hideous. I know it's semantically superior to sepples in every possible way, but SYNTACTICALLY it just makes me fucking LONG to program in the jumbled mess that is sepples.

And affine types, obviously.

Did you forget to join() threads?

>it has nothing to do with C++,
>Self::Transport
>From
>;
>{}
>&
This is some sepples tier bullshit. I don't give a shit about the semantics, it's still sepples tier just on syntax alone.

Is the probability of getting sequencing lottery numbers (e.g. 4,5,6,7,8) the same as random numbers (e.g.12,3,45,6,22) ?

Attached: 1529862166194s.jpg (168x250, 6K)

More like the Rust system is pretty much just Haskell lite plus ::>>

>I don't give a shit about the semantics

Attached: 1525891708311.png (229x220, 6K)

>caring about useless bullshit

go back to academia, kid

You said "type system", not syntax, m8.

Or do you think "type system" is about things you "type" with your keyboard?

Attached: yG7tbJH.jpg (1561x2048, 203K)

>C++ and pthreads
Why are you doing this to yourself? Use C++11 and standard threads.

It's true though, the semantics don't matter if the syntax is awful. Haskell's type system is nice, and it wouldn't be nice if it had sepples semantics, it rather wouldn't be nice at all, but it ALSO wouldn't be nice if it KEPT its nice semantics but had sepples SYNTAX. Which it fucking DID, and the steaming pile of turds that is Rust was born.

no
pthread_join(controler_thr, 0);
pthread_join(impar_thr, 0);
pthread_join(par_thr, 0);
I think that the problem is that the threads stay asleep forever after cond_wait but I cannot debug it because pthreads

I think "type system," when applied to a programming language, should be taken to mean both the type system in the mathematical sense and the language's aesthetic treatment of it.

the probability of 4,5,6,7,8 being drawn is exactly the same as that of 12,3,45,6,22. (unless the lottery is rigged or sumthin) The probability of seing consecutive numbers is higher, depending on the number of possible sequences that are consecutive.

Code artisan detected

I want to manipulate fonts but I have no idea how the formats work and Google won't tell me

Attached: Ryūko Matoi.png (132x132, 21K)

>"your language is ugly as balls"
>"hhurrr, c--c--code artisan, m--muh memes"

Attached: 3Q7iXtQ.png (645x729, 51K)

Trying to work on a K-Means algorithm, specifically for images.

If I have a general class, ImageProcessor that can take care of several image processing algorithms (like K-Means), how would I do the following:
Give the image information (like, image contents for each pixel/width/height/all that) to any sub-classes that need them (like K-Means or Dithering) without doing expensive copying? Would simply copying not be too bad?

Would I use pointers to the data?

When a normal person says "type system" they aren't talking about syntax. If they want to talk about syntax, they say "syntax".

You do realize, in contrast to math, aesthetics is highly subjective and no one cares about your personal taste, especially since you haven't spent a minute learning the language yet complaint about it being incomprehensive.

>it just makes me fucking LONG to program in the jumbled mess that is sepples
There is nothing in Rust that is remotely as terrible as std::visit though

How do I make this compile without allocating an unnecessary String in the case of the key already exists?

use std::collections::HashMap;

fn main() {
let mut map = HashMap::::new();

assert_eq!(get_value_or_create(&mut map, "foo"), 420);
}

fn get_value_or_create(map: &mut HashMap, key: &str) -> i32 {
match map.get(key) {
Some(i) => *i,
None => {
*map.entry(key.to_string()).or_insert(420)
}
}
}


error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable
--> src/main.rs:13:14
|
10 | match map.get(key) {
| --- immutable borrow occurs here
...
13 | *map.entry(key.to_string()).or_insert(420)
| ^^^ mutable borrow occurs here
14 | }
15 | }
| - immutable borrow ends here

Sometimes you wonder how OOPlets even come up with such absurd questions.

WTF do you pass data to subclasses? You mean when calling superclass constructors or what?

>Haskell uses :: for type annotations and : for list cons
Why in God's name?

>I think "semantics" should also mean "syntax"

Attached: images.png (185x272, 6K)

>You do realize, in contrast to math, aesthetics is highly subjective
Disagree, there are objective measures of it and Rust fails all of them.

And don't even get me started on this fucking language. Just ew.

zero-cost abstractions if maintainability and developer time are worthless

which is no good thing

use std::collections::HashMap;

fn main() {
let mut map = HashMap::::new();

assert_eq!(get_value_or_create(&mut map, "foo"), 420);
}

fn get_value_or_create(map: &mut HashMap, key: &str) -> i32 {
if let Some(i) = map.get(key) {
return *i;
}
*map.entry(key.to_string()).or_insert(420)
}

blenderscript (python) for batch conversion

>there are objective measures of aesthetics
Are you one of these autists who "disprove" modern art?

A language can't really call itself functional if it's not lazy.

Attached: 1528483789059.png (600x275, 123K)

if you don't understand sepples you're just a brainlet

#include
#include
#include
#include
#include
#include
#define b

auto m = (auto bitand a) { while( a, compl decltype (a.a + a.a) (a) ) ( decltype (__FILE__[0]) ) a; };
static inline struct a {
decltype (! std::numeric_limits::max () ) a ;
decltype (1'1'1) aa ;
auto operator , ( decltype (a) ) -> struct a { return { std::equal_to (aa, EOF) }; }
operator decltype (a) (b) { a xor_eq not false; return not not a; }
operator decltype ( '1' ) (b) { putchar(aa); }
operator decltype ( std::numeric_limits::min () ) ()
{ aa = getchar(); return a; }
} a;
auto main (b) -> decltype (a.a ? a.a : INT_MAX) try catch (...) { }

> tfw getting audio to work with Linux is my full time job

I didn't ask for this feel.

Attached: IMG_20170902_172057454.jpg (2340x4160, 827K)

Actually, a language can't really call itself functional if evaluation strategy matters at all.

Incoherent rambling.

>if you think there are objective measures for the aesthetics of programming languages you must think that about art as well
>programming languages are comparable to art in any way
>you, however, are the code artisan here for thinking rust is ugly, certainly not me for thinking a programming language can be a work of art

Attached: 1529473523399.jpg (900x250, 5K)

wrong it had to be azy
because:
functional mean everything a functin

> Aesththethix in brogramming

Attached: download.jpg (474x275, 24K)

Experimenting with the strip tool. How much can I reliably remove? And how much easier does it get if I'm using a static libc?

Trial and error says:
strip -s --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag --remove-section=.jcr --remove-section=.eh_frame --remove-section=.eh_frame_ptr --remove-section=.eh_frame_hdr --remove-section=.gnu.version a.out

Is there a more reliable way?

You forgot about a loop in the controller thread, it just signals twice. Your two other threads never terminate, so they can't be joined.

use std::collections::HashMap;
use std::collections::hash_map::Entry;

fn main() {
let mut map = HashMap::::new();

assert_eq!(get_value_or_create(&mut map, "foo"), 420);
}

fn get_value_or_create(map: &mut HashMap, key: &str) -> i32 {
match map.entry(key.to_string()) {
Entry::Occupied(oe) => {
*oe.get()
}
Entry::Vacant(ve) => {
*ve.insert(420)
}
}
}

>"huuurrr ass the dicks don't exist in programming"
>uses rust
>doesn't use pure machine language for everything
you seem to be contradicting yourself here

Attached: 1529241703052s.jpg (125x78, 2K)

It would search for the key two times if it's not present, which is suboptimal.

What are you even trying to optimize for? Memory usage? high-insertion scenarios? read-mostly ?

If you have profiled and this is your bottleneck, don't even just use a standard library hashmap, they're not made to be fast.

What it looks like is you're doing some extremely premature optimization.

> He doesn't know about programmer productivity

Pleb

> he implies programmer productivity is not exactly the same thing as aesthetics and precisely the objective measure to which i was referring

Attached: 1528640310942.jpg (259x194, 5K)

I'm not the guy who's asking, I'm just pointing out you can match directly to the result of entity thus avoiding searching the map two times, .

Thanks, but why is it not working in the case of returning a reference? E.g.
use std::collections::HashMap;

fn main() {
let mut map = HashMap::::new();

assert_eq!(get_value_or_create(&mut map, "foo"), &420);
}

fn get_value_or_create &'a i32 {
if let Some(i) = map.get(key) {
return i;
}
map.entry(key.to_string()).or_insert(420)
}


This allocates a new string which isn't needed in the case the string already exists in the map.

Yeah, if that's what you're optimizing for.
user was asking how to avoid the memory allocation.

>avoiding an obvious waste of time is premature optimization
I fucking hate you shitters who quote Knuth as if you could even hope to understand what he was originally getting at.

You're thoroughly misguided, you reason like just looking at the interface — at how the data structure is used — is going to tell show you where time is wasted.

Breaking news, abstractions are not perfect. Get a better map adapted to your use case and you will get rid of orders of magnitude more overhead than by eliminating the possibility of a double lookup.

daily reminder we are repeating history here by fulfilling the prophecy of the golem.

computers are literally golems. they're clumps of earth animated by energy from the skies and given purpose by arcane runes inscribed within them. the earth in question being molten sand extract, the energy being lightning -- which we have learned to create rather than relying on storms -- and the arcane runes being set and unset bits.

do you feel like ancient wisemen now? because you are

Oh, right, I've missed that bit, then is the solution.

> Language tooling is aesthetics

Turbo pleb.

I made a small cli program to print a random shakespeare quote because I wanted a shakespeare quote when I logged in like the fortune program does.

The programming part was easy, but then I realized I had to compile a bigass list of a bunch of shakespeare quotes and now it's taken three weeks and I still have like twenty plays to go.

just kill me senpai

Try using #![feature(nll)] if you're on nightly.

haskell is an abomination.

Rewriting the whole data structure could very well be an extremely premature optimization compared to just not being stupid with how you interact with it from client code.

It's far more likely for an extra lookup to be more expensive than an extra allocation.

>wanting everything to be forced lazy when next to no programs or situations are inherently lazy
>wanting to use an eternally slow lang

I mean it's more likely for complexity from how many items are stored to be the bottleneck as opposed to allocation.

>Thanks, but why is it not working in the case of returning a reference?
Basically because of a technicality with the lifetimes of returned references.

When you call get() and return the reference it gives you, then that reference's lifetime must outlive the function. So the compiler writes down that that reference lives for at least the whole function.

Later in the same function you call entry(), which makes a mutable borrow. The compiler (incorrectly) thinks the reference from your earlier call to get() is still alive at this point so it won't let you do anything.

The short of it is you're basically screwed.

Some more info because it's not completely hopeless, technically the Non-Lexical Lifetimes feature that everyone's been awaiting for the past 5 years would solve this.
However NLL is currently partly implemented, and the only part of it that's missing is the part you need.
There's an experimental complete version of NLL that addresses this, but it's far from complete (because of course it is).

smallcultfollowing.com/babysteps/blog/2018/06/15/mir-based-borrow-check-nll-status-update/#polonius

Playing with Remote Procedure Call in Go. It's pretty nice:
package main

import (
"fmt"
"log"
"net"
"net/rpc"
"time"
)

const (
serverAddr = "localhost"
portNum = "5006"
)

func main() {
go func() { log.Fatal(server()) }()
time.Sleep(200 * time.Millisecond)
if err := client(); err != nil {
log.Fatal(err)
}
}

type Fib struct{}

func (f Fib) FibN(n int, res *int) error {
a, b := 0, 1
for i := 0; i < n; i++ {
a, b = b, a+b
}
*res = a
return nil
}

func server() error {
l, err := net.Listen("tcp", serverAddr+":"+portNum)
if err != nil {
return err
}
var fib Fib
if err := rpc.Register(fib); err != nil {
return err
}
rpc.Accept(l)
return nil
}

func client() error {
c, err := rpc.Dial("tcp", serverAddr+":"+portNum)
if err != nil {
return err
}
defer c.Close()
n, res := 3, 0
if err := c.Call("Fib.FibN", n, &res); err != nil {
return err
}
fmt.Printf("fib(%d) = %d\n", n, res)
return nil
}

>if err != nil

Attached: 1529777549976.jpg (480x480, 19K)

Guess I have to use the entry API and swallow the wasted allocation.

What is Go used for?

I'm analyzing the upcoming popular languages. I've got Typescript (used the same as JavaScript), Swift (used for iOS and Mac OS X stuff) and Golang.

I have no idea what the last one is for. Help me, Jow Forums.

Attached: dragon.gif (500x500, 1.96M)

go is so disgusting. google's brainlet magic is something else to have fucked up pike this bad.

Docker?

Attached: Da9Cp2l.png (680x680, 118K)

Golang was originally envisionned as a systems programming language. When everyone laughed them out of the room, they fell back to a multithreaded backend server niche, which they're just okay at.

primarily for webshit backends, as go is literally designed for brainlets.

Those are upcoming languages?

Stop after you've reached a sizeable amount of quotes and periodically add more quotes as you start to recognize the ones you see on bootup. Also pls post the database on archive.org or something.

Thanks.

Well, I scraped github and those are the ones that have at least 5% usage across all the projects for the past 3 years in a row.

Other than that it's JavaScript, Java, Python and C++, but they have been there for 8 years and are not moving. C died around 5 years ago it seems.

when did you realize that programming is boring as fuck

Attached: 1414633747087.jpg (251x242, 10K)

it's not, you're just an ADD brainlet, Josh.

Servers. It has a very simple but powerful concurrency model based on CSP which really shines in a server setting and fully functional server implementations for various protocols in its standard library. Google basically created it in order to replace old custom languages on various servers.

My english isn't that good, is there a good book about learning C in german language?

Thanks!

Trying to learn how to set up tests for my program in XCode

I found this library, Catch2, that looks simple enough that I can use it well. However, whenever I include everything, I either get "conflicting types for main" or "Linker Error - duplicat main_" functions

Anyone have experiences with testing these things in XCode?

Attached: Screen Shot 2018-06-24 at 12.03.25 PM.png (3416x432, 179K)

As soon as I learned all the fundamentals.
What's fun is the cool new complicated projects I can program, not the act of typing.

>C died around 5 years ago it seems.
No, that can't be possible. C will live forever. It's the heart of open source. Your numbers are just wrong.

It is sad to see pike go from stuff like this:
netlib.bell-labs.com/sources/contrib/steve/other-docs/struct-regex.pdf

to stuff like go

You should also consider Rust, it's quite new but promising.
t. Rust shill

Why is there so much shit in a binary?
>compile sqlite shell, disable extension loading, thread safety, -Os, statically link in sqlite3
gcc shell.c -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION sqlite3.c -Os
647168 bytes
>have it do garbage collection (why didn't -Os do this before me?!)
gcc shell.c -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION sqlite3.c -Os -Wl,--gc-sections
643072 bytes
>#include sqlite3 instead of statically linking it, and garbage collect
(you can safely ignore the warnings)
gcc shell.c -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -include sqlite3.c -Os -Wl,--gc-sections
642328 bytes
>#include sqlite3, garbage collect, do static build with musl libc
gcc -I/home/username/Documents/coreutils/musl-1.1.19/arch/x86_64/ -I/home/username/Documents/coreutils/musl-1.1.19/obj/include -I/home/username/Documents/coreutils/musl-1.1.19/include/ -I/home/username/Documents/coreutils/musl-1.1.19/arch/generic/ -specs=musl-gcc.specs2 shell.c -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -include sqlite3.c -Os -Wl,--gc-sections -static
678128 bytes

NB! replace /home/username/Documents/coreutils/musl-1.1.19/ with your path to a compiled musl directory
NB! cat musl-gcc.specs | sed 's/\/usr\/local\/musl/\/home\/username\/Documents\/coreutils\/musl-1.1.19\//g' > musl-gcc.specs2
>remove all symbols with strip
strip -s a.out

593928 bytes
Again, why the fuck does -Os not do this for me automatically? It reduced the binary size with over 12%!
>remove some other sections that aren't needed with strip, one of which appears to be used for Java (!)
strip --remove-section=.comment --remove-section=.jcr --remove-section=.eh_frame a.out

593672 bytes


What is the reason for this madness? Why does default -Os produce a binary that is something like 20% larger than it has to be, regardless of other circumstances?
(dynamic musl is about 54k, but needs installed musl)

github is not a valid measurement for popularity.
JavaScript is so popular on github because it is easy to make bugs or create absurd shit like leftpad (hence the largest amount of "libraries").
Java and C++ because the standard lib sucks ass and python for script kiddie tier programs and as interface for low level crap.
The percentage of actually useful open source programs is barely 1% like nginx

>watch crystal presentation
>guy says "don't worry if the type annotation (name : String) is scary to you"
Do dynamic shitters really get overwhelmed by simple type annotations?

540k*

try
strip --strip-all

lewd

-s is the short version of --strip-all. As you can see, it does in fact not strip all, because there is still .comment, .jcr (something about java), and .eh_frame (something about exceptions or c++ or debugging or something)

>Your numbers are just wrong.
Probably. I have a huge gap in data which I will fix for the next version, but right now I have mostly shitty projects (1700 stars).

It's not for me, but for a seminar.

Well, I don't really have another place to scrape.

Attached: trend_all.png (3840x3072, 94K)