/dpt/ daily programming thread

Old thread:

Attached: Julialogo.png (320x216, 11K)

Other urls found in this thread:

repl.it/repls/CultivatedOnlyProcedure
github.com/perl6/marketing/blob/master/Brochures/Introducing-Perl6-Brochure/Introducing-Perl6-Brochure.pdf
news.mit.edu/2017/three-mit-seniors-awarded-marshall-scholarships-1204
twitter.com/SFWRedditGifs

someone please tell me why the fuck this
n = [3, 5, 7]

def total(numbers):
result = 0
for i in range(len(numbers)):
result = numbers[i]
print result

is 6?

it's not, you fuck

$yes
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);
}

Attached: 1521736946997.jpg (1280x1440, 179K)

It prints 7 for me?

Attached: Screenshot from 2018-03-28 13-32-05.png (1932x771, 86K)

owo whats this
rust is looking better and better

You stripped away the documentation didn't you?

you never called the function. so that result isn't from this run. or it's from (((codeacademy))) calling your function with a different argument. or you edited it.
1/10 made me reply

just to ask again quickly.
Hey, so doing a thing in kernel space.

What's the kernel equivalent of getrusage() ?
I want the time spent in system and user space, (and not just a measurement of execution time), but obviously sys/resources isn't available in kernel space.
anyone know?

>clone_from_slice
>split_at_mut

...

>faster_than_C

Attached: Screenshot_2018-03-28_13-36-42.png (3840x2160, 358K)

winner

Attached: 1455788821495.jpg (240x225, 18K)

i need some inspiration,
give me some programming ideas

Attached: 28238328_353551738456631_5926683382684073176_o.png (870x1086, 527K)

repl.it/repls/CultivatedOnlyProcedure

have you ever made a game? try making one, it's a good way to exercise creativity as well.

Not surprised because you abused the shit out of Cow, Os string and page size.
It's a tradeoff for performance.

i used to work ( as a programmer) in a game studio.
but thanks for the idea

someone post the /dpt/ rolls, i'll do one in haskell

It is though. It tells you that the lifetimes of the buffer, output, and the return value slices must be the same. You can't express this at all in C++'s type system.

so
std::vector foo(std::vector, int) {

is cleaner than
def foo(lst, n):

because it tells you more about the types?
Sorry, bud. "Cleaner" doesn't mean "tells you more"

I'm reading Object-Oriented Programming in Common Lisp and it is blowing my mind.
Do any other languages implement anything like CLOS?

Dylan, it was based on Common Lisp and CLOS, but given an ALGOL-like syntax instead of s-expressions.

What does lie beyond horizon of govnocode!

Attached: govnocode.webm (640x360, 2.35M)

What's the age cutoff for learning a new programming language?

They say it's incredibly hard to learn new spoken languages as you age and almost impossible in your elder years. does the same apply for programming languages? I'm 34 and never wanted to learn till now.

Attached: sad_pepe_300x300.jpg (300x300, 11K)

no cutoff, dimwit
also my dad is 60 and he's learning french. fuck off with this "old people can't learn" shit
plus 34 isn't even old at all
FUCK your stupidity makes me ANGERY

I have to do some stuff in VBScript for work. I'm not a real programmer. Anyone have any good documentation or interpreter links?

That's just a meme perpetrated by lazy old people.
What do you want to learn?

Dead people can't learn new things, so if you're dead, you're too old for this.

fn foo(lst : Vec, n : i64) -> Vec {


Is nicer than this:

// lst is a vector of strings, n is an
// integer, this returns a vector of vector of ints
def foo(lst, n):

Though I personally would prefer something like this:

foo :: Vec String -> i64 -> Vec (Vec i64)
let foo lst n = ...


where the type signature and the implementation are separate.

Python has a built-in function called "sum" that will do what you want.

Well I've been playing with HTML and CSS which I know aren't true program languages. But I know it's easier and can help me start learning.

I want to eventually look into Python or javascript when I begin to understand more.

What are some good resources for becoming a full stack dev? My internship and work experience so far has all been desktop app experience and my college web development classes were a joke.

the last is better than both the first two by a mile
foo :: [String] -> Integer -> [[Integer]]
foo xs n = ...

stop sucking the imperative teat

>just use "sum" durr
this person is obviously trying to learn programming basics, you're not being helpful at all

do you have a personal website with some stupid fancy effects made in javascript? or does it serve up the results of something you wrote in python? try that if you can

Among modern languages, Julia is entirely based on CLOS-like multiple dispatch as its core feature. It adds some feature like parametric polymorhpism (generics) which fully interplay with the dynamic dispatching, but avoids inheritance of non-abstract types so that have value semantics for all types which can be instantiated.

Multimethods in Julia are also much faster than multimethods in CLOS which had a performance penalty compared to regular functions.

It's fairly lispy and has macros, but it has a more traditional syntax and since it's designed to be fast, it avoids features that have a too high performance cost in favor of features that are zero cost abstractions in the typical case.

Google:
>Switch to kotlin, it's the future!

Kotlin:
fun solveP10() {
val LIM = 10000000
val Z: Byte = 0
val bs = ByteArray(LIM + 1)
var sum: Long = 0
var n = 2

while (n < LIM) {
sum += n

(n shl 1 until LIM).step(n).forEach { bs[it] = 1 }
while (bs[++n] != Z);
}

println(sum)
}


Java:
static void solveP10() {
final int LIM = 10000000;
byte[] bs = new byte[LIM+1];
long sum = 0;
int n = 2;

while (n < LIM) {
sum += n;

for (int x = n

>Julia
You have good taste OP

No website or anything. I've just been doing the courses on codeacademy. I'm nowhere near ready to touch java or python. I guess I just wondered if it would even be possible to teach myself those at my age. HTML is still so new to me and it will take me awhile to get it.

try using a normal for loop in the kotlin code so you actually have a valid comparison

Java is king and always will be king, remember that

alright yeah sounds good. you'll get there, user. everyone who doesn't give up makes it there.

Thanks. Any other websites like codeacademy you recommend? I'm thinking of paying for their for their Pro membership

My Python sieve can do it in 1s, while being easier to write and read. Clearly the future is Python.

t. Gurpreet

Have you heard about this cool new language, Perl 6? Check out this introductory brochure!

github.com/perl6/marketing/blob/master/Brochures/Introducing-Perl6-Brochure/Introducing-Perl6-Brochure.pdf

Attached: p6-book-flowchart.png (1361x1123, 689K)

>My Python sieve can do it in 1s

Attached: 1514337071020.png (644x500, 66K)

did the "average" guys miss out already? by that I mean, to be successful as a software developer for the next couple of decades, do you have to be really fuckin motivated, creative, and intelligent?
I feel like back in the 90s and 00s all you had to do was know what a for loop was and have half a brain and you could have a successful career as a dev.

user i'm 30 and thought like you...too old to start why bother...let me show you something that changed my life and helped me start about a month ago.

from Python The Hard Way by Zed Shaw
As you study this book and continue with programming, remember that anything worth doing
is diffi cult at fi rst. Maybe you are the kind of person who is afraid of failure, so you give up at
the fi rst sign of diffi culty. Maybe you never learned self- discipline, so you can’t do anything that’s
“boring.” Maybe you were told that you are “gifted,” so you never attempt anything that might
make you seem stupid or not a prodigy. Maybe you are competitive and unfairly compare yourself
to someone like me who’s been programming for 20+ years.
Whatever your reason for wanting to quit, keep at it. Force yourself. If you run into a Study Drill
you can’t do or a lesson you just do not understand, then skip it and come back to it later. Just
keep going because with programming there’s this very odd thing that happens. At fi rst, you will
not understand anything. It’ll be weird, just like with learning any human language. You will
struggle with words and not know what symbols are what, and it’ll all be very confusing. Then
one day—BANG—your brain will snap and you will suddenly “get it.” If you keep doing the exer-
cises and keep trying to understand them, you will get it. You might not be a master coder, but
you will at least understand how programming works.
If you give up, you won’t ever reach this point. You will hit the fi rst confusing thing (which is
everything at fi rst) and then stop. If you keep trying, keep typing it in, trying to understand it and
reading about it, you will eventually get it.
But if you go through this whole book and you still do not understand how to code, at least you
gave it a shot. You can say you tried yo

Slow as fuck. Would have been nice back when old Perl now, but now there's a lot of other alternatives and there's no reason to learn an unpopular language which is also slow.

As you study this book and continue with programming, remember that anything worth doing
is diffi cult at fi rst. Maybe you are the kind of person who is afraid of failure, so you give up at
the fi rst sign of diffi culty. Maybe you never learned self- discipline, so you can’t do anything that’s
“boring.” Maybe you were told that you are “gifted,” so you never attempt anything that might
make you seem stupid or not a prodigy. Maybe you are competitive and unfairly compare yourself
to someone like me who’s been programming for 20+ years.

>afraid of failure
>no self-discipline
>told i was "gifted"

fml, i believe they call that a trifecta...

Thanks for the encouragement user. I believe I will stick with it!

This book is what got me really started with python. Highly recommend it. I think the title is misleading because the content really isn't hard. The book just covers a large variety of features and modules and doesn't skim over any details. Maybe the hard way if learning about the language doesn't interest you.

shit book, avoid zed shaw at all costs

>no reason to learn an unpopualr language that is slow

and yet everyone shills Lisp and Haskell.


also haskell>lisp

>no reason to learn an unpopular slow language
that doesn't do anything better than other languages

and yet everyone shills lisp and haskell

not even better, just in a significantly different way.
haskell and lisp are both different enough from the mainstream to be worth learning.

but which ones BETTER?

can I be a HACKER in haskell or lisp?
No?

Then why bother

t.mathmajor who failed out of python

Thanks!

Now that it's become more mature, I'm increasingly using it as my first goto for most mathy tasks instead of Mathematica (except if I need lots of symbolic computations done). It's really nice to use and will be even more awesome when makie.jl will be fully mature so that plotting speed won't be the bottleneck.

I'm looking forward to the day when I can share a CuArray on the GPU from flux.jl to makie.jl and render a plot without ever sending the data back from my graphics card. Or live displays of an evolving PDE if DifferentialEquations.jl becomes a mature option for PDE's with GPU acceleration.

Attached: goaway.png (415x82, 6K)

agreed 100%

Taking a programming class in C++ next quarter. Any BIG syntax changes from Java that I should be aware of?

Perl 6 has lots of interesting features, peruse the brochure! And it's gotten much faster from when it first came out

Attached: Screenshot from 2018-03-28 00-28-59.jpg (901x954, 85K)

How do you deal with the feeling of being absolutely inferior to people?

I am the best econ student at my no name state school and I was thinking about applying to this scholarship.

I'm 24 and I started school late so I feel even worse.

news.mit.edu/2017/three-mit-seniors-awarded-marshall-scholarships-1204


These kids are apparently more accomplished than my whole immediate family combined at age 22.

I'm going to just give up.

looks cool desu
say Parser.parse: 'I Butts';
# OUTPUT: ┌No Homo┘ homo => ┌No┘

am i retarded
where is this syntax error

Attached: isuck.png (660x57, 5K)

>scala
Who pooed in my haskell

I want to take
tnaoehoeutn, 234234, oetnhunah

and get
tnaoehoeutn,
234234,
oetnhunah

with regex
I tried
.+,?

but it turns out that matches the whole thing
What regex do I need to make it stop at a comma, and not read past it?

i just turned down a scala job. utterly disgusting language.
who else /saving employment virginity for haskell/ here?

why bully scala
whats wrong with scala chan

Learn you a haskell for great good is a good read and explains all the things haskellfags get pretentious about in a non pretentious way. Because the things they get pretentious about are just function shit and lisp can do function shit of course. Reading it has significantly improved my lisp-fu.

Haskell as a language still offends me though.

you don't even need regex
your language of choice should have a splitter function.

why

How one who does not exist will be able to go away?

The syntax is fucking horrific I dislike everything being curried by default. I loath lack of variadic functions. I loath infix functions.

f x y z w
Yuck! In Scheme this could just be (acall f x y z w)

>trying to learn to program in common lisp
>cant even do problem 1 of project euler
fuck

project euler is fucking awful to learn a language in.
Just pick up SICP and google whenever you run into a scheme specific thing.

thats too basic though

I know how to program kind of generally, lay things out in a logical manner. I majored in Math I can think like this. and I know what i want to do but I can never finangle any of this god damned mother fucking programming languages syntax into what im trying to do.

lisp is garbage
learn a language with ordinary syntax

>thats too basic though
> but I can't even reason about the syntax
alrighty m8

What?
I just want to know why making a loop in lisp is so fucking obfuscated and esoteric

Read SICP

how many fucking times am i going to be forced to read the same shit

>another afternoon of "heres what an if is! this is what cons does! here's car and cdr! let me explain prefix notation to you!"
Fuck you

>sicp is basic
So thats why mi fuckin t uses it as a textbook for an upper level elective. Sounds like you need basic though if you can't look in lisp user.

Please implement if, car, cdr and cons from memory user.

Yeah maybe in the 80s
huh?

If you know what they are, write an implementation of them.

why would i implement something thats built in

That's pointless though. The point of kotlin is lambda expressions which they say "uses the optimal JVM byte code to execute the expression with the best possible performance".

And out of curiosity I did replace it with a standard while loop and Java still wins by 30-40 ms 10/10 times.

it's not 6, it should print 7 given that you call
total(n).

Seems weird, why do you need a for loop?
you can have less lines of code and don't need a function for something that trivial.

result = 0
end = len(n)
result = n[end]

Can you stop being a big meanie? It's really frustrating that after consistent trying and dedication for two fucking years I have still not been able to make anything in any programming language. I just dont feel fucking comfortable in any programming language. i've tried so hard and I don't understand why its so unintuitive and such a brickwall.

I never proclaimed myself a lisp expert but I would really like it if after banging my head against common lisp for six fucking months I was able to write a simple fucking loop to solve the first project euler problem

kotlin/Ruby/python may be easier to write with far superior verbosity/readability but no one in their right mind would use it (let along migrate) for a large project like an Android app where performance matters.

I see a ton of people bragging about migrating their Android apps to kotlin. Literally pointless.

Where are you calling the function? You need to display the sum, you aren't summing anything.

Here's something simpler:

n = [3,5,7]
result = 0
for i in range(len(n)):
result = result + n[i]
print(result)

>lisp
That's your problem. Learn C, it's one of the easiest languages to do project Euler's in and you'll be glad you learned the fundamentals like memory management and pointers.

maybe read through practical common lisp first before you whine about basic loops?
(let ((sum 0))
(dotimes (i 1000)
(cond
((= (mod i 3) 0)
(incf sum i))
((= (mod i 5) 0)
(incf sum i)
)))
(format t "Look Ma' Im spoonfeeding a brainlet ~%SUM: ~a~%" sum))


$ sbcl --script I_did_this_in_2_minutes.lisp
Look Ma' Im spoonfeeding a brainlet
SUM: 233168