/dpt/ - Daily Programming Thread

/dpt/ - Daily Programming Thread

Previous thread:

Attached: C_dpt.jpg (1280x720, 582K)

Other urls found in this thread:

rosettacode.org/wiki/FizzBuzz
gist.github.com/7ba9ce731bc0828e38e5e410393d6f23
reddit.com/r/rust/comments/7qels2/i_wonder_why_graydon_hoare_the_author_of_rust/
en.cppreference.com/w/cpp/language/default_constructor
twitter.com/SFWRedditVideos

Cool photo

Bumping from last thread

Attached: 1517094039892.jpg (1920x1080, 512K)

Lisp is the most powerful programming language.

fuck the police!

We're getting somewhere:
module Main where

import qualified Data.ByteString.Char8 as S8
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Network.HTTP.Simple (getResponseBody, httpLBS, parseRequest)
import System.Environment (getArgs)
import Text.XML (def, parseLBS_)

import Lib

help = "euclase 0.1.0\n\nUsage: euclase URL [URL...]"

main :: IO ()
main = do
urls

A tip is to attend a hackaton with some friends or colleagues.

How do I write if(line in text file is empty) in C?

e.g

#
#
#
#
#
[empty line]
[empty line]
#
#
#
#
#
#

Redpill me on R, is it still the best place to start for wannabe data analysts?

Yes

Nope. Python has left it in the dust.

implemented fft [spoiler]on clisp[/spoiler]
can i get a job now

>friends or colleagues

Attached: nicebuttersnigga.jpg (1200x900, 249K)

Learn R, then use Python and rpy2 instead.

Same question as here: rate my prime lister, give me a (You) if it looks okay

search for \n?

I'm sorry, I don't speak meme. What point are you trying to convey? You don't have any friends (that can program) or colleagues?

So, I just subscribed to Treehouse and started learning Java. The lectures are concise and helpful, however their compiler sucks. Many people have complained about it, and it keeps messing up the format of my output even when I do exactly as the guy does in the video. They say they've messed with it since the video was released to increase memory size, but now it keeps giving me a line of useless shit every time I compile, and the line to compile the next line of code always starts on the same line the previous code compiled in and I can't change that, so it just looks messy.

Are there any compilers you guys can recommend for Java? I'm waiting for a textbook on Java to arrive that I ordered on Amazon to help me along

Attached: Treehouse.png (565x176, 22K)

good first try, now implement the sieve of eratosthenes

First of all, it's stupid to check all numbers up to the number you are currently checking, checking divisibility up to the square root of the current number is sufficient.

Secondly, if you're creating a list of primes, use a sieve instead. It's way less computationally heavy.

Thanks, I only have a bit of programming experience but not much so I think I'm gonna start with R and pivot to Python later.

since I'm pretty sure this will require a scripted solution, I'll repost my question here:
----------------------------------

is it possible to search through all of the source code of a specific website (a tumblr blog in particular)? there is a private image I want removed on Tumblr, and I want to see the specific post it's in before I report it just in case there are more photos accompanying this one.

I have the URL of the Tumblr image, and I know which Tumblr it was posted on, but I cannot find the specific post within the Tumblr, because there are probably hundreds of thousands of images to sift through.

The syntax of the image URL doesn't tell us much, so I can't go through the archive and look up a specific date to sift through.

I already tried inspecting the page element in Firefox and using the "search HTML" feature to search for the image URL (adjusted to reflect the thumbnail size that would be shown on the archive page, changing _1280 in the URL to _250) while scrolling through the single-page Archive 6 months at a time. This was only successful if I searched for a specific image AS it was scrolling by my screen. So I don't think the Archive feature is of any use, even though it appears to load all of the images on one page (it really doesn't)

I've tried numerous other options, but I think just searching through the source code of every page on the site for the specific image URL is the only way for me to find the post that contains the image. I was thinking a script that loads every page in the tumblr (gayniggas.tumblr.com/page/1, gayniggas.tumblr.com/page/2, gayniggas.tumblr.com/page/3... etc) and searches for the image URL would be able to find it in no time, but I don't know any programming.

This seems like something that should be a lot easier than it is. Please halp

Attached: 1529723199360.jpg (1651x1100, 862K)

nice

i don't know why you'd do that. if you think R would somehow improve your data science theoretical knowledge you're mistaken. you should take a course on linear algebra, probability, and statistics for that

I've taken all of those, graduating in 2 years with a math/stats bachelor's. I'd just like to start some data analysis projects.

That grep video was neat.

>graduating in 2 years with a math/stats bachelor's
I hope to god at least one class is on applied statistical analysis using R, otherwise you're going to a shit college.

>Are there any compilers you guys can recommend for Java

javac via openjdk? I don't know why you'd avoid openjdk or oracle jdk unless you had specific licensing or performance requirements.

for a white cis scum

How would you do this in rust?
struct Camera {
const Person *p;
};

struct Person {
int x, y;
};

{
Person p = {};
Camera c = {&p};
while (1) {
p.x++;
p.y++;
printf("the camera is at %d, %d\n", c.p->x, c.p->y);
}
}

How about Eclipse?

struct Person {
x: i32,
y: i32,
}

struct Camera {
person: Person,
}

fn main() {
let p = Person { x: 0, y: 0 };
let mut c = Camera { person: p };
loop {
c.person.x += 1;
c.person.y += 1;
}
}

Does Eclipse package a version of the JDK/JRE currently?

I recall that IntelliJ IDEA was shipping some stable OpenJDK version of its own for a while.

Or are you asking about IDEs? Eclipse is fine, IntelliJ IDEA is fine, Netbeans is not worth the pain. Or you could always use a text editor and just call javac with your source files. (Or mvn or gradle if you're using such a system).

That's not the same thing.

Not really, I'm an autist.

You didn't state your requirements. I only imitated the behavior.

what is a good webscraper project for a beginner in python?

You can always show up at one anyway though. They expect people of different skill levels to attend. I joined one with some colleagues from work once, and there were vastly different people there from autistic neckbeards with their thinkpads to literal trannies with programming socks.

Just heard of miniKanren.
Fascinating stuff.

This has the same observable behavior.
fn main() {
loop {
}
}

you should all kill yourselves.

If they're not inclusive of rookies that's their loss.
And really since it's been advertised to you they're probably looking for inexperienced people.

Why?

could you show me how to do it if my requirements were the camera could follow a different person if you assigned a different person pointer/reference to it. the camera also shouldn't modify the person

why not

I don't find any reasons why I should kill myself.
I have some reasons not to kill myself.

this sounds retarded but I think it'd be fun to write fizzbuzz in 100 programming languages

I just started toying around with Common Lisp yesterday. I think the biggest challenge for me is going to be making sure that I write code in a way that makes the bracket matching readable. Any suggestions?

There's a lot of ways, but here's one
#include
#include

int main(void) {
FILE * file;
char * line = NULL;
size_t len = 0;
ssize_t line_len;

file = fopen("./path/to/your/file.txt", "r");

if (file == NULL) {
// do something if the file couldn't be opened
} else {
while ((line_len = getline(&line, &len, file)) != -1) {
printf("length of line is %zu\n", line_len);
}

fclose(file);
free(line);
}

return 0;
}

I was thinking of showing up just to observe at the very least. Might help me network as well.
Worst case scenario I can do something easy if I decide to enter. Thanks!

Good question. I gave up on Rust, so my knowledge on the subject is a bit Rusty :^)
Pro tip: it's a fucking nightmare to implement.

new line in text file is "\r\n" or just "\n"?

>"\r\n" or just "\n"
Yes

>this sounds retarded but I think it'd be fun to write fizzbuzz in 100 programming languages
rosettacode.org/wiki/FizzBuzz

So, the camera needs to identify which person it follows, and needs read-only access to the person's location, but only while being updated, and without having ownership of the person?

What language is this? Looks neat.

Haskell

The language of Elves.

yeah I think so

Not that person but I find that confusing.
How is a reference that hard to do?
We've clearly covered the rest since the C++ code doesn't prevent the camera object from modifying the person (though that'd likely be unintentional).

You should probably keep a list of all the Persons somewhere and have the camera keep the index of the followed person instead of a direct reference.

That's what you'd think, but...
gist.github.com/7ba9ce731bc0828e38e5e410393d6f23 (couldn't post link directly to play.rust-lang.org because spam detection).
The borrow checker doesn't like the code even though it's perfectly valid. You may be able to fix it with Rc though.

Why? We know very little about the choices concerning person here. A reference allows for very few code modifications in the event of change compared to an index.
So there's no way to express non-owning reference in Rust?
What's

then just learn the python data science stack. how would R factor into it

OK, here's the Rust way of doing that, and you're not going to like it.

struct Camera {
person: PersonId,
}

struct Person {
x: i32,
y: i32,
}

#[derive(Copy, Clone)]
struct PersonId(usize);

fn main() {
let mut person_table = vec![
Person { x: 0, y: 0 },
];

let camera = Camera { person: PersonId(0) };

for _ in 0 .. 10 {
for person in person_table.iter_mut() {
person.x += 1;
person.y += 1;
}

let PersonId(p) = camera.person;
let x = person_table[p].x;
let y = person_table[p].y;
println!("The camera is at {}, {}", x, y);
}
}

Alternatively you could have an Rc, but that's an even bigger pain in the ass

>So there's no way to express non-owning reference in Rust?
Not that I know of, but I'm not a Rust expert. It's not as easy as you think it is.
>What's

>it's not as easy as you think it is
Yeah that's clear.
>lifetime parameter
Interesting.

Not him (I'm ), but that's some evil code.

kernighan

>So there's no way to express non-owning reference in Rust?
It depends on your lifetime requirements. If there's a possibility that the reference can outlive the stack frame where the referent was created, then the referent needs to live on the heap somewhere, so you use boxes (for exactly one reference) or refcounting (for multiple references). If you use refcounting you need to decide for yourself which references are strong or weak, and how to guard mutation access on the referent (RefCell or some kind of lock).
You have to remember that Rust's standard tools for building data structures are totally unyielding when it comes to mutation and lifetimes. This is by design, because the whole point of Rust is being able to guarantee memory safety in any part of your program where you don't explicitly opt out. There are probably other ways to make this guarantee that are easier to use. But those ways don't exist yet. Rust does.

Will Rust ever be mainstream?

For a myriad of reasons it won't be replacing C. But it could replace C++.

Even then, only if the tooling and ecosystem gets better than C++.

how can it replace c++ if it cant replace go

Hey guys, I want to make an interactive map. The current way I implement this is to painstakingly cut out the regions, put them back together again like humpty dumpty, and listen for button clicks on their id.

Now this is far from an ideal solution. I'd preferably like to define action regions dynamically. All the "action" has to do is just count up one for every click. I can't use pixels because it'd need to be defined for every resolution. I'd rather not simply import google api because a 500 k jpeg loads much faster than that piece of shit. Anyone point me in the right direction?

Attached: gerrymandering.jpg (2160x1080, 216K)

Why can't the camera own the object it follows? Then you have a camera with a person, and a list of non-followed people. What do you actually need the system to be able to do? "Replicate this C++ code" (which by the way is retarded code) is a poor requirement.

How does sorting work in a fp language if you cannot modify the state?

If you're looking to make this yourself, look into Python and the Selenium library for python. It shouldn't be much work at all, probably would come out to something like 30 lines at most.

The simplest thing to do is produce a sorted copy. A better alternative is to not disallow mutable state and instead control it (e.g. State or ST monads) to still be pure.

C is minimalist, if C had string type and provided a way to manage resources i would never use any other language.

C++ is a clusterfuck, no secret, if you stick with a few features, you can live with it but then it's better to use C anyway.

Go is nice, it's a small language and addresses the issues C has. But i don't think it would pass as a systems language.

Rust is a true systems language, very fast, has a small runtime, but even it's original author switched to swift and he thinks it's superior to rust :(

Right now i program mostly in C and Go, sometimes Python. I would like to learn a functional programming language, maybe scheme or haskell but i can't find motivation to do so, since they are not used for anything serious.

r8 my cute code

Attached: 1520081807585.png (1920x952, 81K)

It won't replace Go without becoming huge and supplanting some other common language/ecosystem.

You need a LOT of inertia with something to supplant Google's internally-developed favorites.

My favorite language at the moment is Idris but if you prefer something else then that's cool too.

Thanks user but if you don't like my favourite programming language then you're a total fucking faggot

so this is what using other languages does to people. turns them bitter, turns them angry, fills them with hate

>and he thinks it's superior to rust :(
No he doesn't.

Why?

Why would i ever want to explicitly declare a default function or constructor?

class Foo{
public:
Foo() = default;
}


When is this useful?

that's what i get when i read this
reddit.com/r/rust/comments/7qels2/i_wonder_why_graydon_hoare_the_author_of_rust/

Okay so I don't know C but does getline free the passed argument itself? Because if not, wouldn't that leak memory for every line read except the last one?

That actually doesn't look that bad for Rust.

>I don't think Rust is the last or only language that needs to exist
>I've always been a language pluralist
>I like Swift too
>it took things that Rust tried to do early in its life and ran with them, rather than changing course in the same places Rust did
How the fuck did you get the impression that he thinks Swift is superior to Rust?

en.cppreference.com/w/cpp/language/default_constructor

>How the fuck did you get the impression that he thinks Swift is superior to Rust?
1- he is the creator of rust
2- he uses and works on swift

he should have been flying between conferences to show people how cool rust is

when you have a non-default constructor. the default one is not created in this case.

Yes, I know what a default constructor is. I'm asking why I would explicitly want to specify it.

is ddd a meme for enterprise?
writing a new class for every field feels a lot like overengineering. also feels like trying to do fp in oo langs (newtype etc)

>1- he is the creator of rust
>2- he uses and works on swift
So? Maybe he got burnt out working on Rust and decided to take an extended break, maybe he got offered more money to write Swift, maybe he's simply no longer interested in doing the things that Rust is targeted at and Swift is a better fit for what he enjoys working on now. In all those possible scenarios he could still think Rust is as good as Swift.

Fucking lol.
Rust is beyond saving.

everything used in enterprise is a meme, and a shit meme at that

Is there a nice C++ sockets library instead of the built in C one?

No. Stop relying on shitty bloat.