/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

doc.rust-lang.org/book/error-handling.html#the-real-try-macro
doc.rust-lang.org/book/error-handling.html#composing-custom-error-types
doc.rust-lang.org/std/error/
tiffzhang.com/startup/
twitter.com/NSFWRedditVideo

First for D

>What are you working on, Sup Forums?
Reading K&R. Just started 1.6 Arrays

First for D

why is this printing out 5?

s = 'azcbobobegghakl'
num = 0
for i in s:
if i in 'bob':
num+=1

print ('Number of times bob occurs is:' + str(num))

Theres nothing in there that would even suggest 5 that i can see?

filter (`elem` ['A'..'Z']) "i lauGh At You BecAuse u r aLL the Same"

CodeEval challenge: String List

Should I drop the beginner book to C now and start on K&R the only things left talk about creating functions which I have a good knowlege about.

>if i in 'bob'
>if i is 'b' or i is 'o'

K&R is outdated
C Primer Plus
C Programming: A Modern Approach

bob is an array of two b's and one o.

>C Programming: A Modern Approach
that's an oxymoron though.

yes. books are for nerds
just code, man

Can someone here assist me with OpenGL? My program generates absolutely no errors but there's no output.
I'll save you from reading the source code as I'm just looking for advice

I've checked the vertex data and the data on the buffer at the time of glDrawArray, and that's OK; the vertex data is perfectly what I intended it to be.

I used GLM to create a projection matrix and applied the transformation in my vertex shader.

I've checked that the VAO and VBOs are generated, they are. They're also bound before glBufferData or glDrawArray.

I've checked the size of glDrawArray and it's perfect.

I've checked that textures work. They do. A debugging program tells me that GL_TEXTURE0 has the image loaded into it, anyway. No other texture units in use

I don't think my camera is inside the geometry- I've checked the depth buffer.

I honestly don't know what else to check. any suggestions?

Attached is an image of the depth buffer, with no alpha. With alpha it's all white.

>when you discover abstraction
How long did it take for programming to click with you?

Go home GCC, you're drunk.

|n| (2..n).take_while(|d| d * d < n).all(|d| n%d > 0)

>What are you working on, Sup Forums?
Django

>C++

Not even once

V E X I N G
E
X
I
N
G

There's a lot of reasons this could be failing. Were you able to successfully draw a triangle with no texture? No depth test? No vertex transformation? No shader at all?

When I run Python through notepad++ it won't do stuff like download images or show errors.

What gives, lads?

I don't want to use a shitty IDE.

I don't understand what's ambiguous about it.
It is quite clearly a function declaration, I'm not seeing any syntax or semantic errors anywhere.
I don't understand why g++ is complaining.

>notepad++

Do you have a variable called "time" anywhere?

how can people watch this mlp tier shit

same reason people like you get robbed and shot up.

cuz you're a punk ass bitch.

you forgot closing } in previous function

it thinks you're trying to create a static bool variable with the parameters

No, I have a class called time though.
Clang came to the rescue and showed my error. it seems the time function from time.h was causing the problem, why the fuck would it though? time from time.h is a function, while my time class is a class, how is that ambiguous?

I doubt you even go outside

And this is why namespaces exist.

Nope.

>C++ is so dumb it can't differentiate between a function name and a type name.

Oh, and it thinks it's ambiguous because it's seeing "time" as a value, parsing (time & t) as an application of the binary & operator, and parsing the whole thing as an initialization.

Use cmd.

It's still the reason you use a namespace. #include instead of .

My reddit interjector bot fucked up and replied to everything containing arch including the word "search"....

Use Sublime Text 3, and run your scripts through your command prompt/shell

and i bet you haven't seen the outside of your mothers ass since you're just constantly turtling like the little shit you are.

Then don't use C++ if it's not suited for you?

Did you get banned yet?

I was instructed to come and ask here : I want to make a program for Windows, with which I'll be able to command my PC with gestures (Kinect). It's for educational purposes and my own satisfaction. I would be really grateful, if anybody could provide any quality tips, materials, code help and this kind of stuff (beginner level programist). Even smallest things will be good.

What's the No Man's Sky of programming?

better watch some barney to calm down

rand();

That didn't solve the problem.
I don't think c is guaranteed to not put them in the global namespace anyway.

learn python, figure it out from there

Ah, that's true, but it's still good practice. Using the new function signature syntax could remove the ambiguity:
static auto parse_time(time &t, std::string &m) -> bool

Something that was a huge disappointment built on a web of lies and broken promises?

Go

Putting my whole program into a namespace seems to have solved the problem.

Learning Rust by making an RSS downloader.
I'm currently stuck with this:
use std::fs::File;
use std::io::Read;

extern crate serde_json;

static PATH: &'static str = "~/Projects/rss/config.json";

#[derive(Deserialise)]
pub struct Config {
urls: Vec
}

impl Config {
pub fn read() -> Result {
let mut file = try!(File::open(PATH).map_err(|e| e.to_string()));
let mut content = Vec::new();
try!(file.read_to_end(&mut content).map_err(|e| e.to_string()));
let config : Config = try!(serde_json::from_slice(&content)
.map_err(|e| e.to_string()));
Ok(config)
}
}

error[E0277]: the trait bound `config::Config: serde::de::Deserialize` is not satisfied
--> src/config.rs:18:36
|
18 | let config : Config = try!(serde_json::from_slice(&content)
| ^^^^^^^^^^^^^^^^^^^^^^ trait `config::Config: serde::de::Deserialize` not satisfied
|
= note: required by `config::serde_json::from_slice`

error: aborting due to previous error

error: Could not compile `rss`.

hell ye

>Deserialise

Well, fuck...
Apparently that's the issue.

Unfortunately you have to get used to the standard being American English in programming.

You need a specific #feature to automatically derive Deserialize from serde iirc (you could use rustc-serialize instead and #[derive(RustcDecodable)]).

I'm using Rust nightly and I've added this to main.rs:
#![feature(plugin, custom_derive)]
#![plugin(serde_macros)]

So far, I'm pretty happy with Rust. I wonder if I can do something about those map_err() though.

Maybe use your own Errortype? What you want is pretty much described in the book:
doc.rust-lang.org/book/error-handling.html#the-real-try-macro
doc.rust-lang.org/book/error-handling.html#composing-custom-error-types

Alternatively use Box instead of String, removes the need for .map_err()

Thanks anons. This is what I currently have:
use std::fs::File;
use std::io::Read;
use std::error::Error;

extern crate serde_json;

static PATH: &'static str = "/home/bas/Projects/rss/config.json";

#[derive(Deserialize, Debug)]
pub struct Config {
urls: Vec
}

impl Config {
pub fn read() -> Result {
let mut file = try!(File::open(PATH));
let mut content = Vec::new();
try!(file.read_to_end(&mut content));
let config = try!(serde_json::from_slice(&content));
Ok(config)
}
}

It looks pretty clean to me. requires me to write boilerplate, so I prefer the Box method. However, is it best practice to use Box like that?

> a human can't beat a compiler because ITS 2016

It is at least preferable to String because:

1: The Error trait provides a description() method returning a &str, removes the need to convert to String in the first place.

2: Unlike String, provide a cause() method, returning the lower-level Error if it exists, thus providing more information.

From doc.rust-lang.org/std/error/

I'd really recommend reading the chapter on Error handling in the book, as it explains idiomatic error handling really well.

Tl:dr: If you don't want to write your own Errortype, use Box instead

Is learning to use GitHub hard?

I'm feeling lost Sup Forums, I'm currently working in .Net but while I enjoy both F# and C# I'm getting tired of the rituals of having project files and solutions. I've been looking around but while other languages have better ideas and executions there is nothing that feels great. Always something that nags in my head. In rust it's the method chains needed to make anything useful but ends up reading like crap. In go it's the type system. OCaml I haven't tried because the tooling on Windows is crap. Haskell has its love for operators and also the wall you need to climb before you can start being proficient. I just want a general language that I can use and make tools for me in. But instead I waste time jumping around. Ugh.

>If you're writing a quick 'n' dirty program and feel ashamed about panicking anyway, then use either a String or a Box for your error type.
That will work just fine for my application.
I did finish reading the Rust documentation a few weeks ago. This is my first time writing Rust instead of looking at examples.

Learn git instead,

learn Haskell, it's not as bad as it looks

make sure you're using an editor that will show you errors as you type though

But what :/

Git is such an incredible tool. It's a little weird when you first start using it, but as soon as you get a good workflow going it's hard to go back

and that's why i do security

How do i get addicted to this and stop gayming?

Install Gentoo

Grow up

how do i create a killer app so i dont have to get a job?

Right now the Haskell community is going through some civil war shit with stack and haskell-lang and from the outside it looks pretty childish. Not sure what to think about that.

love this meme

>civil war
Explain

How bad is it that I never use virtualenvs for my Python projects?

go to tiffzhang.com/startup/

Whatever it gives you you slap it together in 2 days or so using node.js, Rust or Go, then get a .io address and start shilling on HN and Reddit

Guy who created Stack (a build tool for Haskell) claims the Haskell devs are trying to shut him out by not shilling his program on their website

He did make some valid points but at the end of the day it's clear his real goal is to become "the Haskell guy"

Like I said this is from my outside perspective but the people behind fp complete, the makers of stack, aren't happy with how Haskell.org is run and have registered their own domain (haskell-lang.org) which they are promoting over the official site. They also prohibited Haskell.org from using the design that had been donated, because the guy who made it is with fp complete. Then there's been some weird blog posts from another fp complete employee where the tone is more fitting of a school yard than a debate about how things should be run.

But this is just what I've gathered from what I've read. Might have misunderstood things, but this is how I'm seeing it and it makes me wonder if I should learn it or wait.

oh my god

Sup Forums in a nutshell

Humans and compilers are both good at different kinds of optimization.

Oh wow. Thanks for the info.

I have no idea about what this is

so we can agree only traps and muhe.peen faggots code in hasklel?

Explain how with an algorithm

Wew, seems pretty retarded.

for (;;);

>you will never be forced by your cute girl classmates to dress as a girl
;_;

What tags do I use to put source code in boxes?

stuff


with [square] brackets

Wth are you defragging an SSD?

class foo
{
public:
int a;
};

class bar : public foo
{
public:
int b;
};

int main()
{
foo *f = new bar;
delete f; // new-delete-type-mismatch from ASAN

return 0;
}


Apparently this is undefined behavior in C++.
How the fuck am I supposed to do polymorphism with this shit?

import Control.Monad
import System.Environment

alphatri' c = let xs = ['a'..c] in xs ++ (reverse . init) xs

alphatriList c = map alphatri' ['a'..c]

indent 0 = []
indent n = [replicate (n-1) ' '] ++ indent (n-1)

indentList c = indent $ length ['a'..c]

alphatri = zipWith (++)

main = do
args

virtual destructor

why are name examples in code always foo bar?

what do they mean?

You need to indent your public, private, etc declarations.

Yeah I'm retarded, I just figured that out.

No I don't, why do I?

what are you trying to achieve?

chaotic map rendering program now on github if anyone wants to tinker with it or contribute code