/dpt/ - Daily Programming Thread

old thread:

Attached: Screenshot-2018-6-13 LINUX is obsolete - Google Groups.png (1642x5511, 874K)

Other urls found in this thread:

xamarin.com/
twitter.com/NSFWRedditGif

First for OP is faggot

Seconded

>remember some user talking about how he fucked up his interview on the whiteboard when asked how to calculate like the first 2 million primes
>whip out text editor and quickly write a c++ program that calculates as many primes as user wants
>works fine, try inputting 2 million
>program is just stuck there since forever

is this normal help
i skip even numbers and i break the for loop that checks if number is divisible by the primes already found if num is in fact divisible by one

Attached: 1517728837089.jpg (400x379, 41K)

>20 years in, Intel cucks AST, puts MINIX in their CPUs and doesn't even give a fuck about notifying him
JUST

>There are orders of magnitude more Minix installations out there
Where's your god now, Linus?

>ARM processors don't exist

The wonders of cuck license, tbhfamlam

Covered in dust most likely

>he says this as phones and tablets and other embedded devices vastly outnumber desktops

Use the inverse of the prime-counting function estimate (x/ln x) to determine how many numbers you need to consider to get the necessary number of primes, and then calculate them all at once using sieve. I dunno if that won't be stuck for some time as well though, I'll try writing it and tell you the results.

Source of that claim?

My ass, apparently. I forgot about , billions of Android devices beat hundreds of millions Intel CPUs. Still, it's true on PC.

Threadly reminder that programming is a subset of anime.

Attached: 1499862358252.png (803x1293, 953K)

>sit on the interview
>nervous as fuck
>forgot what malloc returns
>forgot what's maximum stack size
>couldnt write an example of oop polymorphism
>realize i wasted 2 years at the university
>i wasted my entire life

Attached: IMG_20180612_200620.jpg (640x640, 74K)

I have a great-great-great idea: it is possible to make a universal multilingual toolchain that will allow to do things like
// some-file.ts
import { Maybe } from "haskell:Data.Maybe";
export const value = Maybe.Just(1);

// Some.Other.File.cs
using SomeFile = TsImport("some-file");
using Show = HsImport("Text.Show");
...
System.Console.WriteLine(Show.show(SomeFile.value));


I know how to do it, but this kind of project would require years of work, it would not be easily adopted in enterprise because of the monsters like Visual Studio, and it would be very unrewarding overall.

So, I want someone else to see and implement its.

I spitted out my idea, now I'm free to go.

Attached: ShinyTheseBushsqueaker.gif (1000x550, 2.62M)

Just got a new project idea to share generic type parameters in .Net

And anime is a subset of Maths.

How do I stop masturbating 5 times a day and actually finish the programs I started writing ?

How come you fucked up the code tags now, you posted it correctly the first time around.

How long does a single masturbation session take for you? In my case it's ~20 min so I can't imagine how it can take up a significant portion of your time even if you do it 5 times a day.

Use Rust and a chastity cage.

Can someone explain to me why memory alignment is important? Why must an int, for example, be 4-byte aligned? How is accessing misaligned data slower than accessing aligned data?

Attached: 1472199356097.png (314x278, 129K)

Cache lines are aligned by 64 bytes IIRC, so if an int isn't at least 4-bytes aligned there's a chance it'll be split between two cache lines, making it's slower to access it. Also there are a lot of CPU tricks to optimize memory access like prefetching, which don't work well on non-aligned data.

Doesn't stack size vary?
knowing neither basic C or POO concepts is pretty bad thouhh

Well if processors read from memory in word sized chunks and you don't align to that, you'll need to mask out the irrelevant bits in order to access the misaligned chunks.

I forgot about tags when I copy-pasted it :c

Isn't the cage redundant if you already have rustc?

At first, yes, but over time you get used to rustc and it doesn't feel restrictive enough.

In the week when I go to work, it's like 3/5th of my evening is spent masturbating, 1/5th doing house chores.

I think you can implement a Maybe monad in C# quite easily

So i had to inteview potential applicants for js/react/redux job. So i decided to ditch requirements (if no work experience i wanted github or some repo) and shit and just ask for skill and knowledge. Ive put in job description following: bachelor level or cs knowledge, intermediate knowledge of react/redux, good knowledge of js, good knowledge of git, elementary knowledge of sql, php, laravel.
Starting sallary 80k€.
I wanted ro say dont be brainlet but well.

I had to flunk 10 people on basic cs shit, are front devs retarded
Write O(n) for arrays, hash maps, binary trees, linked lisfs
Explain proof by induction
List all datastructers used in js stdlib and write O(n)s for all ops
Height of binary tree
Explain http http/2
Server client architecture
Explain whats cache miss
Sum of n natural numbers
O(n) of various js snippets

God damn brainlets

Yeah, basically something like this, this is fast enough. Finishes in under 2 seconds on my Core 2 Duo, so it should run very fast on modern processors.
#define N 36000000

int main()
{
static char is_prime[N];
memset(is_prime, 1, sizeof(is_prime));
int m = (int)(sqrt(N)+1);
for (int i = 2; i < m; i++) {
if (is_prime[i]) {
for (int j = i*2; j < N; j += i) {
is_prime[j] = 0;
}
}
}
int n = 0;
for (int i = 2; i < N; i++) {
if (is_prime[i]) {
n++;
printf("%d\n", i);
}
}
assert(n >= 2000000);
}
N was chosen experimentally since it turns out calculating the approximation of the inverse of x / ln x is harder than it seems and I'm short on time. This is a one-off snippet, obviously you should use dynamic allocation and structure your code better when answering an actual interview question.

All that for front end web development? You're kidding yourself, nigga.

>>forgot what malloc returns
What do you mean? The type of what it returns? If it can return NULL or not?

Im paying u 80k for entry level job at least have basic level of education. I wanted smartish people or at least educated that can learn. Idc if u dont know how to use entirety of react, if you are not retard youll pick it up fast. My actual programming part would have been easy. If u can make something like Jow Forums good enough

Attached: ____.png (625x626, 66K)

>Write O(n) for arrays, hash maps, binary trees, linked lisfs
That sentence doesn't make sense.
>Explain proof by induction
Why?
>Explain whats cache miss
Is it really relevant for the job you are going to offer?

>Explain proof by induction.
The requirements for your shitty front end job can't be fulfilled by the brainlets who would be willing to do it, and the job itself is not of any interest to people with knowledge needed to satisfy your requirements.

>but i throw money at you!
Good luck.

>He can't prove proof by induction
Wew, lad.

Attached: hume.jpg (289x352, 52K)

anyone ever done some minecraft modding?

Yes. Quite a while ago. You should just ask instead of asking to ask.

I bet somw high schools do proofs by induction... seriously is it that hard thing to ask?
I asked explain not prove, or in other words describe how you prove something by induction. So hard...

Also i said bachelor cs knowledge in job application, induction is first year everywhere in the world

So if I have a frontend made with Python, which will interact with the user and parse their input, and the backend with Haskell,
does that means I also need to re-parse and rebuild the syntax tree in the haskell back-end?

>seriously is it that hard thing to ask?
It's not just about that one particular question. You're looking for applicants with wide knowledge to do a boring shitty front end job where they will rot not being able to use any of it.

>tfw too brainlet to implement sieve of atkin and have to use inferior eratosthenes

Attached: 14004028.jpg (800x522, 28K)

Proof by inductions is freshmen shit what the fuck guys

Yes, but you just use some common format, every language has a library for, like JSON. That way the intermediary format parsing is mostly transparent.

Probably a dumb question:
How do you develop for iOS on a non-apple platform? Everything produced seems to be tied to apple products.

I wanted to test that they retain some of that education and thus eliminate idiots. How do you get smart people without experience otherwise?

Qt Quick and buy an iPhone to test it on. Otherwise you are cucked into developing on an Apple machine too.

xamarin.com/

doesn't matter, eratosthenes is fast enough, see

Forgetting the knowledge you never use in your daily life (and you can be sure proof by induction is in that category for almost everyone) is normal. Actually expecting smart people to respond to your shitty frontend job is extremely optimistic. Don't look for smart. Look for ones that can do the job.

So that also means that I have 2 program running together, one acting as the server, and another one as the client?
That seems very tedious and bloaty for a single program.
Also how to make a synchronize the program so they will run together and exit together?

This user answered it
But to give you use case. You want to make front end in some slow but easy to use language and thus spare time i.e python but your data requires some heavy processing which makes python unsuitable. What you can do is make front end in python and process data in sepples and send it in some standard format like json for e.g. You have slight ivergead with that but it potentialy saves lots of devel time and is much faster than python

I meant this for
You send requests like on web or something

>So that also means that I have 2 program running together, one acting as the server, and another one as the client?
Yes.
>That seems very tedious and bloaty for a single program.
The advantage is that you can have an infinite amount of clients connected to the same server and they can be running in separate places in the network.
>Also how to make a synchronize the program so they will run together and exit together?
You can, but you generally don't. You keep the server running and spawn/terminate clients as you go.

Just compile your haskell bullshit for the COMMON LANGUAGE Runtime and anybody in .Net land could use it.

I think haskell has C types too which would be a lot easier than implementing on CLR because it might end up being not CLS compliant. Things like typeclasses can be implemented zero cost by the compiler but real support for it and hkt requires clr rewrite and that is quite... not easy because of the big c++ legacy code there. Good thing they are planning on rewriting the clr in C# using corert

Attached: benchmark_game.png (1180x364, 56K)

Are there any cases where it makes a difference to use the register keyword?

>Are there any cases where it makes a difference to use the register keyword?
From what I've head, most compliers pretty much ignore it.

You can't access the address of a variable marked with the register keyword if the compiler ends up respecting it.

`register` is deprecated since C++11 and removed in C++17. I guess the C standard committee will follow the lead.

don syme (c# generics guy) hates typeclasses (and monads, HKT), still won't introduce them to F#

F# will be forced to implement typeclasses when Shapes and Extensions gets merged into C#, C# is a first class language in .NET. F# gets shit all, even though .NET CLR originally was meant to support many languages. (MSR prototyped with Haskell .NET)

Yes, the type. Was asked what would you do if it's incorrect (or something). I said malloc is not type-safe, so it's a programmer job to trace what is allocated or not. I said it returns void (without mentioning a pointer). Then proceed to fuck around, said "no, not void". Was asked if you could add two pointers, told no. Then they went, like, "really?". And I started to mumble and spill spaghetti again, wrote (*p1 + *p2) and got the answer that it's not right, what's the '*' operator? One more question is "why do we need IP if there are MAC which are unique?".
Was asked how to clear the contents of file, then I said "use cat", but didn't specify "how". So then I just mumbled that you might use vi/nano to do it manually.

I knew about poly, about inheritance and encapsulation, I used it and even answered alright on CPPQuiz, wrote OOP shit, knew about pure virtuality. Speaking about encapsulation, told that public can be accessed anywhere if method/variable is static, accessed from a instantiated class if it exists, protected are only viable if there's a protected inheritance, private could not be accessed from anywhere besides methods/classes declared as friend.
What I didn't know -- what's the stack size, where '*this' is stored, if I can convert A class to B using static_cast.
Algorithmic task was to get all unique elements from array. Said it could be done in O(n^2) if you just bruteforce and compare every element with one another, O(nlogn) if we sort and compare adjacent elements. Or we can put everything in the set.
Holy shit, I am so fucking embarrassed I failed on these easy questions.

Attached: 1503492059955.png (710x842, 573K)

I'm learning python after I arrived from the past in a qbasic powered time machine.


I'm watching random tutorials and reviewed some materials from my uni. It seems that a lot of stuff is actually available in the non-default set of instructions, like you can make a graph just with 4 lines.

Are the modern languages all about knowledge of libraries useful for what you're doing? Because for drawing graphs I'd imagine you'd 1st to prepare data, prepare something that draws lines, and then calculate how to draw these lines.

Also how do I make my python scripts into websites?

Are MTA, MCSA, MCSE, CompTIA A+, CompTIA Security+, CCNA, MTCNA and MTCRE certs worth it?

Is any of them less worth than the others?
I'm thinking on enrolling into a cert school in my town to further educate myself and possibly move up in the job ladder.

Would it be better to just learn independently and prove myself on the interview?

Why is linux worth programming in? I was thinking about getting a thinkpad and setting up ubuntu but I don't know if it's necessary.

Attached: flat,800x800,075,f.jpg (800x402, 67K)

void A(); void B();
static int i = 0;
void A() { ++i; B(); }; void B() { ++i; A(); };
int main() {
A();
return 0;
}


Is it stack overflow?

Attached: rust.png (1213x820, 39K)

Library management and compilers aren't as much of a PITA as on Windows.

What do when need mutable references to two elements from a collection?
Am I really supposed to get these values out of the collection and insert them back when I'm done?
Is this hell?

Attached: BzbFfITCYAEzBfb.jpg (362x362, 21K)

Forgot to say I'm using Rust.

Attached: images.jpg (232x217, 11K)

Best girl

Attached: Screenshot from 2018-06-14 00-41-22.png (2094x628, 244K)

Which collection, what are you trying to do?

yeah I'd imagine so

>Which collection
A hashmap
>what are you trying to do?
In general terms, get two elements by their ids and execute a function that is supposed to get mutable references to both.
Specifically, I have structs representing state change that are supposed to be sent through a network so I can't really use RefCells because these can't be used like that and I use indexes instead.

Any Java shills ITT?
If I use Scala on Graal, and the program uses GTK bindings, will I get the performance optimizations from truffle?

Is this answer OK?

Hopefully F# community pushes the bar higher for HKT and HKP. That way we can also get it for C# and CLR rewriting will be much more meaningful to ease up the interop between the two langs and implement these features as first-class citizens

Well you obviously can't have mutable references to both, but RefCell usually helps.

Bringing my post up.
Is there any list of the "basic" libraries I should know and work on every python machine?

Good post

what problems were monads created to solve?

Why does this not work? it works at 48 but on 24 it just prints the "press enter to continue..." but it doesnt wait like it should

#include

int main(void){

int i,n;

printf("This program prints a table of squares. \n");
printf("Enter number of entries in table: \n");
scanf("%d", &n); //get input for amount of squares

for (i = 1; i

>what problems were monads created to solve?
They just make certain things simpler. A lot of people go way too abstract and theoretical when explaining monads. Mostly, monads are a pattern that comes up over and over again in programming. By recognizing that pattern, we can simplify our code and avoid reimplementing certain functions.

put
while (getchar() != '\n');
after scanf to flush the input of any newlines

What are the most comfy programming jobs?

those that pays you money

another note: this will work but you shouldn't do it desu

#include

int main() {
int a[] = {1, 2, 3, 1, 2, 3};
for (int *p = &a[0]; *p; ++p) {
std::cout

Attached: 9JN8mfTLT-o.jpg (1280x853, 131K)

>*p

C/C++ arrays aren't null terminated, i.e they don't end with zero which is what you're checking with *p

should be
int a[] = {1, 2, 3, 1, 2, 3, 0};

also it's helpful to know that &a[0] is the same as just a

sending a one line pull request to a project that hasn't been updated in 4 years

Good/recommended IDEs for C++ development?

CLion, Visual Studio, Qt Creator.