/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

jeuxdemots.org/rezo-dump.php?gotermsubmit=Chercher&gotermrel='
github.com/redox-os/kernel
godbolt.org/g/xYHJr9
gist.github.com/pythonesque/5943252fb464b49123fa
doc.rust-lang.org/std/collections/struct.LinkedList.html
doc.rust-lang.org/src/alloc/linked_list.rs.html
twitter.com/SFWRedditGifs

>there exist "programmers" in this thread who know nothing except for curlybrace shitlangs
How do we deal with the langlet problem, /dpt/?

Why does Java stringify null?

If this block of code runs on an array with any null entries, it automatically treats the nulls as strings and prints them with the valid output.

for (int i = 0; i < fourCylinderVehicles.length; i++) {
// TODO: improve logic for excluding null entries from output - incorporate into method?
if (fourCylinderVehicles[i] != null) {
System.out.println("\t" + fourCylinderVehicles[i]);
}

}

It makes debugging and troubleshooting anything working with strings of unknown value a fucking nightmare.

I meant this code:
for (int i = 0; i < fourCylinderVehicles.length; i++) {
if (fourCylinderVehicles[i] != null) {
System.out.println("\t" + fourCylinderVehicles[i]);
}

The previous post was my shitty solution to the problem.

>Java null references
have fun, and write a lot of tests

>Why does Java stringify null?
Why wouldn't it? Why should null be somehow inherently unprintable?

>It makes debugging and troubleshooting anything working with strings of unknown value a fucking nightmare
That problem has nothing to do with strings, but with the fact that the language allows null references and makes them compatible with every object type. Why does it do this? Because its curlybrace predecessors did so. There's literally no good reason for it.

Yeah I figured as much.

Would have liked to just use ArrayList for the vehicles array so I didn't have to fuck around with a bunch of null padding for modifying the array, especially since the finished program takes hundreds of values from a CSV file..

Unfortunately this is a school project and we're explicitly forbidden from using ArrayList in any part of the program.

So I'm not a langlet if I know Python?

>So I'm not a langlet if I know Python?
If you know Python, you're a perma-langlet no matter how many other programming languages you learn. I thought that was obvious.

What makes it even more fucked is the fact that Java throws NullPointerExceptions like it's cool everywhere except the methods you would use to trace/debug/view the output of your program.

What if I know Python, Go and Haskell?

>What makes it even more fucked is the fact that Java throws NullPointerExceptions like it's cool everywhere except the methods you would use to trace/debug/view the output of your program.
So you're telling me it would've been better if your program simply crashed while you're trying to inspect the values and figure out where the nulls are coming from? Brilliant idea, user. You should be a language designer.

>python, go
Not even Haskell is enough to offset that damage.

Say I wasn't a langlet and was interested in running java script from a .html to a terminal over my network. I programmed a bot that handles some basic network requests, and want to be able to login to a website from any device on the network and send commands/java script to it. Any of you nerds know how to do that?

I can work with C++, Java, Python, and a few others. But I know little of HTML and that sort.

Even keywords to search would help.

check out phantomjs

> Go
You should consider getting brain damage in hope of losing memory.

>You should consider getting brain damage in hope of losing memory.
Well I also know Rust so...

>Rust
Why do people do this? It doesn't make real low-level systems programming any safer than C/C++, and it doesn't do high-level programming as well as real high-level programming languages.

I need to view the standard error of a plugin which is loaded in a GUI program. This is trivial on GNU/Linux, but how do I accomplish the same in Windows?

>It doesn't make real low-level systems programming any safer than C/C++
False.
>it doesn't do high-level programming as well as real high-level programming languages
False.

Getting into node.js. It's pretty unsettling when you're not used to that sort of stuff.

fetchHTML: function(term, rel, htmlFetchedCallback){
var url = 'jeuxdemots.org/rezo-dump.php?gotermsubmit=Chercher&gotermrel=' + term + '&rel=' + rel;
request.get({url: url, encoding: 'binary'}, function(err, response, body) {
debug('Fetching HTML from ' + url);
var enc = charset(response.headers, body) || jschardet.detect(body).encoding.toLowerCase();

if(enc !== 'utf8') {
var iconv = new Iconv(enc, 'UTF-8//TRANSLIT//IGNORE');
body = iconv.convert(new Buffer(body, 'binary')).toString('utf8');
}

var $ = cheerio.load(body);
var code = $('CODE').contents().text();
htmlFetchedCallback(code);
});
}

>thinking his denial alters objective reality
But it doesn't, user.

I realized what a piece of shit Node was after trying Erlang, C# and Go in that order. You should look into these, they seem to be picking up some pace this year in the webdev scene.

>objective reality is whatever I say it is
Rust does make real low-level systems programming safer than C/C++, even C-tards mostly agree on that, the only possible argument is about the cost.

...

>jeuxdemots
This is familiar. So we have some lirmm people posting on Sup Forums.

>Rust does make real low-level systems programming safer than C/C++
How is it safer when you have to use unsafe features for any serious work, user?
>b-b-but it lets me put unsafe operations in unsafe blocks and then hide them behind an interface and use it in safe code
>and the safety of the safe code makes the code inside the unsafe blocks magically safe
user, that's delusional.

ayyyy, how do you even know about that?

Fine you snobby cunt, get some logic programming in OCaml instead.

(* Returns the expression in its recursive CNF *)
let rec simplify ?(i=0) expr =
print_endline (String.concat "" ("Simplifying: " :: String.make i ' ' :: string_of_expression expr :: []));
let result =
match expr with
Atom (x,y) -> Atom(x,y) (* P(x) ---> P(x) *)
| Not x ->
(match x with
Not a -> x (* ¬¬A ---> A *)
| And (a,b) -> Or( Not(a), Not(b) ) (* ¬(A ∨ B) ---> ¬A ∧ ¬B *)
| Or (a,b) -> And( Not(a), Not(b) ) (* ¬(A ∧ B) ---> ¬A) ∨ ¬B *)
| _ -> Not(simplify ~i:(i + 1) x)) (* ¬A ---> ¬A *)
| Or (x,y) ->
(match (x,y) with
_, And (b,c) -> And( Or(x,b), Or(x,c) ) (* A ∨ (B ∧ C) ---> (A ∨ B) ∧ (A ∨ C) *)
|And (a,b), _ -> And( Or(a,y), Or(b,y) ) (* (A ∧ B) ∨ C ---> (A ∨ C) ∧ (B ∨ C) *)
| (_,_) -> Or( (simplify ~i:(i + 1) x), (simplify ~i:(i + 1) y) )) (* A ∨ B ---> A ∨ B *)
| And (x,y) -> And( (simplify ~i:(i + 1) x), (simplify ~i:(i + 1) y) ) (* A ∧ B ---> A ∧ B *)
| Implies (x,y) -> Or( Not(x), y) (* A => B ---> ¬A ∨ B *)
| Equivalent (x,y) -> And( Implies(x,y), Implies(y,x) ) (*A B ---> (A => B) ∧ (B => A) *)
| Forall (x,y) | Exists (x,y) -> skolem ~i expr in
if expr = result then
result
else
simplify ~i:(i + 1) result;;

That's better.

Because I did my thesis of compiler theory at lirmm.

>there are people on Sup Forums that were involved with lirmm at some point in their life
Well fuck me silly.

>What are you working on, Sup Forums?

Some graph clustering algorithms!

basically I've got friendships between lolis represented as a weighted digraph with a vertex for each loli and weights in [-1, 1] for how much one loli likes another one (-1 is hate, 1 is adoration).

I decided I might as well make use of this when planning group activities (say, at a school), so that friends get grouped together at lunch-hour (although right now the lolis just stay in their desk from 7:30am-2:30pm without moving...)

I basically just threw together some ad-hoc approach of greedily merging together vertices subject to some minimum friendship threshold, then if there are any over-sized groups (I have that as a parameter) just recursively subdivide them by removing the lightest edge until it breaks up into components smaller than the max).

Then just greedily disjoint-union-merge them together in a secondary phase to see if any of the smaller groups were split up by the process, but could still be joined based on the original threshold (ie maybe {1, 2, 3, 4}, {5} were the ones, but then it broke into {1, 2},{3, 4}.,{5}, then you find you can merge it into {1, 2, 5}. {3, 4}.)

Probably a terrible way of doing it since I just pulled it out of my ass and I don't really know much about spectral graph theory methods or anything, but oh well. Should suffice for what I'm using it for, and is fairly simple.

>he still thinks having unsafe somehow compromises Rust
>he still thinks Rust programmers are unable/prohibited to write unsafe code when it's the best way to go
>he still thinks "unsafe Rust" is somehow worse than C code
>he still thinks 1% unsafe code is the same as 100% unsafe code
Now go ahead and tell me about double-linked lists for the thousandth time and post some ugly Rust type signatures you yourself came up with, that would be a great argument.

why is unsafe rust wrapped in safe rust better than making your c or c++ code safe?
C++ is pretty easy to make safe, so why switch at all?

And here's the trick or treating.

>using the versioning jew

what does safe even mean?

buzzword used by dumb non-programmer weenies

> why is unsafe rust wrapped in safe rust better than making your c or c++ code safe?
"I'm pretty sure the code is safe - I've read it, like, two times" and "the compiler guarantees the code is free from these popular types of memory errors and data races" is two completely different tiers of safety. Having 1% of the former and 99% of the latter is better than having 100% of the former.

I meant to note that this is an example of where I could use it. I could make a weighted digraph mixing the friendship digraph + one related to distance (so only girls who live roughly nearby would go out together).

Well, what should I work on now tonight?

>he still thinks you can spam unsafe blocks all over the place and call your program safe as long as they're hidden behind an interface
>he still thinks rustlets can tell when unsafe code is appropriate, and don't screech at you autistically for not using types like Rc and suffering from reference counting and dynamic borrow checking overhead in performance-sensitive kernel code
>he still thinks "unsafe Rust" is somehow better than C for the sort of things "unsafe Rust" would be used for
>he still thinks his fizzbuzz projects reflect the real system programming
Rustletism is a legit mental illness. I hope you get better, user, but I'm glad people like you have a containment language for now.

>"the compiler guarantees the code is free from these popular types of memory errors and data races"
Only applies to your fizzbuzz projects. Does not apply to any real low-level system code.
>muh 1% of fizzbuzz
Not a valid argument.

>Only applies to your fizzbuzz projects. Does not apply to any real low-level system code.
and no evidence to back that up, of course

C - I'm getting "warning: extra tokens at end of #ifdef directive"

and it's pointing at the underscore of:

#ifdef PTHREAD _SYNC

Code works fine, but want to remove warnings. I have it defined as:

#define PTHREAD _SYNC

at top and I'm closing all my #ifdef with #endif of course.

Why?

>can't even make a doubly linked list without performance penalties and excessive verbosity, let alone more realistic and complex data structures
>can't have multiple mutable references
>s-s-system programming is all about transforming immutable trees! prove me wrong!

Because you're a retard that put a space before the underscore.

An actual kernel github.com/redox-os/kernel has 7.5% unsafe code, m8.

I've been using LD_PRELOAD with wine in order to do some botting, but now I'm going to try and use it to get false frames in order to get fluent input but low fps (and specialy, low cpu usage) in WoW. Which opengl funcions consume the most cpu typically?

so you only have to audit 7.5% of the code?

This is why I love Sup Forums.

>An actual kernel
That's not an "actual kernel", kid. That's a fizzbuzz.

You're such a bad troll, why are you even here anyway?

You have to audit all the code because memory errors and data races are only a subset of all possible errors. But you can be reasonably sure you don't have use-after-free, double-free and data races in 92.5% of your code, which is a nice guarantee to have, especially coming from inherently unsafe languages like C.
>I can dismiss any argument by crying "fizzbuzz!" for long enough
Why do I even bother?

Just because a program is memory safe, doesn't mean it is correct.

That's wrong, you know?

data races are solved by using mutexes.
memory errors can be divided into out of range, double free or other "use after free" or memory leaks.
You can make sure everything is "safe" by following good practices regarding memory.
Smart pointers have solved most problems.
I see they also mention undefined behaviour but this is usually solved by rejecting commits with compiler warnings.

>being unable to grasp the difference between someone's OS class toy project and a practical kernel
That's a symptom of mental illness. I could write a grossly inefficient toy kernel in 90% pure functional style. Still wouldn't make immutable tree structures an appropriate choice for kernel programming.

FBIIIIIIIIIIIIII

>lolidev will complete a project before I even start one
It hurts.

Lmfao epic

You should implement something similar to allow selling their mothers for quick cash.

thats probably it, but it was provided by my professor like that with the space so it ain't all my fault. thanks

which libraries (if any) do you use?

>You can make sure everything is "safe" by following good practices regarding memory.
You can't, you can significantly reduce the possibility of an error, but you can't be sure about something that's not automatically checked. Besides, good luck enforcing such practices in a serious project and not turning it into OpenBSD-tier gulag.
>Smart pointers have solved most problems.
Sure, but they aren't enforced.

The problem with Rust is that it has a built-in backpedal mechanism for every claim and promise it makes, and that allows for the kind of schizophrenic attitude that the average Rust acolyte develops. The Rust compiler should enforce a limit of 7.5% unsafe code in every project and enforce "safety" on rustlets the rest of the time, so that the rest of the industry could observe you monkeys trying to do mostly "safe" programming and see what kind of projects your community generates in the next 15 years.

Ofcourse you can make safe code in any language, the language is just about making it easy to do the right thing.
Some problems are too hard to detect so you must check it at runtime in order to see if it is safe.
People use unit tests for this.
They make a small example code and then they run it so they can get some statistics about the new version of the application every time they build it.
It can take a long time if the problem is complex, but you can automate these things so it doesn't slow down the programmers.
As for enforcement, you enforce it by having a coding standard.
If everyone is doing things the same way as you, it is very easy to read what other people are doing.
It can cover how you are testing stuff too if you need this.

OpenBSD rules

These are the same arguments fans of dynamic typing use to claim static typing is unnecessary. Of course, you can (and should) write test, use run-time checks and code standards, but it's always good to have the compiler statically enforce as many invariants as possible.
Maybe, but it's still gulag.

Smart pointers do have overhead. Generally in the form of memory for ref counting, and a little time for constructors / destructors (unique_ptr & shared_ptr) and assignment(shared_ptr)

"Safe" C++ code will usually make the same / similar performance trade offs to rust.

>Smart pointers do have overhead.
Neither std::unique_ptr nor Box have any overheads.
>a little time for constructors / destructors
You have to construct/destruct objects anyway, it's not an overhead.

std::unique has overheads for if you provide a non trivial deleter.

As for constructors / destructors even if you're just using a basic int pointer it introduces at least 2 calls for a constructor and destructor that wouldn't necessarily exist for a raw pointer.

The "overhead" they have is not larger than the code you yourself would have written to manage dumb pointers manually.

Dynamic typing is underrated.

Reminder:
Rc

overrated, sucks to implement and not even decidable generally, so you can never be sure

>sucks to implement
Not true, you technically need less checks
>not even decidable
Literally makes no sense. Stop spitting out these fancy terms they taught you at college to describe things that have nothing to do with them.

> std::unique has overheads for if you provide a non trivial deleter.
But has none if you don't.
>even if you're just using a basic int pointer it introduces at least 2 calls for a constructor and destructor that wouldn't necessarily exist for a raw pointer
godbolt.org/g/xYHJr9
You can't avoid calling constructors even with raw pointers, but you're right, you can avoid calling destructors, this advanced optimization technique is called "memory leak".

Memory leaks aren't the only way to avoid calling destructors. Some allocators do this.

>github
*internally pukes*

You mean in-place new? Sure, you can reuse the same memory for a new object, but you still have to call destructor of the old object before that, even with raw pointers.

i was going to learn rust, but Sup Forums told me you can't even have a safe and efficient doubly linked list in it, so i'm reconsidering... is it true? can you show me a way to implement a doubly linked list in rust safely and without reference counting/dynamic borrow checking overhead?

So I just committed a fucking marvel of software engineering, built to spec and to every industry best practice, tested, documented, the works. Yet it’s a completely useless piece of shit. Turns out good software engineering isn’t a magic pill after all.

Reminder to ignore the unsafe rust troll, he's already getting desperate with baits.

Anyway it’s a combination of an unrealistic spec and technical limitations I’m still a brainlet for not catching it in time and coming up with a better solution.

SFML for graphics and JSON11 (dropbox) for JSOn parsing.

I thought about allowing kidnapping of adults to use as breeding cows.

so you mean it's just one guy trolling? but then how do i do the thing he says you can't do?

Why are you making such a gross game. You still have time to repent.

gist.github.com/pythonesque/5943252fb464b49123fa

Does this count for your linked list requirements?

No I am not talking about in-place new.
No idea why you are asking me, I am not a Rust programmer but I am pretty sure you are memeing here. No idea why you would want to re-implement doc.rust-lang.org/std/collections/struct.LinkedList.html I am not even sure if one is able to implement a linked list "safely" in c/c++ either so.

>Does this count for your linked list requirements?
i don't know. is mem::swap/mem::replace safe? do the boxing and option things have overhead?

>No idea why you would want to re-implement doc.rust-lang.org/std/collections/struct.LinkedList.html
i wouldn't, but if i couldn't do that safely and efficiently, i have a hard time believing you could do actually complicated stuff safely and efficiently, so maybe the troll is right?

boxing / option should compile into basically a normal sized pointer or object for that type.

mem::swap and mem::replace should be 100% safe if I'm remembering correctly.

source code when

hmm... but why does this have so many unsafe blocks if you can have an equally good safe version?
doc.rust-lang.org/src/alloc/linked_list.rs.html

less compile time, more run time. you still need to throw errors on invalid types, you just do it in the run time

>commie propaganda
No fucking wonder who is behind shit threads

That is about the same as asking why so many code bases made in modern c++ still use raw pointers when you've got shared_ptr, unique_ptr, and weak_ptr.

It made more sense to the programmer doing the implementation or they're more comfortable using that method.

Not him and also I don't know Rust but what exactly is even wrong with just using Rust and putting unsafe everywhere?

Literally why not just do that? You act as if anyone using Rust is somehow inherently obligated to actually want their code to be safe at all costs.

SO's articles claim Kotlin's one of the fastest growing languages. Is it that good, or is it just another meme?

>That is about the same as asking why so many code bases made in modern c++ still use raw pointers when you've got shared_ptr, unique_ptr, and weak_ptr
that's not true... c++ is much older, and it wasn't conceived with an emphasis on safety from the beginning

>It made more sense to the programmer doing the implementation or they're more comfortable using that method
so you're saying there's no real reason for it? they could've done it safely but just chose not to? maybe the rust devs just know something you don't