/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Old thread:

Attached: TWC.jpg (2048x1536, 252K)

Other urls found in this thread:

haskellbook.com/
learnbchs.org/
benchmarksgame-team.pages.debian.net/benchmarksgame/faster/swift-go.html
twitter.com/NSFWRedditGif

QuantifiedConstraints is cool

ive noticed that in programming there are people that like a little bit of sugar to make things a bit more sweet and there are niggers that eat cake frosting

Please post an anime (programming) related image next time.

How long before I feel like there isn't a gaping hole in my knowledge that stops me from ever starting anything

template[lifetime A, type T]
public function first_mut(self: RefMut[A, Self[T]]) returns Option[RefMut[A, T]]
begin
if self.is_empty() then
return None
else
return Some(borrow mut self[0])
end if
end function

template[lifetime A, type T, type F]
where F implements FnMut[(RefMut[A, T]), Ordering]
public function binary_search_by(self: RefMut[A, Self[T]], variable f: F) returns Result[usize, usize]
begin
local s = self
local variable size = s.len()
if size is 0 then
return Err(0)
end if

local variable base of usize = 0
while size > 1 loop
local half = size / 2
local mid = base + half
local cmp = f(s[mid])
if cmp is not Greater then
base = mid
end if
size = size - half
end loop

local cmp = f(s[base])
if cmp is Equal then
return Ok(base)
else if cmp is Less then
return Err(base + 1)
else
return Err(base)
end if
end function

What book or website with Java exercises does Jow Forums recommend? I would say I'm at the pre-intermediate/intermediate stage.

Just learn kotlin. You'll thank me later.

You'll never know what it is to kiss a girl.
That hole will never close.

When you actually start on something. I had that exact same problem until I learned kotlin and worked every single day on the project.

haskellbook.com/

actually having a gf helps because I feel smart every time I talk to her about programming

wow what a beautifu-

Attached: aesthetics.gif (480x270, 495K)

iktf, none of my coworkers know how to program correctly, so I always feel smart when we talk about work.

I want to get started on data analysis and then go on to machine learning. I've been doing Andrew Ng's course and watching Sentdex's videos which have helped to understand the algorithms but not so much on starting a first project. Been going through kaggle today but it seems unnecessarily complicated (although I figure I will just push through it because of all the data sets I can access on there)

idk. any advice for someone with no work experience looking to go in to data analysis?

Daily reminder that __auto_type, statement expressions and local functions make gnuc acceptable lisp.

Just use higher level apis with God tier documentation. OjAlgo is pretty good for example. Also Nvidia has a bunch of shit that is ez to use. If you start too complicated and low level, you just burn out.

Playing with Haskell
{-# LANGUAGE OverloadedStrings #-}

module Main where

import Lib
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Network.HTTP.Simple
import Text.XML
import Text.XML.Cursor

data Entry = Entry { name :: T.Text, url :: T.Text }

main :: IO ()
main = do
response putStrLn $ "Parse error: " ++ show e
Right document -> mapM_ (T.putStrLn . name) $ handleDocument document

handleDocument document = map handleItem $
fromDocument document $// element "channel"
&// element "item"

handleItem item = Entry name url
where name = head $ item $// element "title" &// content
url = head $ item $// element "link" &// content

>If you start too complicated and low level, you just burn out.
Yeah I've realised this. Luckily I enjoy the maths enough to understand the algorithms, but implementing them is a different story.

I've heard Keras is a good place to start if I want to build NNs.

[spoiler]I have an AMD card[/spoiler]

Odoo stuff like every other Day in my life, fuck this

Motherfucker, if you talk shit I'll write a compiler I swear to god

LMAO
I did my internship with odoo. Even got 3 job offers related to odoo, one was net 70K starting + company car.
Every day I thank god for helping me fight back the temptation. Odoo is Satan's work, user, leave while you can.

Haskell is love
Haskell is life

Idris > Haskell

False

sepples is an acceptable lisp?

sepples is the most powerful lisp.

I'm quite happy with the code. Even though it took me two evenings to write.
I learned Haskell using LYAH and the Wikibook, but it never stuck to me. This week I said to myself: fuck it, just write some code. So I did. Most of the time I spent searching "how to do X in Haskell", but I pulled through. Now everything starts to make sense.
Pro tip: if you want to learn a language, learn the basics and start writing code.

Continuing from last thread: (Code in that post)

I was talking about it the other day, but I need to collect my thoughts more. I am certain in a 2D platform game with a maximum of 512 entities that this shouldn't impact performance, not even on toasters. But, for the sake of learning, I would like to figure out a way to optimize this a little more so that instead of running through every "alt" entity to check collision with, it only runs through the ones near it.

I've seen a number of things listed that I could use:

>quadtree
>octotree
>spatial partition grid
>AABB tree

I've spent the past few days trying to figure something out, and I haven't gotten anywhere yet. I will probably figure it out at some point, but an opinion with an example may help me get there sooner.

I am using C, I have gotten good with memory management, but making something like the "List" that I see in C++ code examples has been a bit difficult. I may be over doing it; if I did a grid I would need a way to store a list of what entities are in that spot, and I am not sure what the right approach is.

>use a flat grid

That's what I was thinking, but how would I use the flat grid? I was thinking of a struct that represented the individual spot in the grid, and a struct inside it that represented the data it had. Something like this:

struct list_s
{
void *data;
list_t *prev;
list_t *next;
};
...
struct spatial_s
{
float x, y;
float w, h;
size_t size;
list_t *list;
};

I'm just a bit confused on where to start/go, but I think once I figure that out I can make something good. I think it would be a good learning exercise to use something like this.

Programming challenge: random number degenerator

Haskell can be a pretty deep rabbit hole but it's all built on simple ideas

first project I did was a command line CRUD program for JSON files on an FTP. I didn't knew what monads were, other than the burrito meme.
Lazy IO made me want to kms for 3 days straight.

imagine having a bs in cs instead of a ba

I don't see any pitfalls using Haskell for relatively simple CLI programs. I guess it all depends on the complexity of the program you're writing.
What's the problem with lazy IO? Can't you simply isolate all impure code?

I just mean that there's always more Haskell you can learn

That's a good thing. It's not a stultifying language.

If in Java I want to make an array of method references like I can easily do for functions in Pyhon, should the list type be the same as what the method returns?
Right now they are all void. What if one day I want to add a method that returns something else?

Attached: 1478122527874.png (735x371, 422K)

I can imagine. I only scratched the surface of Haskell. Functors, applicative functors, monoids are still magical to me.
I'm fine feeling stupid using Haskell. That's an indication of a powerful language. Rust makes me irritated.

Can't overwrite a file that hasn't been read in its entirety yet. Or something like that.

Brainlet tier question coming through. I am currently reading "Berj's Network Programming" book. Will I, when I finish this book, be able to write a web scraper, or any other cool stuff regarding web pages, with C?

Attached: brianlet.jpg (800x450, 41K)

learnbchs.org/

>tfw you'll never have ∞ contributors to your project

Attached: 1111111.png (1321x385, 34K)

Go look up functional interfaces. Method references and lambda expressions are just anonymous classes which implement a functional interface.

>array of method references
?

an array of method references? what? not sure it's possible unless you shit up the types with List

maybe something like List but that limits you to a method which takes 1 input and returns an output

Why, thank you, user. I will check this out.

enjoy your incredibly tedious and slow development process

The DB is beyond my control, I'm building one on my own by visiting the website with a web crawler/spider

I'm not an expert, but it sounds to me like you messed up somewhere.

Niggas talking shit about you?

How do I learn all this gui crap? I just want to use OpenTK to draw a fucking raw bitmap

Rust:
>new
>semi-unstable
>already has full-fledged wasm support

Haskell:
>mature
>stable
>GHC is written in the best language for compiler development
>no wasm support

When will they put their crap together?

Attached: maxresdefault.jpg (1280x720, 283K)

Rust is not new
Neither are mature or stable
Haskell sucks
wasm your ass

Attached: aid988455-v4-728px-Spit-Step-13.jpg (728x546, 112K)

Aren't there delegates in Java?

>java delegates
They are half-assed `functional interfaces'

I always thought Java was on par with C#.

Is pointer memcpy-able in C?
for example:
void * f_array[3] = {&foo, &bar, &baz};
void * s_array[3];
memcpy(s_array, f_array, (sizeof(void *) * 3);

is that going to be UB or works perfectly fine?

functional interfaces are better than delegates though.

That's fine.

Automated refcounting uses less memory than Garbage collectio....
benchmarksgame-team.pages.debian.net/benchmarksgame/faster/swift-go.html

Not really. Both the language and the runtime are decades behind.

Not this shit again

>Failed
>Failed
>?
Fucking pathetic shitlangs

Behind what?

Go uses significantly less memory than Swift on almost every single benchmark.

>inb4 butthurt jvmfags

Attached: eID1jOj.jpg (1280x720, 318K)

I need to "learn" it (do useless shit with it using basic OOP stuff I already know from C++) for school.
This sucks so bad, I like C, C++ and Python.

I should be getting better at those languages but school forces me to use this instead, for a whole year or 2
It's just more brain cells used for storing the syntax and standard class / method names of a language I don't want to use.

Attached: 1456974152001.jpg (500x375, 100K)

I mean, I still like Swift slightly more because it has generics and pattern matching, but its lack of garbage collection really hurts it. Using less memory than Java is not a major accomplishment.

Go makes a bunch of really opinionated design decisions that I don't like and still hasn't figured out a design for generics, but the compiler + runtime are really well executed.

Java syntax and semantics are simple, a lot more so than C#.

Is there anything you can do with delegates that you can't do with lambdas?

The PL itself is simple as in it lacks a lot and compensates with boilerplate. You will get used to it, dumb frogposter.

dumb frogposter

lambdas are anonymous delegates

Java 10/11 adds full type inference. Modern Java is much less heavy on boilerplate than old Java. However, he'll probably have to deal with old Java in school.

>modern java
No such thing. Type inference and half-assed lambdas are nothing modern.

There is horrible unsafe old java where lists could contain any type, and newer less-terrible Java. The latter honestly isn't too bad.

Java had broken generics since forever. Nobody is talking about Java pre-2K

The single abstract method interfaces and command/strategy patterns were still a thing until recently with lambdas, and still are in older code.

So? It's a seamless transition to go from old code to new because they're both implemented in terms of SAM types.
Try converting C# code using interfaces to using delegates instead. C# doesn't care about backward or forward compatibility.

def f(rand):
return 0

One has to support an extensive runtime, the other can run on bare metal.

I'm writing queries that will test against incoming logs to find matches. For example, a multi-line query could be:
when name != "bob" and country == "Greenland" and height > 70"
when some_value == 5 or some_value == 7

So, both line have to match the log for the query to return results.

I want to generate a sample log in JSON format that will test positively against a query. Similar to a unit test in a way. So, if I run the query against the JSON I generate, the engine returns the JSON log.

What is a good way to parse queries in the above form and generate JSON that matches it? Any langauge is fine

That hole always exists because in software you automate the things you know. There's always stuff you don't waiting on the horizon though.

Actually doing work acclimates you to being comfortable with always spending half your time learning.

>convert an interface to a delegate
kek

Dumb question, but can someone explain to me how on this piece of code, the "case NUMBER", is able to catch all characters between '0', and '9'? Shouldn't you have to explicitly state it on a switch statement?
#include
#include /* for atof() */
#define MAXOP 100 /* max size of operand or operator */
#define NUMBER '0' /* signal that a number was found */
int getop(char []);
void push(double);
double pop(void);
/* reverse Polish calculator */
main()
{
int type;
double op2;
char s[MAXOP];
while ((type = getop(s)) != EOF) {
switch (type) {
case NUMBER:
push(atof(s));
break;
case '+':
push(pop() + pop());
break;
case '*':
push(pop() * pop());
break;
case '-':
op2 = pop();
push(pop() - op2);
break;
case '/':
op2 = pop();
if (op2 != 0.0)
push(pop() / op2);
else
printf("error: zero divisor\n");
break;
case '\n':
printf("\t%.8g\n", pop());
break;
default:
printf("error: unknown command %s\n", s);
break;
}
}
return 0;
}

What do you guys think of GO/ Golang

better for brainlets than java or other poolangs but still inexpressive and unwieldy

What does getop do?

Why did you reply to yourself?

if appropriate, read json into a db & call SQL queries
I don't know enough about your requirements to give a good answer here

The following is a non-exhaustive list of programming languages that are objectively garbage. If you use any of them, you should stop immediately.
>Java
>C#
>Python
>JavaScript
>Go
>Ruby
>Kotlin
>Perl
>TypeScript
>Groovy

Sorry for poor formatting, the Jow Forums window is not letting me use tabs. inb4 "REEEEEEE spaces over tabs"
int getch(void);
void ungetch(int);
/* getop: get next character or numeric operand */
int getop(char s[])
{
int i, c;
while ((s[0] = c = getch()) == ' ' || c == '\t')
;
s[1] = '\0';
if (!isdigit(c) && c != '.')
return c; /* not a number */
i = 0;
if (isdigit(c)) /* collect integer part */
while (isdigit(s[++i] = c = getch()))
;
if (c == '.') /* collect fraction part */
while (isdigit(s[++i] = c = getch()))
;
s[i] = '\0';
if (c != EOF)
ungetch(c);
return NUMBER;
}

#define BUFSIZE 100
char buf[BUFSIZE]; /* buffer for ungetch */
int bufp = 0; /* next free position in buf */
int getch(void) /* get a (possibly pushed-back) character */
{
return (bufp > 0) ? buf[--bufp] : getchar();
}
void ungetch(int c) /* push character back on input */
{
if (bufp >= BUFSIZE)
printf("ungetch: too many characters\n");
else
buf[bufp++] = c;
}

you forgot c++

:%s/\t/ /g

>non-exhaustive

I am retarded, so I don't know what this means.

Employed Haskell programmer reporting in

Attached: 1486967195245.png (750x750, 82K)

Employed Idris programmer reporting in. Come to the total side, we have termination proofs!

Read the chapter again. I dont remeber but something returns NUMBER. When isdigit().

good work