/dpt/ - Daily Programming Thread

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

Attached: 1564824401741.png (696x984, 958K)

Other urls found in this thread:

tridejur.uy/t123.php?id=191213&alta=2018-05-16 13:02:00
eloquentjavascript.net
twitter.com/SFWRedditVideos

Wrong, I use windows and I would never opt for Powershell over bash on Linux/unix systems.

rumia > marisa >>>>>> remilia

Is there a comfier setup for julia than jupyter notebook?

x = [1,2,3,4,5,6,7]
for (i = 0; i

The most powerful programming language is Lisp. If you don't know Lisp (or its variant, Scheme), you don't know what it means for a programming language to be powerful and elegant. Once you learn Lisp, you will see what is lacking in most other languages.

Lisp is for old people.

Lisp is for retards.

Lisp is for you and me.

And C is for dinosaurs

Is it true that the more simple is the language, the harder it is to use?

see Haskell
but no

maybe. it depends on the feature set and overall syntax.
some features simplify rather than complicate the language like generics and metaclasses.

No. JavaScript is simple and easy to use.

const x = [1,2,3,4,5,6,7]
for (let i = 0; i < 5; ++i)
console.log(x.pop(Math.random()*x.length))

In SDL, is there ANY way to get the actual size of a window when using SDL_RenderSetLogicalSize? I need to handle touch events, which come with x,y coordinates normalized from 0..1 over the whole area of the touchscreen (i.e. they are not restricted to the actual window area or scaled to the logical window size).

>JavaScript is simple and easy to use.

Attached: 1847298859.jpg (800x800, 334K)

it is tho

this
JavaScript is neither of those

Reposting my image from last time, making a DSL for generating shapes.

I've just finished adding an Orbit function, allowing a rotation around a point that isn't (0,0,0).

Is there a better program than Microsoft 3D viewer for viewing simple 3D models? This one seems to move your object to center it at 0,0,0 instead of leaving the points where they were.

Attached: Screenshot (128).png (919x399, 112K)

Lisp is for weenies.

No, do not accept this false meme. JavaScript's problem is it's too easy, allowing any retard to program in it.

I'm not sure harder to use is a good assertion, but I would argue it's harder to write good code.

I'd consider C one of the most simple programming languages. I was able to do well on tests in my uni classes because there's only about 8 things you need to know about it and everything you do uses those, but if you were to write a complex program in C it would be difficult to maintain a clean codebase.

That's not even a meme, JavaScript reigns supreme. Everyone from C* programmers to functional programmers are irreparably BTFO. Especially The Man. Utterly rekt by skiddies coding in JavaScript.

Simpler languages force you to think in certain ways. Depending on how well the language was architected that could make it very fast or very unintuitive or very unreadable. See Forth, J, and Brainfuck in that order.

You come home from a big shopping trip with a week's worth of groceries split across some number of grocery bags. Each bag holds at most 10 kg of groceries. You need to carry these bags from your car and into your house, and you want to do so in as few trips as possible. You can carry at most 10 kg at a time.

Given a list of doubles representing the weight of the groceries in each bag, determine how many trips you must make to move all of the groceries into your house.

Example:

Given the following weights: [2.5, 4.5, 10.0, 4.5, 7.1], the best we can do is 3 trips.

I like NP-complete problems because brute force is the correct answer, I dont have to think too much.

Look up the backpack problem

Let's see some code then my dude.

Well if there are multiple bags of the same weight you can optimize. But if that's unlikely (domain is all doubles 0.0

>do my homework for me

Attached: 08e456829afd750f1724bc0fe047023e-d77kvfi.png (420x264, 113K)

fuck doing maths when you've got spoilable shit that needs to go in the fridge/freezer asap
i ain't loosing my fish spread again

I had it in a hackerrank challenge last week

>You can carry at most 10 kg at a time.
weenie

Attached: costco.jpg (400x321, 104K)

There is a lore optimal solution using dynamic programming.

I think there's probably a pseudo polynomial solution if the weights were given as integers, but I haven't tried it.

lightest first? Basically use modulo in some smart way

No, the greedy solution isn't optimal.

Start from the other direction.

>ungreedy solution
nice

Did /dpt/ do any internships during university? How was the experience?

I did three of them. My school had a rule against work-from-home positions as your first job, but I pressured them to break it for me. That was a bit of a mistake, because even if you can code really well there's lots of things about software development that you don't know.

Otherwise it was good experience and much better money than working retail over the summer. I turned my last co-op into a full time job.

Finished hash table implementation a few days ago tested it and it works now i just finished first draft of the self-resizing version haven't tested it yet but here is some untested code from it that i wanted to post because i am ginormous figgot ejnoy

static int resize(int w, int h, int d, struct srstab **tt) {
if (!(tt && validatetable(*tt))) return 0;
struct srstab *t = *tt;
size_t s = srstabsize(
tablewidth(getraw(t)),
tableheight(getraw(t)),
tabledepth(getraw(t)));
size_t s2 = srstabsize(w, h, d);
char vbytes[s];
memcpy(&vbytes[0], t, s);
struct srstab *v = (struct srstab *) &vbytes[0];
if (!(t = v->realloc(t, s2))) {
if ((t = v->realloc(t, s)))
memcpy(t, v, s);
*tt = t;
return 0;
}
memset(t, 0, s2);
initsrstab(w, h, d, t);
srstabsetalloc(v->realloc, t);
if (tablecpy(getraw(t), cgetraw(v))) {
*tt = t;
return 1;
} else {
if ((t = v->realloc(t, s)))
memcpy(t, v, s);
*tt = t;
return 0;
}
}

char *srstabput(const char *k, const char *v, struct srstab **tt) {
if (!( tt
&& validatetable(*tt)
&& validatekey(k)
&& validatevalue(v)))
return 0;
int w = tablewidth(getraw(*tt));
int h = tableheight(getraw(*tt));
int d = tabledepth(getraw(*tt));
while (strlen(k) >= d || strlen(v) >= d)
d

In ruby this is just
{}

>in bloated scripting lang this is just pre-implemented high-level feature
and no one was surprised

install crystal

install lua it's pretty much ruby minus poo and bloat and it's missing a shitload of features compared to ruby but it has gc and built-in hash tables so implementing everything else it lacks becomes trivial

>lua
install Terra

terra seems nice can u use luarocks with it

I would imagine so, haven't tried it though.

>Not grabbing everything in one trip
Not going to make it

if you post post any language other than C++ you are NOT cute!!

Attached: IMG_20190806_173537.jpg (634x1024, 67K)

Having mastered C++ and Haskell, I need a new language to learn. Do I learn Rust or OCaml next?

Attached: 1564172739297.png (528x514, 284K)

Rust because it's fast and I know your NEET ass cares about that

Is it worth getting a PhD in CS?

Attached: renge.png (981x716, 704K)

>Having mastered C++ and Haskell
Are you literally me?

no

I basically have this output of my research
#20190812 Balance publicación y datos histórcos - tridejur
tridejur.uy/t123.php?id=191213&alta=2018-05-16 13:02:00

The bloat makes it more fun.
class Array
def mean
sum / size
end
def standard_deviation
avg = mean
variance = map { |x| (x-avg)**2 }
Math.sqrt(variance.mean)
end
end

Nice try CIA

This is unironically true, but it's slow as shit and takes up loads of memory

Admirable attempt, Mossad.

:- module shopping.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module random, float, list.

:- type bags == list(float).
:- type trips == list(bags).

:- pred partition(bags::in, trips::out) is det.
partition(Bags, Trips) :- partition(Bags, [], Trips, 0.0, []).

:- pred partition(bags::in, trips::in, trips::out, float::in, bags::in) is det.
partition([], !Trips, _, []).
partition([], Trips0, [Acc | Trips0], _, Acc @ [_|_]).
partition([Bag | Bags], Trip0, Trips, Sum, Acc) :-
( if Sum + Bag < 10.0 then
partition(Bags, Trip0, Trips, Sum + Bag, [Bag | Acc])
else
partition(Bags, [Acc | Trip0], Trips, Bag, [Bag])
).

:- pred stupidity(bags::in, random.supply::in, io::di, io::uo) is det.
stupidity(Bags, !.RS, !IO) :-
permutation(Bags, Random, !RS),
partition(Random, Trips),
io.print_line(Trips, !IO),
stupidity(Bags, !.RS, !IO).

main(!IO) :-
random.init(42_31337_666, RS),
stupidity([2.5, 4.5, 10.0, 4.5, 7.1], RS, !IO).
>using a logical language
>bad at logic
my code when.
output:
$ ./shopping |head
[[4.5], [7.1], [10.0], [4.5, 2.5]]
[[7.1], [4.5, 4.5], [10.0], [2.5]]
[[7.1], [4.5], [4.5, 2.5], [10.0], []]
[[4.5], [10.0], [2.5, 7.1], [4.5]]
[[2.5, 7.1], [4.5], [10.0], [4.5]]
[[7.1], [10.0], [4.5], [2.5, 4.5]]
[[7.1], [10.0], [4.5], [4.5, 2.5]]
[[4.5], [7.1], [4.5, 2.5], [10.0], []]
...

printing only length(Trips) = 3:
$ ./shopping |head -100|sort -u
[[10.0], [2.5, 7.1], [4.5, 4.5]]
[[10.0], [4.5, 4.5], [2.5, 7.1]]
[[10.0], [4.5, 4.5], [7.1, 2.5]]
[[10.0], [7.1, 2.5], [4.5, 4.5]]
[[2.5, 7.1], [10.0], [4.5, 4.5]]
[[4.5, 4.5], [10.0], [2.5, 7.1]]
[[4.5, 4.5], [10.0], [7.1, 2.5]]
[[7.1, 2.5], [10.0], [4.5, 4.5]]

You have a repo anywhere?
Would love more merc references to study.

I don't have much yet
check out wangp, juliensf, FlyingJester, and sebgod on github.

How hard is it to implement lazyness into a language?

The best I can do is an upper bound. When the number of bags is N, the number of trips is no more than N log N + 3.

It's easy, you can do it later.

Laziness is just a coroutine so about that hard

What's the difference between laziness via coroutines and laziness via wrapping expressions in thunks

What? The upper bound is trivially N.

it's not worth any level of effort btw. It makes the language harder to understand and use, it lets you do some stupid tricks that are less flexible and harder to use than what you would do in a strict language, and it smooths some edges that only benefit masturbatory type shit.
don't be lazy.

If the number of bags is 10, the bound is 10. But what if it's 13? Then you need 3 more. So it's at least N + 3.

most languages have it already
if you have an and operator and one side is true it might not evaluate the other side

laziness is useful for passive stuff like logging.
lazy by default is a terrible idea, but opt-in laziness for qualifying args is fine.

Atom with Juno plugins

is Head First JavaScript an okay starting book?

it's not eloquentjavascript.net so it's probably not that good.

>having mastered C++

Attached: 1534535798681.gif (200x200, 3.89M)

A thunk lives in the same subroutine, so it stays within the same execution context. A coroutine would have to jump to just to some saved stack state to continue execution.

you will get a job

Attached: 1565545037513.png (689x473, 97K)

i get this part but i guess what i was asking was why would you use a coroutine instead of a thunk

I learned how to make a for loop in C++. Learning asm's going to be a cakewalk.

Fuck off, stupid reddit frog.

It's Ok, C was invented for people who couldn't grasp C++

Attached: 1564309228335.jpg (236x236, 11K)

but C came before C++

Attached: ratl me bons.png (600x800, 259K)

I like coroutines since they can emulate thunks by just running the entirety of the coroutine when a thunk would be used. A thunk would be simpler implementation wise, but then you miss out on having lazily generated iterators. That and I mostly use coroutines, would love to hear some arguments in favor of thunks.

>A thunk would be simpler implementation wise,
this is pretty much the only argument in favor of thunks but also i had to ask anyway because i couldn't think of literally a single argument in favor of coroutines
>but then you miss out on having lazily generated iterators
i'm not so sure about this
your thunk iterator can capture the data structure and recursively call the function that made the thunk so that with each iteration a new thunk is made for the remainder of the data structure
if the data structure is mutable and captured by reference then you effectively have a lazily generated iterator because if the remainder of the data structure changes then the iterator will reflect these changes as you continue to advance along it
if the data structure is immutable and also infinite then there must be some kind of inductive logic to its contents
you can then write that inductive logic directly into the thunk and thus iterate directly over the data structure's infinite contents while eliminating the need for the data structure itself

Do you guys think it's worth it to learn legacy programming? I want to get a job in coding and I'm hoping it will give me an edge.

Or so C programmers would have us believe.

what kind of legacy?

Fortran and COBOL

Depends on what kind of "legacy" you're talking about. COBOL, Fortran, Pascal, and similar languages would be pretty useless.

COBOL still has bank jobs
no idea about FORTRAN though

The legacy code touched my penis.

Attached: FFABF6C9-385A-45E1-A892-7A1CFFB2E2D4.jpg (224x224, 7K)

Look for open positions for cobol or fortran programmers. Depending on how many you find, you can probably make up your mind about how useful their knowledge would be.

I don't want A job, I want a GOOD job

Was it intentional to make forchan sound like 4tran?

Attached: this is a level of shitposting i find difficult to tolerate.png (424x360, 166K)