/dpt/ - Daily Programming Thread

Previous thread: >

Attached: 1531795716178.jpg (1679x586, 164K)

Other urls found in this thread:

github.com/enfiskutensykkel/ssd-gpu-dma
iaeng.org/IJCS/issues_v32/issue_4/IJCS_32_4_19.pdf
cl.cam.ac.uk/~sd601/thesis.pdf
pastebin.com/iqRxzr88
github.com/Cloudnaut/HFFDC
twitter.com/NSFWRedditVideo

What are you working on, Jow Forums?

Attached: karen haskell.png (1280x719, 818K)

>What are you working on, Jow Forums?
Writing a paper about my work on this: github.com/enfiskutensykkel/ssd-gpu-dma

Is it possible to create a vector of vectors in C++, each with different type?

yes

If you use a pointer to a type specialised vector instead, yes.

How? Can you point me in some direction?

Wrap it in a class with some interface

what do you mean by this?

Making a blackjack game in F#
I'm terrible and should kill myself but it's something at least

use monads
i don't know for what

ooh how about comonads

Subtyping is bad for type inference. It's much easier to infer types without it.

Elaborate please.

I'll repeat my question from previous thread

Where do you guys put business logic in MVC applications?

Model isn't suitable for logic involving multiple models or hundreds of business rules
View should be just presentation.
Controller should be just binding model to view.

and static BusinessLogicManagerHelperUtils get messy pretty fast

>Where do you guys put business logic in MVC applications?
Model

>Model isn't suitable for logic involving multiple models or hundreds of business rules
It is.

Why aren't you programming in Red?

Attached: Red_Language_Tower_Logo.png (200x200, 23K)

Of course! If I can't show off my amazing monad skills then what's the point of functional programming?

If you put the business logic that involves more than one model in a model, you are introducing a tight coupling between those models. As applications continues to grow, these models tends to turn into god models, knowing too much. And this will quickly turns into a big mess that is hard to test and maintain.

>If you put the business logic that involves more than one model in a model, you are introducing a tight coupling between those models.
Split your controller up into multiple controllers, one for each model.

>As applications continues to grow, these models tends to turn into god models, knowing too much. And this will quickly turns into a big mess that is hard to test and maintain.
I agree, use multiple controllers and design your application with multiple endpoints.

>people want better C
Literally just C with better standard library, like define the fucking API for threading and add compiler flag for
platforms that supports it. Now do the same for directories and file paths, basic data structures for systems that
support dynamic allocation.
Maybe smarter compiler like, recursive macros and type inference.
Saner types without the _t ending so every faggot doesn't have to rename uint32_t to u32 or allow multiple typedefs.
>Solutions proposed
GC
Uglier syntax than ATS
Name mangling
nonstandard ABI
Anything but what people want from C

Does it make sense to check if something is assigned first, then skip assignment if it's already set. Or should I just always re-set it regardless?

i.e.

if someVar == NULL {
someVar = notNull
}
[/code]
vs
someVar = notNul


My instincts tell me the latter is better in most cases, but I'm not actually sure. In my particular case I'm assigning pointers to structs so there shouldn't be any large allocations or copies that I'm aware of.

Attached: 1388903446260.jpg (226x239, 11K)

It would probably help if I explained why I might do the first one. I'm only going to set this once, like a static variable, but this language doesn't have that.

that's the spirit

Attached: find your Monado.png (503x60, 38K)

how creating multiple models with controllers would help? you still need to process those models together somewhere, so it doesn't really prevent creating god models

In the MVC pattern, a controller can have multiple subcontrollers.

Also, what the fuck is this god model you keep talking about?

Android app problem:
The app detects if the user has completed setup and entered the required person info such as name, phone no and if that is done then it flags the setupCompleted key for the user as true in firebase. The plan is, the next time the user logs in, it detects if they have already completed setup by checking the flag. But since firebase loads data asynchronously, it continues to the setupactivity. If I try to change to the activity in the ondatachange method, the app closes to launcher for a few seconds then launches to the correct activity. The logcat comes up with

"Skipping duplicate class check due to unrecognized classloader"

when the app closes. Any idea how I can make the app "wait" until it receives the flag information from the ValueEventListerner? Below is the function for the check and this currently is the method that causes the app to close for a few seconds.

public void setupCompletedCheck() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference reference = database.getReference("Users").child(user.getUid()).child("setupComplete");

reference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if ((boolean)dataSnapshot.getValue())
startActivity(new Intent(LoginActivity.this, MainActivity.class));
else
startActivity(new Intent(LoginActivity.this, SetupActivity.class));
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}

None of the langs in the OP are good

it's like being 5'11 king of manlets
OP is king of langlets

Never mind, I have to do the former.
I'm caching data so anyone can call the cache and be the first one to set the address, if I used the second one it would use another address.

>t. chronically buttflustered FP autist that doesn't see his lang in OP
stay mad LMAO

Let's be honest, most anons here aren't smart enough to understand FP or use it productively.

Let's be honest, nobody understands FP or can use it productively because no software has been written in FP languages.

FP is only useful for pointless wankery.

>multiple subcontrollers.
why would that help with anything relevant

>what the fuck is this god model
never heard of "god class", in control of other classes and in effect tightly coupled with all of them, in addition to be giant and hard to maintain?

FP is completely useless

Any language out there that are as fast as those?

Common Lisp

Haskell

By fast I meant fast, not slower than Java.

t. three brainlets sharing half a brain

Prove it.

Attached: Screenshot from 2018-08-24 00-29-27.png (1996x1084, 263K)

Common Lisp is faster than C.

Here, for you.

Attached: butthurt-cream-dawgmaspatentedbutthurtcream1-1024x423.jpg (1024x423, 71K)

iaeng.org/IJCS/issues_v32/issue_4/IJCS_32_4_19.pdf

It isn't.

Attached: Screenshot_2018-08-24 Lisp SBCL vs C++ g++ - Which programs are faster Computer Language Benchmarks (1300x4431, 289K)

I thank you for your evident personal expertise in which butthurt cream is best, but I think you'll continue to need the stuff more than I do.

>posting rigged benchmarks

It's the compiler, not the language that's slow.

How is it rigged?

>refuses ATS2 because fuck you
>forces C solutions to use some suboptimal libraries

Uh,, sweaty, ...

Attached: Screenshot from 2018-08-24 00-39-03.png (1274x652, 115K)

>>refuses ATS2 because fuck you
That's not rigging. ATS is not fast, don't get your hopes up.
>forces C solutions to use some suboptimal libraries
Where did you get that FUD from?

Attached: mstk.jpg (279x343, 39K)

>ATS is not fast, don't get your hopes up
doesn't matter you retard but it is faster than your shitty rust.

Create a vector of pointers to vectors.
Each pointer doesnt really care about the underlying type inside the vector it points to.

>>refuses ATS2 because fuck you
No, that's because no one uses ATS to keep that garbage updated. Hence keeping that shit on would mean updated version that would make ATS worse than it is.

use std::env;
use std::io::{self, Write};
use std::process;
use std::borrow::Cow;

use std::ffi::OsString;
pub const BUFFER_CAPACITY: usize = 64 * 1024;

pub fn to_bytes(os_str: OsString) -> Vec {
use std::os::unix::ffi::OsStringExt;
os_str.into_vec()
}

fn fill_up_buffer buffer.len() / 2 {
return output;
}

let mut buffer_size = output.len();
buffer[..buffer_size].clone_from_slice(output);

while buffer_size < buffer.len() / 2 {
let (left, right) = buffer.split_at_mut(buffer_size);
right[..buffer_size].clone_from_slice(left);
buffer_size *= 2;
}

&buffer[..buffer_size]
}

fn write(output: &[u8]) {
let stdout = io::stdout();
let mut locked = stdout.lock();
let mut buffer = [0u8; BUFFER_CAPACITY];

let filled = fill_up_buffer(&mut buffer, output);
while locked.write_all(filled).is_ok() {}
}

fn main() {
write(&env::args_os().nth(1).map(to_bytes).map_or(
Cow::Borrowed(
&b"y\n"[..],
),
|mut arg| {
arg.push(b'\n');
Cow::Owned(arg)
},
));
process::exit(1);
}[/code[]

`yes` in Rust. I dare you come up with an ATS port faster than this.

cl.cam.ac.uk/~sd601/thesis.pdf

>use std::borrow::Cow;
Cow::String is one of my favorite things in Rust. For ergonomic reasons.

Holy shit that's the ugliest code I have ever seen and I have seen PHP written by Pajeet.

>c++ slower than c
If C++ ends up being slower than C, you're doing something wrong.
All the additional information provided to the compiler makes it potentially faster than C.

Attached: 1525979701831.png (1200x1400, 502K)

>Lisp is sometimes as fast as C, sometimes faster
So it's faster overall.

It's not an argument. If you want pitty party cute weeb tier syntax go use Ruby, cuteness not my concern.

If I use goto for error handling in C (which I understand is a common use case), where do I report errors?


Foo *foo = foomaker();
if (!foo) {
goto error_cleanup;
}
/* ... */
error_cleanup:
fprintf(stderr, "foo error\n");
/* cleanup stuff */

// or

Foo *foo = foomaker();
if (!foo) {
fprintf(stderr, "foo error\n");
goto error_cleanup;
}
/* ... */
error_cleanup:
/* cleanup stuff */

Yeah it's not that the shooter killed the person, the blood loss created by bullet wound is the culprit.

#define goto_error(msg) do { error_message = msg; goto error; }while(0)

void fn()
{
char *error_message = 0;
// ...
error:
if(error_message) { puts(error_message); }
}

>where do I report errors?
in foomaker before returning NULL

>subtyping makes type inference harder
>NO UR WRONG SOMEONE SPENT YEARS MAKING IT WORK
Perhaps learn to read.

not him, i haven't read it but it's possible this is good, give him the benefit of the doubt

>I dare you come up with an ATS port faster than this.
He won't because he doesn't use ATS. No one does. Even if he did, which means he's one of the 3/4 users of ATS, he knows full well it's not nearly as fast as Rust.

Attached: Screenshot_2018-08-24 Performance Implications of FP in ATS.png (1330x6299, 523K)

I'm not saying it's not good, just that it took a very smart person years to make type inference work with subtyping, so clearly it wasn't easy and subtyping makes type inference harder.

The thing with figuring out is that once a very smart person took a few years to figure it out and share the result it is then figured out for everyone.

It's the way civilisations progress.

Yes, but the solution is a simple extension to unification that does not required you dragging the subtype constraints along. It's pretty sweet and simple if you compare it to all the garbage papers that try to make System-F_

Attached: 1528047390755.jpg (4160x2340, 3.64M)

Attached: 924272FB-4A42-41BB-9E29-7C00D0390079.jpg (402x536, 80K)

It requires an extension to unification. So it makes type inference harder.

>tfw made $1000 so far doing Java homeworks in 3 months
Ah, time for an upgrade. Can't decide if I should get a Note 9 or a Threadripper.

Attached: 1527100908678.png (498x710, 290K)

You're missing the point, which is that type inference is harder with subtyping than without it. That the discovery of how to do it can be reused is irrelevant.

How, senpai

public class Fix
{
public static Function fix(Function f)
{
return f.apply(() -> fix(f));
}

public static void main(String[] args)
{
Function factorial = fix(rec -> x -> x

>solve a fairly easy programming problem
>realize 75% of /dpt/ couldn't solve it in under two hours
Feels good, man. Maybe I've finally started to rise above the CS chaff.

Attached: 1531287821369.jpg (896x960, 99K)

>not posting the problem

I'd go with the first option since it resembles try-catch exception handling, doesn't pepper the body of your function with error messaging and goes naturally with having multiple cleanup options.

if only anons were smart enough to understand OOP as well to use it productively.

I put ad on gumtree, and posted some advertisements around a few uni campuses. The rest was a history.
You won't believe how popular programming courses are, especially year 1 level courses.

Attached: images.jpg (300x168, 7K)

Given a directed graph, a starting node, and an ending node, return whether or not you can ever reach the ending node from the starting node.

Again, fairly easy. But seeing as half the people here can't FizzBuzz...

that's brainlet tier easy you fucking faggot

This is the code so far: pastebin.com/iqRxzr88
Any obvious things to improve?

Man, looking at it like that is a bit embarrasing. Feels like I've been working on it for hours yet it's only 43 rows long.

>But seeing as half the people here can't FizzBuzz...
Can you retards stop with this meme? Everyone can do this.

Strongly disagree. FizzBuzz does have its place, but definitely not for the average web developer. If they wanted someone who did serious backend engineering, then it would be a decent way to see how someone steps through logic, but very few web dev jobs really need anyone who does that.

Then shut the fuck up and post your implementation yourself retard. I still know most of the people in this thread would have trouble with it.

It tests conditionals and loops, which are like the first thing you learn. I think most people can do it within a few days of starting even basic programming.

You'd be surprised. I work in a place where the average developer cannot FizzBuzz. Almost everyone there is paid $50k. Wish I was joking.

void *thing() {
Foo *foo = create_foo();
if (!foo) {
fprintf(stderr, "foo failed");
goto error_foo;
}
Bar *bar = create_bar();
if (!bar) {
fprintf(stderr, "bar failed");
goto error_bar;
}
Baz *baz = create_baz();
if (!baz) {
fprintf(stderr, "baz failed");
goto error_baz;
}

error_baz:
destroy_bar(foo)
error_bar:
destroy_foo(foo);
error_foo:
return NULL;
}

post the graph's api

>I think most people can do
LIE. I’m a physics/math grad and unless you’ve taken some abstract algebra recently, you will be totally loss.

Working on a really efficient program to sync huge files. Until now I didn't find anything better. Yesterday I thought I could drop this because I found rclone.

However rclone doesn't seem to be as optimized as I hoped.

Sharing in case somebody is interested.

github.com/Cloudnaut/HFFDC

I'll commit a powershell script later which wraps the program to backup whole directories.

Why mess up the readability of your function with error messaging when you could just put it all at the end? I'd even dispense with the braces in this one case "if (!foo) goto error_foo;" is perfectly unambiguous.

how would you put it all at the end without getting all the error messages printed out even though only the last thing failed?