/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

reddit.com/r/ProgrammerHumor
science.raphael.poss.name/rust-for-functional-programmers.html
garden.dlang.io/
github.com/hsutter/gcpp
youtube.com/watch?v=JfmTagWcqoE
aristeia.com/books.html
en.cppreference.com/w/cpp
stackoverflow.com/questions/2191632/begin-rescue-and-ensure-in-ruby
twitter.com/NSFWRedditVideo

Nice op image.
We need more like this.

I fucking hate anime as op image

Thanks, friend, I stole it from reddit.com/r/ProgrammerHumor , you should really check it out, it's hilarious, that volume control running joke is killing me! :^)

>What are you working on
Nothing :(

stop watching anime

What do you make of this, anons?

>tfw finished the fun part of the project too quickly
>tfw procrastinating from writing the scary part

how do i into GUI?
Qt is intimidating.

What do they call that kind of style?

>paying money for books
Why would anyone do that?

The only worthwhile thing there looks like the Scala bundle.
Golang is retardedly easy to pick up, and if you want to understand exactly whats going on inside a package its very very easy to read and figure out. You have to intentionally try and be obtuse to produce hard-to-read code in it.
Everything else looks like worthless "web developer bootcamp" material.

>he knows reddit memes
Thought for sure this was Sup Forums oc but I guess not.

std::string* decToBinary(std::string text, int txtlen) {
std::cout

Start with basic example and hack until you understand it.

Then start over. Repeat if you have to.

Do you have any of these for python?

Just look at any python code.

I haven't read all of it but you free (delete) your string before you return it. That's probably what's wrong here. You just need to not do that. Let it be the callers responsibility to delete the allocated string.
So remove the line: delete[] binaryTxt;

No, only the result of teaching people python.

okay thanks, so does that mean that when that after the function returns a value, the memory used in that function automatically frees itself?

I'm kinda new to pointers and stuff.

Usually you allocate the array (even if its on the stack) before calling the function. For example:

void
fill_array(int *array, int size)
{
for (int i = 0; i < size; ++i)
array[i] = i;
}

...

int array[5];
fill_array(array, 5);

That's static allocation. Usually you don't want to do this, but for example you could also do the following:

void
fill_array
{
int *array = (int*)malloc(5 * sizeof(int));
/* Fill the array somehow */
return array;
}


Obviously in the latter case, you also have to free the allocated array later.

The latter function should've returned an int pointer. Anyway, you get the point.

wait, so you allocate the memory in the scope containing the function and then pass it as an argument into the function? Then after the function has returned a value, you free the memory in the same scope you allocated it?

No it means it doesn't. You need the string outside the function right? In that case you want the string to remain, it shouldn't be deleted.
A pointer just points to something. In this case a std::string. With the 'new' operator you asked the computer to allocate some memory for your pointer to point to so you can store the string. It will remain until you deallocate it (delete it). So it will remain even outside the function. But you don't know where it is unless you return a pointer to it. Which you are doing.

Also you have a problem with your while loop.
You wrote while(cond=True) this assigns cond the value of True and the checks if cond==True
You almost certainly meant while(cond==True), checking if cond is equal to True. Or even shorter: while(cond)

>if I see another keyboard I swear I'm gonna fuckin SHIT
w-what?

Yes, you can do that. Of course if the array is on the stack, you don't need to explicitly free it (as in the first example).

>I'm gonna fuckin-
>SHIT

science.raphael.poss.name/rust-for-functional-programmers.html

And for my fellow D fags, must read
garden.dlang.io/

Rust for Karl Marx.

?

Rust introduces a new “box” type with dedicated syntax for heap allocated objects, which are called managed objects.

Rust supports multiple management strategies for boxes, associated to different typing rules.

The default management strategy for boxes ensures that boxes are uniquely owned, so that the compiler knows precisely when the lifetime of a box ends and where it can be safely deallocated without the need for extra machinery like reference counting or garbage collection.

Another strategy is GC, that uses deferred garbage collection: the storage for GC boxes is reclaimed and made available for reuse at some point when the Rust run-time system can determine that they are not needed any more. (This may delay reclamation for an unpredictable amount of time.) References to GC boxes need not be unique, so GC boxes are an appropriate type to build complex data structures with common nodes, like arbitrary graphs.

Unlike C, Rust forbids sharing of managed objects across threads: like in Erlang, objects have a single owner for allocation, and most objects are entirely private to each thread. This eliminates most data races. Also the single thread ownership implies that garbage collection for GC objects does not require inter-thread synchronization, so it is easier to implement and can run faster.

>July 2014
It was a year before 1.0.

>iterate over all pairs of the string and increment a key in our dictionary
import std.array: array;
import std.algorithm: each, map;
import std.range: dropOne, only, save, zip;
import std.conv: to;

int[string] d;
auto arr = "AGAGA".array;
arr.zip(arr.save.dropOne)
.map!"a.expand.only"
.map!(to!string)
.each!(a => d[a]++);
assert(d == ["AG": 2, "GA": 2]);

Good thing they've got rid of it, the language would be such a mess with an optional GC.

The goyim know.

Yes that's what I was thinking about. I have nothing against the optional GC really though

Yea, GC can be occasionally useful, I think Sutter's idea of manually-controlled kinda-GC as a library for C++14 is interesting: github.com/hsutter/gcpp , youtube.com/watch?v=JfmTagWcqoE .

>finish something
>it's an ugly unsafe piece of shit
>would need to rewrite everything to make it better

Any reason why you're using a pointer here? Just use a stack variable and return it, it'll be fine due to copy elision.

I wonder what people think when they stumble upon one of my codes.

I was writing a program that reads and prints the first nth lines to the stdout:
>>
>> import std.stdio;
>>
>> void main(string[] args)
>> {
>> import std.algorithm, std.range;
>> import std.conv;
>> stdin.byLine.take(args[1].to!ulong).each!writeln;
>> }
>>
>> As far as I understand the stdin.byLine.take(args[1].to!ulong) part reads all the lines written in stdin.
>> What if I want to make byLine read only and only first nth line?


I was actually just looking for ways to read the first n line and then print it ($man head). My current program
1. reads all the lines provided by the stdin (bottleneck)
2. takes the first n lines (bottleneck)
3. prints each line


I want to
1. read all the lines
2. when line number n is reached, stop reading the rest of the input
3. print each line


Sorry, I am new to functional paradigm

Post it

C supports lambdas, they just have to be strongly typed and declared at top level with a name.

Yeah.
C also supports dynamic typing.
It just has to be statically typed.

what to read to learn c++11, that isn't a 1300 pages long?

What exactly do you need from 11 that isn't available from any general C++ tutorial?

aristeia.com/books.html
en.cppreference.com/w/cpp

I learned c++98 bc the lecturer is a lazy fuck, and I don't want to read stuff I already know

There aren't that many features that you would need after 98, unless you want to use the standard library. But then, if you think you need a structure or functionality from the standard library, just search for it on the internet. Templates and the like to my knowledge also exist in 98 anyway, so there's really not much for you to learn there.

cant go wrong with scott meyers

You just have to use a better language.
use std::io::{stdin, BufRead};
use std::env::args;

fn main() {
let n = args().nth(1).unwrap().parse().unwrap();
let stdin = stdin();
let _ = stdin.lock().lines().take(n).map(|l| println!("{}", l.unwrap())).count();
}

>let n = args().nth(1).unwrap().parse().unwrap();
kek

I knew some autists will be triggered by this.
See, you have two potential points of failure here: there could be no argument, and it could be not integer, so you have to explicitly say you don't care two times.

>use std::io::{stdin, BufRead}
nice
>.unwrap().parse().unwrap();
the fuck
>stdin.lock().lines().take(n).map(|l| println!("{}", l.unwrap())).count();
not any better

>let stdin = stdin();
Has science gone too far?

What's the point of that if the program is going to crash either way?

Is this rust? Why oh why would they take the horrible namespace syntax from C++ (::)?

How many of you friends/employee do you know that read multiple technical books page to page?
I haven't seen anyone trying to improve. Their knowledge is confined to stackoverflow, occasional tutorials, youtube videos.
The state of learning process is worst and people don't seem to care as long as they go home stick their dick in their wife's holes.

>let stdin = stdin();
W E W
E
W

>the fuck
See >not any better
Not better than what? It's better than the D version because lines() doesn't read anything, it returns a lazy iterator, then take() and map() modify this iterator and it's only via count() the IO actually gets executed. Oh, and the result code is a tight loop without any calls, possible even unrolled.
You have to handle all the possible errors in the code itself, for example with .unwrap_or_default(), or .unwrap_or_else(), or by matching the result manually. Equivalent D/Java/C# code would compile without error handling but then produce exceptions during the runtime, which is not very safe. In rust you can ignore error by unwrap(), but you don't get any surprise crashes, because you wrote than unwrap yourself.

>You have to handle all the possible errors in the code itself, for example with .unwrap_or_default(), or .unwrap_or_else(), or by matching the result manually. Equivalent D/Java/C# code would compile without error handling but then produce exceptions during the runtime, which is not very safe. In rust you can ignore error by unwrap(), but you don't get any surprise crashes, because you wrote than unwrap yourself.
It doesn't change the fact that the syntax is ugly as fuck.

I don't have any friends

Freedom (from memory unsafety) ain't free.
Oh well.

>they go home stick their dick in their wife's holes.
what more could you ask for in life?

correct me if I'm wrong, but you can't return static arrays in C/C++.

also gave me an error where I tried to use static arrays for variables, said that the array size needed to be constant(I still wanted to change the size of the array to match the length of the input), which makes sense

thanks guys, i appreciate it. I'm gonna finish the project and then read up on pointers some more.

I didn't even use map

A coworker of mine is writing his own neural network. I don't know of anyone else hobby programming though.

There are much better ways you can write that.
use std::io::{stdin, BufRead};
use std::env::args;

fn main() {
let n = args().nth(1).unwrap_or_default()
.parse().unwrap_or(0);
let stdin = stdin();
let lines = stdin.lock()
.lines().take(n)
.filter_map(|l| l.ok());

for l in lines {
println!("{}", l);
}
}

Everything in your post reeks of reddit.
Seriously: piss off. Your kind is not welcome here.

>forcing FP into a C like language
cancer incarnate

Not programming related.

What is a ``FP" though?

treffer is a list. you have to get the first instance or iterate through them.

to reiterate: its a list of objects, you can't access the properties of those objects through the list interface.

are you retarded

>Wrote my first useful program

>foobar2k saves .m3u playlists with absolute file paths in them
>mp3 player needs relative paths

Programs goes through every line of every .m3u file in a folder and cuts the first 17 characters off to make it relative.

import os

temp = []

for i in os.listdir(os.getcwd()):
if i.endswith('.m3u'):
test = open(i, 'r')
for x in test:
temp.append(x[17:])
test.close()

test2 = open(i,'w')
for y in temp:
test2.write(y)
temp = []
test2.close()

>Wrote my first useful program
>foobar2k saves .m3u playlists with absolute file paths in them
>mp3 player needs relative paths

Why did you mark these as quotes?

If it works, great! I always get tingles when I use my own program.
I'm no Python expert, but try this:
import os

temp = []

for i in os.listdir(os.getcwd()):
if i.endswith('.m3u'):
#test = open(i, 'r')
#for x in test:
# temp.append(x[17:])
#test.close()

with open(i, 'r') as test:
for x in test:
temp.append(x[17:])

#test2 = open(i,'w')
#for y in temp:
# test2.write(y)
#temp = []
#test2.close()

with open(i, 'w') as test:
for y in temp:
test2.write(y)
temp = []
test2.close()

To make you reply.

I fucked up the last block, but I hope you get the idea.

>I fucked up the last block
You fucked up the whole program. It's in Python.

I do. Thank you.

>reddit.com/r/ProgrammerHumor
>:^)
>memes
Use

You want to return std::string from the stack, no one said anything about static arrays.

QUICK
what is your fav IDE

qtcreator

IntelliJ

>constant pain in lower arm when using mouse of typing
rip programming career

i dunno
VS is alright but it's a bit thicc

Visual Studio 2017

Notepad++

>not having someone else typing out the code

vim

Vim any day.

ed

But why is she gonna take a shit if she sees another keyboard?

Is it possible to do something like this in Ruby?

if mutex.try_lock
do_something() ensure mutex.unlock
end

stackoverflow.com/questions/2191632/begin-rescue-and-ensure-in-ruby
>holy shit google is so fucking hard

i want to return an array, read the binaryToDec function.

Hello anons, Python noob here, I'm learning the selenium module at the moment and this error appears every time

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH


I have done some research on the error and understand it, and I have tried putting the driver in every possible folder and it still doesn't recognize it as in PATH.

My question is, what's PATH path suppose to be by default? Google gives nothing and I have also tried putting the driver on /usr/local/bin but it didn't changed anything, any ideas would be really appreciate it.

There are no male programmers.