[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 334
Thread images: 27

File: prog.jpg (105KB, 473x496px) Image search: [Google]
prog.jpg
105KB, 473x496px
Old thread: >>60820727

What are you working on, /g/?
>>
nth for the power of
.chars().next().unwrap();
>>
>>60825463
>nth
How ironic, you can actually do
let c = s.chars().nth(0).unwrap();

as well, still need the iterator though.
>>
what are some good sources to learn functional programming?

i'm a backend webdev and i need to step my game up
>>
>>60825498
i'll shit on webdev any day but functional programming would honestly be a step down from backend webdev
>>
>>60825482
2.0 better get a syntax overhaul.
>>
>>60825548
what do you mean by this?
>>
>>60825553
>>60825482
>>
>>60825563

>Rust is functional programming
>>
>>60825549
try
""[1]
or
""[2]
in your favorite shitlang and tell us what happens. For some, exceptions are an acceptable tradeoff, for arustyian herrenrasse members, not.
>>
>>60825584
appending an empty char?
>>
>>60825498
>webdev
>functional programming
cum on step it up
>>
>>60825580
that's where the autistic let, iterator and unwrap crap comes from. pure fp languages are even worse

firstTruthy :: Monad m => (a -> Bool) -> [m a] -> m (Maybe a)
firstTruthy f = foldr
(\x r -> x >>= uncurry (bool r) . (return . Just &&& f))
(return Nothing)
>>
>>60825563
>>60825620
i dont know what either of you are talking about and neither one of you answered my question.
>>
>>60825683
just look at that shit >>60825626
>>
>>60825683
Indexing strings in rust
https://play.rust-lang.org/?gist=87182a369df135091b3fb4253e458627&version=stable&backtrace=0
>>
>>60825703
its very general and useful, yes
same program would take many lines in java
>>
>>60825721
What is that even doing, i can barely read simple haskell code.
>>
>>60825703
>>60825709
i didnt say i want to learn a language that strictly follows the functional paradigm. i just want a source so i can improve at writing functions with general languages
>>
>>60825742

functional programming =/= programming with functions
>>
>>60825731
its not simple its very compacted and dense. i agree that its hard to read but it could be stretched out to be more explicit.
it takes a list of monadic actions and a function to accept or reject the result of those actions. it returns the first result that meets the condition supplied and stops executing the actions there. if no actions match, it returns Nothing, or null.

in pseduocode, though a little less general:
a = doFirst() 
if (valid(a))
return a
b = doSecond()
if (valid(b))
return b
...
return null
>>
>>60825742
>i just want a source so i can improve at writing functions with general languages
If you want to learn the functional way, limit the use of mutability, and write as many of your functions as pure, I.E. no side-effects.
>>
>>60825779
so how do i actually improve at solving programming challenges?

>inb4 just do them
on codewars i cant do past a certain level of questions no matter how long i sit and sweat
>>
>>60825787
ah, that helps, thanks lad.
>>
>>60825823

then you ask for help with the bits you don't get until you understand

>>60825814

That's a good rule of thumb even if you're not writing a pure functional language.
>>
Found my new memelang /dpt/. So abstract I cant relate any pic. So far-fetched you cant joke about it.

http://iolanguage.org
>>
>>60825823
>codewars
oh wow, never heard of this before. cool.
>>
>>60825872
whats your point here?
>>
>>60825861
Yeah, also severely limiting the use of POO exceptions ani try-catch as well.
>>
>>60825862
> a language that puts irrational minimalism over functionality
my heart, too bad mines still gonna be better
>>
>>60825894

exceptions are fine if they actually represent exceptional conditions.
they have a place, and that place is not general purpose error handling
>>
File: wedidit.MOV.webm (572KB, 1280x720px) Image search: [Google]
wedidit.MOV.webm
572KB, 1280x720px
BOYS WE DID IT. NOW JUST TWO MORE NUMBERS.

Steps afterwards:
designing pcb
programming a countdown controlled via local webserver
>>
>>60825933
Is its name going to be an obscure pun in italian tho? If not kys
>>
>>60825862
looks like shit
>>
>>60826045
>Woplangs
Absolutely not.
>>
>>60826018
this
>>
>>60826052
>>60826075
va fanculo
>>
>>60826045
ravio.li
>>
>>60826178
nice pasta
>>
>>60825862
>everything is an object
>everyrhing is a message
W E W
L
A
D
>>
I need to make a Counting Bloom Filter in C and i dont know where to start.

In a nutshell, a function needs to read a file with "tweets" in the format "user,tag1,tag2,..." and print the users in order of amount of tags used.

So far I made a split function to work with the tags but I cannot get the rest
>>
how do i turn a lamp on with my phone? i'll need a special type of lamp right?
>>
File: sphere.png (14KB, 415x464px) Image search: [Google]
sphere.png
14KB, 415x464px
>>60825862
https://gist.github.com/anonymous/2d779bef18ead25e924ceaddf1747b14
>>
>>60826691
>working with strings in C
why would you do this?
>>
>>60826691
>So far I made a split function to work with the tags
strtok

>print the users in order of amount of tags used
Store the users in an array and either sort it as you parse the tags or qsort the array after all users are parsed. Then iterate over the list and print.
>>
>>60826704
OMG I just jizzed my pants
>>
>>60826703
1. special lamp: they sell lightbulbs with IoT crap integrated. They connect to wifi and you can control them using (((apps)))
2. special device: replace your switch with a relay, connect that to a mini-pc board (arudino, raspi, cubieboard etc) and you can control those over network.
>>
File: challenge.png (13KB, 516x33px) Image search: [Google]
challenge.png
13KB, 516x33px
is that subtle form of bullying
>>
>>60826885
Kek
>>
>150 lines of code
>already had to use 6 globals
>just realized I will have to add one more
FUCKING INTERRUPTS REEEEE
>>
>>60825429
>What are you working on, /g/?

Homework :(

Is there anyway for getting a C++ iterator to stop and end at arbitrary points in a list?
>>
>>60827335

use break; to terminate a loop early
>>
>>60827323
Don't misuse "REEEEE" for general anger, use it against normalfags.
>>
>>60827366
>Chad programms compilers in his free time while you have trouble with the interrupt homework
>>
>Just had to add another global
>>
>>60827446
>allowing globals to infect your program state
you never "have" to add a global, anon
>>
>>60827504
>Interrupt routine is always called without any parameters
>Only way it can get access to program state is with globals
How else would I change my programs state
>>
>>60827446
Globals are haram.
>>
>>60827554
ASM? What kind of interrupts?
>>
>he still has to worry about global scope
>>
>>60827564
Timer and Button interrupts
Language is C, Chip is from atmel
>>
>inb4 oop a shit
http://www.strawpoll.me/13148484
>>
the anti-globals meme is just something that is taught as an almost absolute to beginners to force them to learn how to properly maintain state and pass it between functions

if you think globals are haram still you need to throw off your training wheels kiddo
>>
>>60827576
You could try using an array, struct or bitfield to organize your global flag variables.
>>
>>60827554
in that case you're fucked
>>
>>60827722
Have fun making a global state riddled program concurrent.
>>
>>60827761
>what is a semaphore

clearly something you never need because global state is verboten!
>>
>>60827722

everything that is evil has a use case, and should be used when it is the least evil of the options

globals are evil does not imply never use globals
>>
File: Me.jpg (3MB, 2162x2162px) Image search: [Google]
Me.jpg
3MB, 2162x2162px
Stop using so many abstractions
Stick to the basics
Learn how TTL/CMOS works
guise
>>
>>60827761
If you're worried about that, you aren't Enterprise Software-ing hard enough
>>
>>60827878

Z E R O C O S T
E
R
O
C
O
S
T
>>
Where should I focus learning?

Android, iPhone, web, or games development?
>>
>>60827894
Esoteric Fizz Buzz
>>
>>60827829
>global state is verboten
Most use cases don't require the use of global state. You should only use it when you absolutely have to. Lisps have a good balance between state and stateless code.
>semaphores
They destroy performance.
>>
>>60827894
Start by learning how to learn
>>
>>60827894
Learn to weld.
>>
>>60827894
your choice
>>60827906
this though
>>
Is Netbeans shit? I'm learning Java (school requirement) on Mac and I'm running into a lot of buggy menus and compiler errors. Whats a good compiler for Mac?
>>
>>60828018
Netbrains isnt a compiler anon.
Edit your files with vi and compile with javac
>>
>>60828018
I use Netbeans for Java and C but I'm also a pseudo Pajeet so take that as you wish
>>
>>60828018
It's shit
>>
>>60828018
https://www.jetbrains.com/idea/

also, not a compiler
>>
Is Rust without the borrow checker the perfect language?
>>
>>60828116

isn't the borrow checker the whole point?
>>
>>60828116
see >>60828124
also, the syntax is shit
>>
>>60828116
Rust without the borrow checker would be C++ with worse syntax
>>
>>60828124
Originally, but Rust has tons of good features that stand out on their own, but the borrow checker really gets in the way of good design sometimes.
>>
>>60828144

For example?
>>
>>60827894
al-Qurʾān, brother
>>
>>60828148
I can't segfault anymore :(
>>
>>60828141
Wait, so C++ has tagged unions, pattern matching, traits, modules, a good build system, and a good standard library?
Well shit, C++ must have really changed since the last time I used C++14 half a year ago.
>>
>>60828167

> tagged unions
I'm pretty sure this is in C++17 as std::variant.
>>
>>60828167
>pattern matching
Can be implemented
https://github.com/mpark/patterns
>>
>>60828148
Try calling a method that takes a
&mut self
and returns a
&mut T
within a method that takes
mut self
while self is immutably/mutably borrowed.
You'll get the borrow checker screeching at you for perfectly fine code.
It's unnecessary, and only stops retard programmers.
>>
>>60828167
Sorry, I'll also add with half-assed FP
>>
File: 1490197910283.jpg (124KB, 874x874px) Image search: [Google]
1490197910283.jpg
124KB, 874x874px
>>60828167
Get/index the first character of a rust string.
>>
>>60828182
And they're trash.
Can't even pattern match against them.
>>
>>60828216
I'd rather have native UTF-8 encoded strings.
>>
>>60828216
"niggers".as_bytes()[0];

It even explicitly states that you're assuming the string to be an ASCII string.
>>
>>60828250
>O(n)
this should be an O(1) operation anon
>>
>>60828198
Pretty shit compared to Rust pattern matching.
>>
>>60828272
It is
>>
>>60828272
It is O(1), you fucking retard.
https://doc.rust-lang.org/std/string/struct.String.html#method.as_bytes
It literally just coerces the string slice to a u8 slice, allowing it to be indexed in O(1) time.
>>
>>60828250
>It even explicitly states that you're assuming the string to be an ASCII string.
no it doesn't
the literal documentation for as_bytes is
>Converts a string slice to a byte slice.
>>
>>60828303
Exactly.
Byte slices in the context of strings are ASCII strings.
>>
>>60825742
Functional programming is a religion. What I recommend is that you stick to imperative languages and prefer pure functions. That's the sweet spot.
>>
>>60828328
So, implicitly, then.
>>
>>60828340
It's more explicit than just
"niggers"[0]
.
I think it's pretty damn clear that the as_bytes() call states that you're assuming the string to not be unicode at least.
If you're so anal about it, just alias as_bytes() to as_ascii().
>>
File: 1477817351847.png (307KB, 500x500px) Image search: [Google]
1477817351847.png
307KB, 500x500px
Now I'm curious, how do you work with utf-8 encoded strings in c++?
>>
>>60827894
Don't do games.
It really isn't a career unless you're the kind of person that really likes making games to the point where you'd make serious social and economic sacrifices. The crunch is brutal. I imagine app or web is much more lax because the deadlines aren't as strict. You don't have millions of dollars of marketing for your app riding on you having a bug free and feature filled release at a date that was planned at least half a year ahead of time.
>>
>>60828397
Very carefully
>>
>>60828397
You don't care. Just use std::string or char *.
>>
>>60828408
This.
Most of the time you can ignore unicode without breaking it.
>>
>>60828397
std::string does it but it really is awful.
>>
>>60828423
Indexing strings is the first step toward breaking it.

>>60828440
>awful

Why?
>>
Unicode should just be outlawed, and we should all just go back to ASCII again.
Who cares about other languages. It's their fault for not using the global standard.
>>
>>60828405
I was thinking more along the lines of indie, rather than corporate, but fair point.
>>
>>60828467
Utf-8 really isn't hard.
>>60828476
Well they're simply poor.
>>
Is there a subset of the C++ standard library for freestanding code? Basically I want to use some C++ STL stuff like std::move and std::optional/variant without having to learn the arcane arts of wizard level template magic to implement them for myself.
>>
>>60828535

So just use that stuff then? I don't see why you'd need to become a template expert to use move semantics and a few containers.
>>
>>60828616
Because it's freestanding code, specifically a kernel, so I can't "just use them" because they're not there, obviously.
I do have my own implementation of std::move, but I'm not wizard level enough in C++ templates to do anything more advanced than that.
>>
>>60828651

I'm not sure I understand. Template code doesn't require any kind of runtime, they're baked into the executable. Why wouldn't they be there?
>>
>>60828730
There's no standard library (including STL) when building in freestanding mode.
>>
>>60828745

I see now.
I'm not aware of any such thing. But, is it really that hard to implement things like optional and variant by hand?
>>
>>60828651
I've been experimenting with using the STL for bare metal programming. You'll probably want to statically link in a cstdlib like newlib-nano, and then redefine new and delete so they become noexcept. That way you can call the STL containers which use the heap. This is a good starting point:
https://arobenko.gitbooks.io/bare_metal_cpp/content/
>>
>>60828535
>Is there a subset of the C++ standard library for freestanding code?
For true freestanding stuff, you build it yourself. It's quite a lot of work as you have to do lots of low-level stuff. (It's annoying in plain C too, if that's any help. Math library implementations get very scary.)
>>
>>60828405
My bud from gamedev always tells me that crunches are the best thing ever for him, performing under severe pressure or some shit. Not everyone's cup of tea for sure
>>
What is the best way to get into Java if I am a seasoned C fag?
>>
>>60829346

think of something you'd write in C and just write it in Java instead

You'll probably dislike it
>>
>>60829471
Disagree. Of course he'd dislike it, things you would write in C are a terrible use for Java.

Think of something you WOULDN'T write in C and just write it in Java instead.
>>
>>60829471
trying to do that, looks like C surrogate in jvm so far
b-but I want to use cool fancy java shit
>>
>>60829540

make something with a gui
>>
#include <iostream>

int main()
{
int a=0;
std::cout << a++ << a++ << std::endl;
}

Output:
10

Why is C++ so shit?
>>
>>60829346
Just do some projects.
This is one of my favorite assignments
>https://drive.google.com/file/d/0B4fSUkWFxrM0R1lhQ1l1VXVVQzQ/view?usp=sharing
I did in one of my intro classes, it's a directory/file search thing.
>>
File: IMG_6701.jpg (825KB, 1728x2592px) Image search: [Google]
IMG_6701.jpg
825KB, 1728x2592px
what do i do now
>>
>>60829629
spasiba faam, will do
>>
>>60829621
Hurr why does this undefined behaviour behave this way?
>>
>>60829654
kill self
>>
>>60829654
Now you kode!
>>
>>60829654

NEETDOM for the rest of life.
>>
>>60829654
topkek anon
1. U of T
2. Waterpoo
are the only CS schools worth shit in CA
>>
>>60829621
faggots like you trigger me with your pajeet tier stack overflow questions
>>
File: dlang_chan.jpg (70KB, 349x368px) Image search: [Google]
dlang_chan.jpg
70KB, 349x368px
Threadly reminder that dlang-chan has RAII; she's quite fast in execution and compilation; she's becoming fully memory-safe; and she's super duper cute! Say something nice about her, /dpt/!

>Tour
http://tour.dlang.org/
>Books
https://wiki.dlang.org/Books
>GC
https://dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
https://wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes
>>
>>60828216
dumb frogposter
>>
>>60828205
>>Try calling a method that takes a &mut self [...] while self is immutably/mutably borrowed.

You're not supposed to mutate something while another part of the program is assuming that nothing else is currently allowed to mutate it. That is the entire point. If the borrow doesn't mutate anything, make it take in a &self as an argument and you will be fine. Or you can switch to persistent data structures as you would in a functional language.

I personally haven't had trouble with the borrow checker except when it had trouble inferring the scope of the lifetimes, which sometimes requires some ugly hacks like adding a temporary variable to force a move.
>>
>>60829698
>hurr durr because parts of my language is undefined that means my language is good
Exactly the opposite friendo
>>
File: gol.webm (3MB, 854x480px) Image search: [Google]
gol.webm
3MB, 854x480px
r8 my Conway's game of life in C Poo Poo
>>
>>60829870
SDL?
>>
>>60829883
SFML, fancied a change after using SDL for a while
>>
>>60828397
Add QT core as a dependency and use QString.
>>
>>60829654
>b. of science (3 year)
is this a meme degree or what?
>>
>>60829870
source
>>
Is there language with same semantics as C but with smarter compiler?
Semantics as does not have name mangling and has stable ABI.
Smarter compiler like type inference and better macros.
ATS looked promising but the syntax is so ugly.
>>
File: devenv_2017-06-09_22-57-38.png (24KB, 622x499px) Image search: [Google]
devenv_2017-06-09_22-57-38.png
24KB, 622x499px
>>60829962
This is the actual algorithm bit, the rest of the source is just showing a different rectangle based on what character is in the array. 'buf' and 'map' are vector<char> and 'buf' is just an intermediate place to store the next iteration.

inb4 this can be rewrote in 50 characters :(
>>
>>60830041

Use C++ and extern C everything
>>
>>60830074
line 7 shouldn't be there, forgot to remove when I ported the code to work with SFML
>>
>>60830097
sepples has even uglier syntax than ATS. Also fuck Bjarne.
>>
>>60830097
it really isn't smarter if you need add extra declarations just to avoid name mangling.
>>
>>60830115

it's literally exactly what you asked for
>>
I just finished an instahoe downloader

import sys
import datetime
import urllib2
import json
import os
import argparse
from pprint import pprint

parser = argparse.ArgumentParser()
parser.add_argument('-u', '--username',
help='The name of the user whose images you want to download', required=True)
args = parser.parse_args()

uname = args.username
print "Username: " + args.username
path = "" + uname
if os.path.exists(uname):
print "Folder exists, moving on"
else:
os.makedirs(uname)

defaultURL = "http://instagram.com/" + uname + "/media"


def downloadImages(jsonItemList):
for item in jsonItemList:
imageURL = item['images']['standard_resolution']['url']
test = item['created_time']
imageDownloadPath = path + "/" + imageURL.split('/')[-1]
x = datetime.datetime.fromtimestamp(
int(test)).strftime('%d-%m-%Y %H-%M-%S')
newname = uname + "\\" + x + ".jpg"
file = open(imageDownloadPath, 'wb')
file.write(urllib2.urlopen(imageURL).read(),)
file.close()
try:
os.rename(imageDownloadPath, newname)
print "Downloaded: " + x + ".jpg"
except WindowsError:
os.remove(imageDownloadPath)
print "Duplicate: " + x + ".jpg"

round = 0
while round != -1:
if round == 0:
URL = defaultURL
round += 1
else:
URL = defaultURL + "?max_id=" + jsonData['items'][-1]['id']

rawContent = urllib2.urlopen(URL).read()
jsonData = json.loads(rawContent)
downloadImages(jsonData['items'])

if jsonData['more_available'] == False:
round = -1
>>
>>60830135
No I asked smarter compiler. Not cluster fuck of shit.
>>
>>60830151
>>60830115

>I have to complain about shit I won't use
Literally just write C, and then add templates. What's the issue here? Why are you complaining about C++ being a clusterfuck when you'd just be writing it like C (which you clearly like) with better macros?
>>
>>60830149
>import
>import
>import
>import
>>>/trash/
>>
>>60830215

what's wrong with that
>>
>>60830186
If you start using sepples you will eventually use libraries written in sepples. Now every sepples developer is fucking retard who writes buggy. So you have to read their shitty sepples code to fix it.
In the end you will be in so deep sepples shit that it's just easier to give up.
Sepples is not langaguge meant to be used.
>>
>>60830222
this guy just hates pep8 formatting
>>
Some help with regex please?
How would I write given parameter "object(type)", where i need to separate both object and type to different variables. Java
>>
>>60830239
>If you start using sepples you will eventually use libraries written in sepples.
Oh, so your problem is that you're too much of a retard to keep doing things the way you like and you're blaming the language for that, even though it lets you keep everything the same with no problems.
>>
>>60830268
what
what the fuck are you even saying
>>
>>60830269
That sentence makes no sense but I didn't expect that sepplestard could type anything comprehensible in english.
>>
>>60830298

>Cfag so irrationally afraid of sepples that he forgets how to parse English sentences
>>
>>60830274
Forgiveness for my late night caffeine overdosage retardation.
My method receives strings of the format "ball(baseball)" as parameter, and I want to separate it into two strings:
str1 = ball
str2 = baseball
How can I achieve that
>>
>>60830334
You want capture groups
>>
>>60830149
based
>>
Do C++ programmers specifically try to make their programs unreadable?
>>
is it a waste of time to write:
>a make alternative that works like a makefile with auto dependencies except without the redundant shit
>a program based on related concepts that syncs a local directory with a remote directory
>>
>>60830699

Some of them do. It's kind of fun to explore the weird bullshit you can do.
>>
>>60829621
kek it should've printed 01 but then again, C++ is utter garbage
>>
post yfw shitlang users will never be able to compete with your c++ code
>>
>>60829654
Train some geodudes
>>
>>60830699
No, C++ in inherently unreadable
>>
>>60830950
Perhaps if you're a poor programmer that's true
>>
>>60830959

Unfortunately, there are a lot of shit C++ programmers.
Those people then went on to write Java, and Java is restrictive enough that they do less damage.
>>
>>60830959
Only poor programmers prefer C++
>>
>>60830991
Rust isn't mature enough yet so C++ is my only option
>>
>>60831008

Rust is still in its infancy and already as ugly as C++. We need to start from scratch but Rust isn't the answer.
>>
Why does Bjarne shill windows?
>>
>>60831023
It's closer to the answer than any other language I've seen.
>>
>>60831058

I agree, but that still doesn't mean it's any good. Just that it's not quite as shit as the other C++-killers.
>>
>want an array of integers and strings in java
>can't do it without boxing
Wow, Java's really a terrible language if you want performance, isn't it?
>>
I'm writing a Perl script that relies on a few external programs. Right now I'm calling them via IPC::Run3, but I'm wondering if it would be worth investing time in the future to write bindings for them. Is there a ton of overhead involved in calling a binary via system(), exec(), backticks or something like IPC::Run3?
>>
File: 39857109.jpg (9KB, 250x241px) Image search: [Google]
39857109.jpg
9KB, 250x241px
Would you a Scott Meyers, /dpt/?
>>
>>60831245

You can do unboxed int arrays in Java, that's just int[].
Any other kind of generic container of integers requires boxing, because Java generics are just typecast macros and Java lacks a unified type system.
>>
>>60831294
But I want an array of { int, string }. Not an array of int.
>>
>>60831245
how does [] arrays = terrible performance?
>>
>>60831323
make an object for it
>>
>>60831326
>>60831337
class IntAndString {
public final int i;
public final String s;
/* ... */
}

IntAndString[] a = ...


It's an array of references, and there's no way around it.
>>
>>60831323

Well yes, then you'd need some kind of object to encapsulate an int-String pair. And god help you if you use a generic one, because then you're actually creating an array of Integers and Strings, which means you have even more dereferencing.
>>
>>60826704
you got nothing against this guy
https://gist.github.com/Wunkolo/249646f7a922ee045c70
>>
>>60831378
Exactly. Yet storing the data how I want is trivial in C/C++/Rust. Java's just bad.
>>
>>60831414

C# gets this one right too. You can use a struct which is a monomorphic value type to box your values up. Your array then holds the objects in contiguous memory, rather than holding references to them.
I believe D has the same idea of what it means to be a struct.

So yes, Java is simply bad at this.
>>
>>60831448
That's cool, I didn't know that. All of my experience of managed langs is with JVM langs.
>>
>>60831356
>an array of points
ITS OVER LADS PERFORMANCE IS DEAD
>>
>>60831515
If you care about performance in the slightest, you wouldn't be using Java.
Also, if you care about sanity in the slightest, you wouldn't be using Java.
>>
>>60831564

Given how shit the language and bytecode it's executing is, the JVM is actually pretty performant.
>>
>>60831515
$ cat structs.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#define COUNT 1 << 28

int main(void)
{
int *array = malloc(sizeof(int) * COUNT);

for (size_t i = 0; i < COUNT; i++) {
array[i] = COUNT - i;
}

uint64_t result = 0;
for (size_t i = 0; i < COUNT; i++) {
result += array[i];
}

printf("%lld\n", result);

return 0;
}

$ gcc -O2 -o structs structs.c
$ time ./structs
-8388608

real 0m0.461s
user 0m0.284s
sys 0m0.176s
$ cat refs.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#define COUNT 1 << 28

int main(void)
{
int **array = malloc(sizeof(int*) * COUNT);

for (size_t i = 0; i < COUNT; i++) {
int *ptr = malloc(sizeof(int));
*ptr = COUNT - i;
array[i] = ptr;
}

uint64_t result = 0;
for (size_t i = 0; i < COUNT; i++) {
result += *(array[i]);
}

printf("%lld\n", result);

return 0;
}

$ gcc -O2 -o refs refs.c
$ time ./refs
-8388608

real 0m6.312s
user 0m4.383s
sys 0m1.915s
>>
File: 1475104523311.jpg (57KB, 618x750px) Image search: [Google]
1475104523311.jpg
57KB, 618x750px
I'm trying to convert this brute force function to some kind of dynamic programming because my seq vector has 100000 items, but can't for the life of me understand how dp or memoization works.

void brf(vector<char>& seq, vector<char> m1, vector<char> m2, int st){
if (seq.size() == st){
int production = calc(m1, m2);
if (production >= max){
max = production ;
}
}
else{
m1.push_back(seq[st]);
brf(seq, m1, m2, st + 1);

m1.pop_back();

m2.push_back(seq[st]);
brf(seq, m1, m2, st + 1);
}
}
>>
>>60831614
"dynamic programming" is a meaningless term
>>
>>60831614
Describe the problem you're actually trying to solve.
>>
>>60831608

I'm willing to bet more of that overhead comes from malloc than derefrencing.
>>
>>60829654
Go work for one of the places where you did a co-op term.

>St. Catharines
Move to a real city.
>>
>>60831624
no it isn't
>>
>>60831663
Probably, but all of those cache misses also makes a huge difference.

>>60831624
Dynamic programming actually does have a proper meaning.
>>
>>60831663
And those mallocs simply aren't necessary in the structs example. You're not helping Java's case here. It doesn't matter how the overhead is distributed between allocation and dereferencing, not being able to store structs directly in arrays is a disaster for performance.
>>
>>60831692

Don't get me wrong, I'm not defending Java. I'm just pointing out that this may be an exaggeration.
>>60831677

Cache is more important than the cost of dereferencing itself desu
>>
>>60831626
Suppose you have 2 mines.
There is a sequence of food rations which is brought to the miners.
The amount of coal produced by the miners is equal to the amount of different food types in the last 3 food rations given to them(e.g. if they get 2 bread and 1 meat, then production is 2, if they get 3x fish then production=is 1 etc).

Given the sequence of food rations, distribute them between the 2 mines in order to maximise production (the sum of coal produced by both mines).

A food ration can only be given to 1 mine (can't be divided) obviously.

My code basically computes every possible combination of food distribution and returns the max sum (which is retardedly slow).
>>
So, this is my last year in uni (Computer Engineering). In order to pass Distributed Systems, I have to pitch a project to our professor, get approved, and develop it after a written and oral exam. I am out of ideas on what to pitch. The only thing that came to mind was some sort of distributed game matchmaking system, like the one used in videogames and chess. I don't wanna try something too out of the ordinary, and therefore hard to code test and deliver, but not too common either. I want to stand out and get a good mark on my project
>>
>>60831719
why don't you turn off your computer and solve the problem before trying to write code that implements an algorithm you don't know
>>
>>60831771
botnet
>>
So I made a strategy for learning C++. First I will read this book:
http://www.cplusplus.com/files/tutorial.pdf
And then I will read "Effective C++"

Is this a decent approach?
>>
>>60831865
>Effective modern C++
>Considered to be an invaluable resource to git good at C++
>Written by Scot Meyers
>He literally shills for D these days
Let's be honest here, D is what you get when C++ is naturally evolved. D is just a better C++.
>>
>>60831928
No, Rust is a better C++. D is a better Java
>>
>>60831987
Rust is a better OCaml, D is better C++
>>
>>60831993
Rust is very much worse than any serious FP language
>>
>>60831782
My usual approach is to think about how I would solve the test case myself, without the help of a computer, and then expand the method to fit a bigger case size.

I have tried to split the sequence to 5-character parts and store the optimal solutions to combine them with the next part.

I solved the problem on paper and wrote down the steps i took to solve it, however, the running time still increases exponentially. Also, how can I be sure that my hand calculated sum is the optimal sum? How do I know it will work for all cases?
>>
>>60831928
>He literally shills for D these days
What? During dconf, he admitted that he doesn't know much about dlang-chan. His speech there was about software engineering in general. With that said, I would love it if he became more involved with dlang-chan and the community.
>>
>>60832016
Why, because it might let you pretend D isn't dead for a little longer?
>>
>>60832007
FP languaes are the worst of the worse. There is no serious FP language.
>>
>>60832029
Agda
>>
>>60832016
>Comes to Dconf, gives a talk on D
>>60832026
>Thinks D is dead

If anything, Rust is going to kill C++ in the next decade, and that's a good thing

>>60832036
I said serious
>>
>>60832026
Your shitposting aside, it's because he is a smart and knowledgeable guy that could further improve dlang-chan.
>>
>>60831719
This sounds NP-hard to me.
>>
>>60832036
<inset a piece of shit useless vaporwave language here>
>>
>>60832041
>If anything, Rust is going to kill C++ in the next decade, and that's a good thing
I don't see how this means D isn't dead
>>
>>60832060
It's more alive than your git
>>
>>60832055
>>60831719
NP-complete I mean. It seems like the subset-selection problem.
>>
>>60832058
m8 r u ok
>>
File: 1491241951711.png (2MB, 549x800px) Image search: [Google]
1491241951711.png
2MB, 549x800px
Is anime NP-complete?
>>
>>60832041
He didn't give a talk on dlang-chan though.
>>
>>60832074
Shouldn't you be busy writing hasklel with no I/O with anime types?
>>
File: 1496219604226.png (523KB, 764x735px) Image search: [Google]
1496219604226.png
523KB, 764x735px
>>60832077
Huskall doesn't support anime types.
>>
>>60832077
Haskell isn't a serious FP language.
>>
>>60832092
FP is not a serious paradigm itself
>>
>>60832092
>>60832098
What is:
1) a ``serious" language or paradigm
2) ``FP"
>>
Another DPT thread where people pretend they use C
>>
>>60832098
Good luck proving anything with "OOP" or "data-oriented programming" or "imperative programming"
>>
>>60832108
>DPT
What?
>pretend they use C
I actually do use C, though.
>>
>>60832075
Is anime AI-complete?
>>
File: 33.gif (18KB, 300x100px) Image search: [Google]
33.gif
18KB, 300x100px
Working on my imageboard, 4kev.org
>>
>>60832107
hahahah xd, I'll pretent that I don't know what functional paradigm is
>>
>>60832107
>a ``serious" language or paradigm
One that is consistent

>``FP"
Designed in Scotland
>>
File: 1495944430109.jpg (71KB, 260x400px) Image search: [Google]
1495944430109.jpg
71KB, 260x400px
>>60832114
That's an open problem. Most people believe it is though.
>>
>>60832111
Prove that "F = ma" in your hipster shit vaporwave language
>>
>>60832120
That's a genuine question.

>>60832125
>One that is consistent
So the empty language is a serious language?
>Designed in Scotland
Most languages from there seem to be shit.
>>
>>60832149
Learn the difference between Object oriented, functional and imperative programing
>>
File: 1491556420796.png (67KB, 385x367px) Image search: [Google]
1491556420796.png
67KB, 385x367px
>>60832111
What is ``OOP" or ``data-oriented programming" or ``imperative programming"?
>>
>>60832041
>If anything, Rust is going to kill C++ in the next decade, and that's a good thing
The problem with Rust is that it doesn't map well to the ENTERPRISE QUALITY object-oriented paradigm that is so dominant in software engineering these days.
>>
>>60832166
What is 'programming`` ?
>>
>>60832069
It seems to have an optimal substructure, but the interaction between the previous characters to the next does not allow me to store optimal solutions for smaller parts of the sequence. I could also be completely wrong and the problem has a linear solution.
>>
>>60832008
write a base case, and then a case that naturally follows from previous cases. use math, stupid code monkey
>>
File: 1484582689170.png (618KB, 738x845px) Image search: [Google]
1484582689170.png
618KB, 738x845px
>>60832160
>Certainly more serious than, say, Haskell or Java
I definitely agree.
>Best watch your fucking mouth lad
Sorry, but it is known that Australians are superior.
>>
>>60832166
Don't use faggot quotes outside of /prog/.
>>
>>60832149
What is a "genuine '` and 'question""?
>>
File: emus.jpg (23KB, 320x352px) Image search: [Google]
emus.jpg
23KB, 320x352px
>>60832179
>>
>>60832179
What is "definately```?
>>
>>60832199
I think it's how Nate Silver describes his predictions
>>
>>60832179
>Australians are superior.
Enjoy your garbage internet.
>>
>>60832207
What is a ''nate"`` silver?
>>
>>60832217
https://twitter.com/natesilver538
>>
>>60832175
>>60832173
Can you provide an example of a base case for 2 arrays? Would it be all optimal combinations of the last/first (n) food rations distributed to the two mines??
>>
post yfw java is 10 times slower than c
>>
Hahaha so funny '``quote marks```" :c
>>
>>60832163
see >>60832166
>>
>>60832253
learn how to use a ````"search engine '``"
>>
Let's go back to >>60831865

Don't let weeb autists ruin another thread
>>
>>60832263
Nobody cares about your sepples crap.
Go learn a real language.
>>
>>60832263
You seem to be new here. All the *chan websites are born out of anime culture.
We apologize that seems to intrinsically trigger your plebbit sensibilities.
>>
>>60832263
Weebs are the cancer killing the internet
>>
>>60832232
you don't have to find all optimal solutions, just AN optimal solution https://en.wikipedia.org/wiki/Mathematical_induction
>>
>>60832276
4chan is an American website. It's made by a white and for whites. Take your degenerate gook shit and fuck off to weebland
>>
>>60831771
I wouldn't really call a match maker and clients a distributed system.
I would do either a master slave system where slaves are either calculating something (digits of pi for example (you can generate the nth binary digit of pi in binary without calculating the previous digits) or slaves have sensors that report back to the master (eg. a sensor that measures how dry the soil is around a farm and reports back to the farmer)
>>
>>60832278
>>60832292
Anime is the fundamental part of imageboard culture and being disgraceful to the anime must be a punishable offence.
>>
>>60832278
Pretty much
>>
haskell!
>>
>>60832292
This
>>
>>60832310
we use idris now
>>
>>60832292
There are no male posters on /dpt/, I can't believe you haven't figured this out yet
>>
>>60832285
>>60832232
also looking at your problem, unless you explained it wrong or i understood your explanation wrong, this is really simple. you start from the end of the list, and anything before the last 6 items doesn't matter
>>
>>60832322
we use agda now.
>>
>>60832346
we use C now
>>
>>60832029
What's serious? And compared to what?

F# and Scala have carved huge niches of their own in industry for all sorts of data processing.

There's a big OCaml shaped hole in Facebook, and Jane Street's whole business is built on top of it.

Elm is getting more and more attention on the frontend, and is used in production in quite a few companies despite not even hitting 1.0; not to mention every JS frontend stack that has come after it are just crude reimplementations of Elm but trying to simplify it for code monkeys in companies with high churn rate.

Elixir is getting Ruby refugees like a motherfucker. You could call this not serious, but the whole stack behind it (Erlang's VM and OTP) is serious engineering at its best.

It just sounds like you don't know about real FP anon.
>>
>>60832361
>skid languages
Get out
>>
>>60832361
>F# and Scala
>FP
Hardly, you might as well say JS is FP
>>
>>60832378
JS is FP
>>
>>60832361
>>60832378
>>60832384
But what is a ``FP" though?
>>
>>60832384
That's it, I quit programming
>>
>>60832358
we use nothing now
>>
>>60832361
>Trash and trash competes with pyshit/Java and C#
>OOOOH LOOK GUYS facebook used my vaporwave crap in some ""hole""
>trash is yet to have it's attention
>webdev trash is for another webdev trash refugees
Nice track record.
>>
>>60832391
JS is FP
>>
>>60832405
>>60832386
>>
File: WhenItSlipsIntoMyAssRealGood.jpg (13KB, 310x345px) Image search: [Google]
WhenItSlipsIntoMyAssRealGood.jpg
13KB, 310x345px
>>60831448
>C#
>>
60832386
Pretending to be retarded doesn't work for the 3rd time
>>
>>60832343
it's not that the last 6 are all that matter, but still i think you'd just be able to start from the end, put it in a mine that maximizes the value (there's only 2 options to look at...) and then look at the next from last, take the previous answer and greedily put it in the one that maximizes the value again. come up with something that proves this wrong, i'm tired and can't think of anything this wouldn't work on. sounds so simple it'd be stupid if it works
>>
>>60825429
Is there a non-retard version of this thread?
>>
>>60832435
There is none, popularity begets idiots.
>>
File: dpt-poster.jpg (517KB, 1521x1076px) Image search: [Google]
dpt-poster.jpg
517KB, 1521x1076px
>>60832435
>>
>>60832443
>>>/a/
Go to hell
>>
>>60832442
Is there an unpopular version of this thread?
>>
>>60832446
Go to reddit.
>>
>>60832168
POO is on the decline. Scala made a huge dent in Java shops and now that frontend has fully embraced FP, its popularity is spreading to the backend.

>>60832375
>not knowing anything about language design and finding anything without C-inspired syntax confusing
>being a code monkey

Get you an AbstractSuicideBeanFactory and inject yourself as a dependency.

>>60832378
JS is as multi-paradigm as it gets. It """works""" as an FP language but it's the weakest one out there.

>>60832391
He's really not that far off the mark. You can treat it as a functional language. The dev experience is just retarded, not taking advantage of everything that makes FP great.

>>60832386
Functional Programming

>>60832399
I would call it bait if I didn't remember being you 10 years ago.

>>60832435
This is /g/.
>>
>>60832285
>>60832343

MFBFFM

the first 6 characters can be arranged as:
MFBFF
M

MBFFM
F

Both solutions give sum 8. Assume the next character is 'B', if it's put into the second solution, it will increase the sum by 3, whereas in the first it will increase it by 2. Therefore I can't just save ONE optimal solution.

The food does not have to be equally distributed
>>
>>60832446
Hoho... thank you, anon
>>
File: of_sorts.gif (219KB, 899x455px) Image search: [Google]
of_sorts.gif
219KB, 899x455px
>>60832361
how did Elixir manage to get a userbase, compared to other functional languages?
I'm doing algorithm design for mechanics at work and there it seems C++ will never go away in such fields. Are web and network people just more eager to switch, learn and accept new tools?

I'm learning Idris at the moment and I post tutorial-like content here:

https://www.youtube.com/channel/UCcrSMnEYhIPX_p127jI23qw

but this is very basic and nothing I can use at work (sadly).
>>
Programming socks, stockings, or pantyhose?
>>
>>60832455
>Functional Programming
What is ``Functional Programming" though?
>>
>>60832455
What's wrong? Are you mad someone called your skid languages skid languages ?
>>
>>60832476
What is a 'programming"`?
>>
>>60832476
It's the opposite of dysfunctional programming
>>
>>60832488
What is ``dysfunctional programming"?
>>
>>60832493
OOP
>>
>>60832470
>>
>>60832500
POO isn't the opposite of FP. Only an absolute retard can claim this.
>>
>>60832493
>>60832488
>>60832485
>>
>>60832463
starting from the back you reverse, so MFFBFM. M goes into mine 1 since it's not in there yet, so does f, next f goes into 2, b goes into 1, f goes into 1 as well since it's already in 2, then the final m goes into 2 since it's not in there yet.

1: MFBF -> FBFM
2: FM -> MF

MFBFFM go into 2, 1, 1, 2, 1, 1 in that order. pretty sure my algorithm gives the optimal answer for that problem, doesn't it? this is a greedy solution
>>
>>60832500
What is a ``OOP" though?
>>
New thread:
>>60832529
>>60832529
>>60832529
>>
>>60832519
>>60832463
also you may need to keep track of order in these, which can be done by creating tuples of (M, 1) for the first whatever. use stacks. glhf
>>
>>60832467
>how did Elixir manage to get a userbase, compared to other functional languages?

José Valim was a Ruby core member, and BEAM+OTP is really a piece of work.

There's a proper ML-inspired lang being developed for it called Alpaca, but it's still in its infancy.

And yes, not just web but it's just systems work that it's so conservative about language, mostly because there are no languages outside of C and C++ that can be used for *all* systems work. Now Rust is introducing some sanity into the field, but adoption is going to be slow as hell and it's not a perfect language either.
>>
>>60832451
Yes.
>>
>>60832701
Link?
>>
File: vista_orb_by_fediafedia.png (75KB, 256x256px) Image search: [Google]
vista_orb_by_fediafedia.png
75KB, 256x256px
>>60825463
I want to learn programming but I want to learn it on Windows because Linux fucking sucks. Any tutorials online for programming on Windows?
>>
>>60833283
it's the same as linux
>>
>>60833283
what would an OS have to do with learning to program?

Are you trying to learn C or something?
>>
Is panda express the programmers fast food goto?
Thread posts: 334
Thread images: 27


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.