/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1528437831742.jpg (1280x720, 559K)

Other urls found in this thread:

en.wikipedia.org/wiki/Erik_Demaine
erikdemaine.org/
en.wikipedia.org/wiki/S-expression
youtube.com/watch?v=YQs6IC-vgmo
twitter.com/SFWRedditGifs

leetcode

my wife, nenecchi, is so cute

fuck python

JSON is okay for exchanging data.

Waiting for Gentoo to finish compiling while shitposting on yotsuba channel.

Starting off with the hot opinions, nice!

Attached: Screenshot from 2017-12-20 01-27-09.png (754x209, 22K)

>why yes user, i would be interested in seeing your assembly program

Attached: cute.png (1000x1500, 1.84M)

en.wikipedia.org/wiki/Erik_Demaine

>He was home-schooled during that time span until entering university at the age of 12.
>Demaine completed his bachelor's degree at 14 years of age at Dalhousie University in Canada, and completed his PhD at the University of Waterloo by the time he was 20 years old.
>Demaine joined the faculty of the Massachusetts Institute of Technology (MIT) in 2001 at age 20, reportedly the youngest professor in the history of MIT

erikdemaine.org/

Could you even compete to this guy?

Attached: halloween2007_small.jpg (317x347, 95K)

JSON is the best way to exchange data. It's not good, but everything else is shit.

>json is the best
>it's not good

Yes, that is what I've said.

Why would I want to compete with that guy? He seems cool.

I have autism, sorry.

en.wikipedia.org/wiki/S-expression

Attached: wow anon.jpg (884x574, 78K)

extracting shared code into classes for reusability

too uncanny valley

Attached: Screenshot_20181220_033838.png (1920x1080, 3.05M)

user, it's the second time this week that you missed your JavaScript lesson

Attached: 3152485e3cd8f1314b3e6ecab1fc977a.jpg (798x1199, 160K)

brb writing assembly

>needing lessons for JS

>everything else is shit.
less shit*

So, you're still using text to represent them, right? Because then you basically have the same issues as with JSON while also missing the widespread support that JSON.

in c++, why can't I reinitialize a pointer with curly bracers?
>Base2* bp {new Base{}};
works
>delete bp;
>bp{new Derived2{}};
doesn't work
>bp = new Derived{};
does

Dalhousie mentioned

Have you read your SICP today?

Attached: thiscomesnextaftersicp.jpg (600x510, 480K)

braces are for initialisation, not assignment

is there no thing such as reinitialization?

Attached: 1545421492017.png (558x614, 24K)

>missing the widespread support
Who cares if you can just (eval data)?

Attached: Screenshot from 2018-11-14 23-03-06.png (1920x1080, 186K)

that seems insecure

no

i fucked up the perspective for the screenshots, but holy fuck, I think i got the math correct for the inverse kinematics of my robot. Now it is probably koding tiems. I still can't believe that it actually displays the results i was expecting. Fuck me.

Attached: ik_first_test.jpg (1926x5356, 824K)

Because initializer lists work only on... you guessed it, initialization.
If you want to assign a new value to an existing variable, you must use =.

No.

Also, braces can be omitted when using new.
But you shouldn't use new at all anyway.

That looks nice, user.
What are you using? Got some usable version or code available somewhere?

So all in all, I can only initialize an object at the same line I (first) declare it?
>you shouldn't use new at all anyway
why is that? not even with smart pointers?

Attached: 1539599769391.png (645x773, 107K)

I'm fucking do it bros
I'm building my fucking GUI using Electron
I've tried GTK, I've tried QT5, but all these crossplatform gotchas and C++ in general just pisses me off. I'm too much of a brainlet to utilize them properly, I admit it.
Using plain HTML and CSS to style my GUI, then using javascript for minor interactivity on the page, then calling an Elixir back-end compiled to an OTP release to actually do shit. Werks on both windows and linux perfectly.
Why the fuck is modern crossplatform GUI programming in the supposed "proper" way so fucking hard aaaAAAAA

Attached: 1558822573158.png (800x600, 1008K)

```javascript
let a = test
```

it's fine as long as you only accept signed data from trusted systems

Attached: Screenshot from 2018-10-07 22-19-21.png (1920x1080, 3.72M)

what if I want to accept data from untrusted sources?

if the declaration is a definition then it also initialises
and initialisation only takes place in a definition

avoid naked new unless you're messing around with low level shit, smart pointers have factory functions instead

I'd like to learn a bit of machine learning. I have a program which reads in a file for its input parameters, processes some stuff, and then outputs a result to a file.

I would like to use machine learning to iterate the input parameters (start with 1, but in future allow it to change multiple values) and then read the output value, slowly trying to generate as low a value as possible.

Is this something easy, or is this quite difficult? I'd like to avoid having to learn the maths, just want a library to call and run sort of thing.

Are you that chicken kicker boy?

>So all in all, I can only initialize an object at the same line I (first) declare it?
Yes, because that's what initialization is by definition.
>why is that? not even with smart pointers?
You have make_unique and make_shared for that. They are safer than using new, even when using smart pointers.

then you have to scan the data for malicious content before eval'ing it

Attached: Screenshot from 2018-08-12 03-13-55.png (1057x459, 324K)

shouldn't you use read instead?

#!/usr/bin/env python
def machine_learning(param):
return float("-inf");

Then you should use proof carrying code.

so I need to have an antivirus built into my program? how about a limited subset of s-expr that can only contain data but not code?

>What are you using?
ROS2 and RVIZ2 for visualisation.
>Got some usable version or code available somewhere?
Not yet, but if the IK works, then I should really get myself together and write this shit up, because it was quite headache inducing and would be nice to have it written somewhere.
Kode is not up, because just a hacky mess for now. I'll promise, that I'll upload it someday somewhere.
Fuck lol, deleted le webm of moving leg. But nvm, if the math works i finally can move on to print the whole robot and get it walking.

You can get pretty far without actually understanding it indepth, but getting it to run well (both in terms of performance and effectiveness) needs more indepth knowledge.

(read port)

on 2.2 by boy

No. Does chicken kicker boy also play this video game on GNU plus Linux?

Attached: Screenshot_20181220_153832.png (1920x1080, 2.18M)

What about qt or some other toolkit for python?

There is placement new as a way to reinit. Be careful to not leak.
#include
#include

class myclass {
public:
myclass()
{
puts("constructor");
}

~myclass()
{
puts("destructor");
}
};

int main()
{
class myclass thing;
class myclass *ptr;

ptr = new(&thing) myclass;

return 0;
}

I want to make an app that lets me use my android phone as a virtual mouse pad and keyboard for my windows 10 desktop by connecting with bluetooth. Is this possible? If so how difficult would it be for a beginner programmer and where exactly would I begin? I only have experience making small windows programs i.e. small college projects.

had a copy on muh fone. If you didn't see it yet, I have a physical copy of the first leg and can control it with a gamepad already (which, for one leg, doesn't need any math at all).

Attached: 1558644518503.webm (1280x720, 2.67M)

A-user, that's lewd.

Never used python

nuthin, just fucking around.

Is such a think even possible?

Yes it is.

thanks. Good double number (the 4 is occuring two times right next to eachother in your number at the end of the number)

don't do this unless you call the destructor explicitly first

Imagine spending a couple hours on this, then to try it out and decide within 20 seconds that it's a piece of poop that nobody wants.

I don't really care if anyone uses it I just want it for myself.

just use a mouse?

Attached: 1559155686599.jpg (288x450, 93K)

>Imagine spending a couple hours on this, then to try it out and decide within 20 seconds that it's a piece of poop that nobody wants.
What are you going to do that's so much better and useful in those hours?

But I want to lie back on my bed and relax. I could buy a wireless mouse but I could also just use my phone.

...

Pretty easy. The only part that isn't totally trivial is using the android bluetooth interface + using a fitting bluetooth library for your desktop application, but if you aren't a total beginner you shouldn't have too much trouble.

I'd go to the electronics store and get a new mouse or whatever.
If its because you want to make netwroked programs, try making a chat client instead.

i used something that did this over wifi

Why are LinkedLists rarely used in most source/applications I see? I always see an ArrayList (Java) used by default even though it has the cost of copying the array every single time you insert a new member. Many times you're just inserting many new elements into a list and then dumping its contents out somewhere. Wouldn't a LinkedList be better in that case (since the cost of adding an element is basically O(1)).

Attached: brainlet.png (621x702, 56K)

Linked lists are very useful when you need to do a lot of insertions and removals, but not too much searching, on a list of arbitrary (unknown at compile-time) length.

Splitting and joining (bidirectionally-linked) lists is very efficient.

You can also combine linked lists - e.g. tree structures can be implemented as "vertical" linked lists (parent/child relationships) connecting together horizontal linked lists (siblings).

Using an array based list for these purposes has severe limitations:

-Adding a new item means the array must be reallocated (or you must allocate more space than you need to allow for future growth and reduce the number of reallocations)

-Removing items leaves wasted space or requires a reallocation

-inserting items anywhere except the end involves (possibly reallocating and) copying lots of the data up one position

because poos in loos don't get pointers

neither do you, Rajesh.

The cost of allocating new arrays is amortised. The ArrayList overallocates its underlying array so it only needs to allocate an entirely new array on rare occasions. Usually the new size is double what it was previously. You can even set the capacity ahead of time if you know the maximum size of the list so it doesn't reallocate at all.

>Why are LinkedLists rarely used in most source/applications I see?
Either your fellow pajeets don't know their datastructures, or they aren't the right choice in the scenario.

>I always see an ArrayList (Java) used by default even though it has the cost of copying the array every single time you insert a new member.
Untrue. It is O(1) insertion until you fill up the capacity. Then a O(n) copy-resize op to twicify the size.

>Many times you're just inserting many new elements into a list and then dumping its contents out somewhere. Wouldn't a LinkedList be better in that case (since the cost of adding an element is basically O(1)).
It would be even better to not even build up lists at all.

>it has the cost of copying the array every single time you insert a new member
This is where you are wrong.

shut up, Rakesh. I am better at Javascript then your

>twicify the size
Why do I have a feeling there is a Factory Generator pattern used to do this "twicification"

Attached: 1436832831810.jpg (228x238, 13K)

It's all under the hood. You just do ArrayList.add and it doubles the capacity whenever it has to.

Well in Java the default size is 10. I am wrong though to say that it increases the size each time. It looks like, based on the JDK version, the growth factor can be 1.5 (jdk 8) or maybe 2.

It's not.
int newCapacity = oldCapacity + (oldCapacity >> 1);

you can prove that arraylists have amortized O(1) insertion time, which is usually all we care about.

>Linked lists are very useful when you need to do a lot of insertions and removals
wrong.

youtube.com/watch?v=YQs6IC-vgmo
TLDR: In practice, linked lists are garbage for random insert/removal performance at any non-trivial scale. The common viewpoint doesn't take into account the fact that real life computers have cache, an array/vector is a contiguous block of memory and therefore very cache-friendly, and every discrete traversal across a linked list involves multiple cache misses.
Unless it's *exactly* what you need for *exactly* your use case, a linked list is probably not the way you want to go, performance-wise.

>, a linked list is probably not the way you want to go, performance-wise.
no shit senpai

use your brain instead of sperging memes

what did she mean by this?

>It would be even better to not even build up lists at all.
Imagine you don't know the size of the array and you want to collect a list of primitives or objects and then dump said list. What would be the alternative?

based and amortization-pilled

>all these leetcode questions where 99% of the work is edge condition checking for maximum and minimum int values
kill me

>insertion and removal = traversal
You fucking retard.

this, the presentation includes traversal times in the deletion and insertion, which is fucking retarded.

Anyone got some ideas for shit I can put on a GitHub to show I know python enough to do an entry level job? What kinds of stuff did you guys show off to display your skill when you were new?

Unemployed NEETs need not reply, wagies only

ArrayList stores the references to its elements in a contiguous array. Copying those references to grow or insert is way cheaper than chasing pointers endlessly.

Do some basic ETL garbage where you grab data from a public API, transform it, and store/present/visualize it somewhere.

can /dpt/ solve this problem in O(n) time and constant space?

Attached: 1539251359381.png (1316x888, 89K)

>smallest missing positive integer
I don't get what it's asking. How do you define an integer that is missing?

>What would be the alternative?
Something like an iterator. I was going to make an elaborate huge example of some REST API where you can request a JSON array of all customers where the customerid is a prime, but I'll just describe it instead of actually implementing it.
Instead of doing this (pseudocode)
Response someRestAPI() {
ArrayList al = {}
foreach customer in customers {
if (customer.id.isPrime()) {
al.add(customer);
}
}
return al.toJSON();
}

This will build up huge lists in memory when there are many customers, and it is totally unnecessary in this case. What would be better is something like
/* Lets pretend this sets the header Transfer-Encoding: Chunked and handles it properly */
StreamingResponse someRestAPI() {
StreamingBuffer buf;
foreach customer in customers {
if (customer.id.isPrime()) {
buf.streamout(customer.toJSON());
}
}
}

the "missing integer" is the smallest positive integer not in the array