/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

45.32.80.36/board.cgi
youtube.com/watch?v=imtPF2b2Q4M
people.freebsd.org/~lstewart/articles/cpumemory.pdf
humblebundle.com/books/joy-of-coding-book-bundle
projecteuler.net/problem=35
twitter.com/NSFWRedditVideo

KYS

Too early edition

Are you even the real trap poster?

wtf i hate anime now

does anyone here actually use typedef's? seems like it would make shit more confusing.

every time when using a struct
and sometimes (which I will be bashed for since it's not portable, but idgaf) I typedef unsigned char to u8, signed char to i8, short to u16 and i16 and so on

I'm writing a messageboard system in C!
45.32.80.36/board.cgi

I'll be working on adding some formatting tomorrow, goodnight!

Currently buying some programming books

Are "The C Programming Language" and "The Go Programming Language" good or are there better books on both languages?

>I typedef unsigned char to u8, signed char to i8, short to u16 and i16 and so on
Why the hell don't you use stdint.h?

They make using function pointers a lot neater.

in C++ i'd use using

What's the market like for assembly programmers?

I don't really care about their size, I just wanted shorter names...

nonexistent

its so hot right now, dont miss out

if you actually care about the length of your type names, you're either doing something horribly wrong, or you're bikeshedding.

You're not one of those retards who creates functions that ask for 20 separate variables, right?

Welp, there goes my intimate connection wit the machine

>I just wanted shorter names
You're saving like 2 letters at most.
And as the other user said, it's a pointless goal.

>be chemist
>4 years at uni
>Perfect GPA of 4.0

>younger brother dropped out of uni after one semester
>dicked around doing part-time casual jobs for a couple years
>recently got a job doing web dev with no previous experience or structured learning
>earns just under $70k a year

>I get $50k a year and work more than he does

Why is this allowed /dpt/?

He didn't fall for the college meme like you did.
Also, I'd like a McPick 2 mcdouble and a McChicken to go.

should've taken maths
>any job I want
>$150k starting

wheres he located? and what is he actually doing to make 70k a year doing fucking web dev

Nah, I didn't fall for any college meme. I studied chemistry because I find it interesting as fuck. I only started studying as a mature aged student after spending a couple years working in totally different industries (finance).

I work in a pharma lab, so I can't legally give you anything I make.

Sydney, mobile ads.

more like the the STEM meme

didnt know programming mobile ads market was hot

interdasting

>Compile ARM-flavored elf ball on laptop with static linking
>scp it to Raspberry PI
>works
>scp it to phone
>works without recompilation.

This is satisfying and I am not sure why it is satisfying.

i've got a mechanical engineering degree with a 3.9 gpa and now i'm a phd student earning ~25k/year because i couldn't find a job after graduating. in all likelihood, i won't be able to find a job if i finish the phd either.

some people are lucky, some aren't.

jesus

i know someone who has her masters in physics and cant find a job

seriously im voting trump

embrace static linking

>learning c# programming
>doesn't understand a single shit about oop
I am going to kill myself. nice knowing you guys. It's hurt to be this retarded

ask and we shall answer
What don't you get?

do you know procedural programming?

fuck c# and do c/c++. I started with javascript and wish i would have started with c/c++

I have a stupid question.

Why do I need to download a compiler to get a language working, when there are hundreds of applications on my computer written in various languages already working without one?

Why did you wish that?

Started with PHP, moved to JS and now I'm trying to learn C and Go.

web dev wont teach you real programming thats why

>now I'm trying to learn C and Go
>trying to learn
Answer is embedded in the wording of your response.

PHP's syntax is somewhat similar to C, but that's about it. People are much better off starting with either of two extremes:
-A scripting language like python, or batch
-A low level language like C, C++, and a bit of assembly.

Often people starting by learning java(script) etc begin to pick up bad ways of thinking about their interaction with the machine, and accumulate these maladaptive tendencies. It also doesn't spur them to understand what the machine is doing, why, and how.

I learned more trying to make things work in batch than I imagine someone would learn dicking around with java.

What are your thoughts on learning two languages at once, one scripting and the other low level? Is it a pointless exercise - would the person better spend their time focusing on one entirely?

there are three kinds of languages: interpreted, compiled, and virtual machine ones

compiled ones change the code (text) into a binary file (exe) and you don't need the compiler for it to work on your machine (C, C++)

virtual machine - those are compiled but work on something like an emulator, you have to download the virtual machine for it to work (check your programs for the .NET framework and Java runtime environment, those have a virtual machine)

interpreted - "scripting languages" you don't need to compile it, you just run it straight from the text file, you need the language installed. windows batch files and unix shell scripts are interpreted, so is the javascript inside your browser.

I said trying to learn because I started yesterday. Just ordered a few books for both languages.

There's some shit I don't get yet but I wouldn't say starting with Javascript is inherently bad. It led me to check out other languages because I wasn't satisfied with the performance of JS for my web applications.

those applications are already compiled, they just are getting executed

you need a compiler to get a language working because that language and all the syntax need to somehow be "converted" into machine code so the computer can execute it

That makes a lot of sense actually.

So what does a compiler like MinGW do for C and C++? If you don't need it, why get it really?

you don't need it to run compiled programs
you need it to compile programs, to make them

how normie is it to have this playing in the background?

youtube.com/watch?v=imtPF2b2Q4M

I already learned c and java.

Not that guy - but I think it makes more sense to learn a high level language while learning how low level stuff works.
Learning C doesn't teach you everything, and there will still be huge holes in your knowledge if you just learn what's necessary for C.
Basically, start with basic EE (or physics if you're into that), move on to shit like TTL, then simple processors and how they work, learn a simple assembly, understand how computers as a whole work, maybe learn a bunch about more modern systems to learn about stuff like the L1 cache, understand how a simple OS and its components work (Minix is a good example) and then do a bunch of stuff related to networking and the different OSI layers.
That's at least how I did it, and the learning courve wasn't too steep for me because I could always build up on the things I learned before.
At the side I learned a high level language and moved towards more low level languages from there. Once you get to the point in my list where you understand how a simple OS works, learning C is a breeze.
That being said, resources on the internet for learning low level things are often abysmal compared to what you can find for getting into programming.

>I think it makes more sense to learn a high level language while learning how low level stuff works.
I definitely want to learn as much as possible, but my concern is having something functional to play around with. My main focus is already on C, but I wondered if it was feasible to pick up something like Python on the side, for simple projects. The added bonus would be learning about different types of languages, at once.

>start with basic EE (or physics if you're into that)
Isn't this step alone pretty difficult? I've really wanted to try and learn physics by myself for a while now, but surmounting calculus has always been daunting and hard.

python is for little shit. Learn some manly language like c# and c++.

Well I'm already doing C, isn't the transition from that to C++ pretty smooth?

I've thought about C#, but seeing how I'm going into C++ sooner or later, is it worth knowing both? I've heard people say how C# improves on the flaws of C++, so it sounds like there's a lot of overlap there.

Writing my own forum software since everything else fuckin sucks. Unless anyone can show me ine thats nit made in some shitass bloated manner with a decent ui and doesnt look like it came from 1990. Oh and one without so many security flaws woukd be nice.

simplemachines is pretty nice

What language are you using?

Rust. These dynamic languages are too slow.

It really depends on the person. At such a point where you're asking this question, the point of its answer is already nullified. It's already apparent you have the drive, and probably the means, to iterate and do what needs to be done. As for how to engineer that process, it's up to your own metacognitive tendencies and how your brain tends to work.

Ultimately though I'd only advise learning one thing at a time. Bounce and contrast it against something else without getting too heavily into it, to avoid compartmentalization and to better understand the whole. ie, if you're learning a scripting language, learn a bit about the low level and think about how the interpreter, JIT, virtual machine, whatever, works. Learning something low level like C, focus equally on how memory works, basics of assembly, why eg an XOR operation takes at most one cycle, how something like an interpreter would be written and how it's parsing the text, how the compiler works, etc. This is why I say starting with C/C++ is much better, it affords more. It lets you better understand the underlying logic.

But it depends on a lot.
Read this regardless:
people.freebsd.org/~lstewart/articles/cpumemory.pdf

>calculus
EE and physics, in a functional (mathematical) sense, aren't useful for programming. You only need to understand the universe in an abstract way. You're influencing a machine, not designing a circuit board or calculating the probability a given photon will be transmitted through a material.

Never heard someone building something like this in rust. How does that work? Do you still work with databases and if so, which one?

Ultimately I think you're right, it's probably better to focus more heavily on one language and worry about picking up other stuff later. And thanks for the link, I'll try and work my way through it even with limited knowledge.

As for the part about physics, my interest in it is separate from programming, but it's nice to see them overlap in this way.

>You only need to understand the universe in an abstract way.
Actually, abstract isn't really the right word for it. You only need to understand and think about the universe's logic in a hard mechanical way. Something which has unfortunately become supplemental to the mathematical approach.

It works same as any other language. Write html generators, output to fastcgi or scgi. The web server forwards requests/gets responses from one of those protocols to your binary.

Probably not going to do the traditional db route. Setting up a database server is annoying, trouble to admin, etc. Plus latency. I dont have a clear plan yet, but I'm thinking a hybrid of git style content addressable tree, maildirs, and nntp spools.

>I'll try and work my way through it even with limited knowledge.
It starts with the base elements and builds very logically and intuitively. Should be fine if read in serial order.

C++ is still a compiled language.
It has all the advantages and disadvantages as C.
It provides a lot of extra tools you can use.
A good example is strings.
String is a class which have operator overloads, extra variables such as size of the string.
It can be dynamically resized and is therefore optimized for strings of text.
Where in C (without libraries) you have q pointer to a char and it ends when you write 0.
This means passing strings to functions is harder and you have to be more careful when you use strings in your application.

When you apply this way of thinking to all classes you make, programming becomes a lot different.
So don't say you know C/C++ as they are the same thing.

C# is different, but I don't have any experience with it. I just blindly think C++ is better without any reason behind it.

the best game engines are written in c++ so theres good reason behind it

c# is different than c++ because it use virtual machine(Common Language Runtime) like java.

It's just somehow less a pain to code in if you just want to make simple shit or a website. Because you mostly do not want to worry about allocating memories of every little shit you want to implement.

Having trouble with a programming assignment.
What's the best place to go for help? I now /dpt/ isn't willing too but maybe you know somewhere.

what is it?

If you are actually willing to learn and you are actually able to search for solutions yourself, stackoverflow.

It being an assignment and you not finding help means that that second thing is the issue 99% of the time.

Thanks. Yeah I'm an engineer that got put into a b level computer class so I'm way out of my depth. Never programmed before.

#include
#include
#include
#include "node.h"


struct node_int {
void *data;
node next;
} node_int;

/*
* 'Constructor' for node
*/
void init_node(node *n, void *o)
{
*n = (node)malloc(sizeof(struct node_int));
(*n)->data;
(*n)->next = NULL;
}
/*
* Getter for data
* Return data field
*/
void *get_data(node n)
{
return (n->data);
}

/*
* Getter for next
* Return next field
*/
node get_next(node n)
{
return (n->next);
}

/*
* Setter for data
* Param o value to be placed into the node's data field
*/
void set_data(node n,void *o)
{
n->data = o;
}

/*
* Setter for next
* Param x value to be placed into the node's next field
*/
void set_next(node n, node x)
{
n->next = n;
}

I posted this here before - the function bodies had COMPLETE ME and I have to fill them in - there's more to this assignment but this seems easiest part but even here I don't have confidence that I've done it right.

What should I know to make a small OS like MINIX and where can I learn it? I'm pretty good with C and I know a little assembly, but I have no idea where to start. I also don't know a lot about OS internals...

in init_node:
node* is the datatype (pointer to node), n is the variable, not *n
if you use the * you will get the value at address n
with that malloc, you want to store the new node at address n
it should be n = (node *) malloc(sizeof(struct node)); (the typecast is optional, but you should know that it returns an address, not a value)
I don't know the difference between node and node_int in your code

n->data is the same as (*n).data just don't use the *

n->data = o I probably what you meant
last line is correct if you remove the *

the reason why I did that because without the (*n) instead of n
I get the error expression must have pointer-to-struct-or-union type
n = (node)malloc(sizeof(struct node_int)); compiles fine but not n->next = 0

ohh yeah I get it

malloc returns a void* though, if you cast a void* to node you will get nonsense

C/C++ and C# are two completely different things. Just like Java and JavaScript are two different things.

Knowing both is highly recommended. Whatever "knowing C++" means. Because C++ is massive kitchen-sink of features, meaning no person can know C++ in it's entirety.

so
void init_node(node *n, void *o)
{
n = (node *)malloc(sizeof(struct node_int));
(*n)->data = 0;
(*n)->next = NULL;
}

this compiles

is there a difference between node and node_int?

in init_node, what are n and o?
is n the pointer to where you should store the node and o it's value?
that would make sense since you aren't returning anything

malloc is needed when you need to find an address to store the variable, but that's n right?

there's no point in casting malloc in C

Is it worth it?
humblebundle.com/books/joy-of-coding-book-bundle

paying for ebooks?

Sure, why not? There is also a part going to charity

hmm... Eloquent JS, LYAH, and Write Great Code are good, most books are beginner tier

>Write Great Code
top tier advice

What's the best book for getting a solid foundation in C if you have experience in C++ already but want to understand more of what's happening closer to the machine?

>C
>closer to the machine

You fell for the meme

Wrong terminology? I feel like learning C would give me a better lower level understanding. Is this wrong?

get an actual com arch textbook

>Is this wrong?
Yes, it won't.
If you want lower level, try ASM

>there ain't no jobs!
>muh thanks Obama!
There is a labor shortage, it's just not among stuff anyone wants to do. We need electricians, truck drivers, and other shitty jobs that you only need trade school for. When 50% of Americans get a college education in some bs field of course they won't be able to find jobs. Fuck!

ok, how the fuck do I suppress this stupid warning bullshit in Atom?

either add a compiler option to supress warnings or edit the settings so that warnings are invisible

By using that method.

>already learned C
You're never finished learning C...

Too many fucktards flooding into CS nowadays...many of them would be better suited to driving a forklift or plumbing or tech support or some shit

#![allow(dead_code)] on top of the file

ikr. Half the people I know at college 1, don't even understand what they're doing but just buy their way through to a degree, or 2, can barely afford it and complain about having college debt into their thirties instead of going to a community college in the first place. (For undergrad at least)

who /kodingwithkarlie/ here?

In C: Is there a better way to get a pointer to the second memory position of a pointer than

P* second = &aLotOfPs[1];

?

Seems like an unnecessary indirection to me...

Where do I start in learning how to program?

P* second = aLotOfPs + 1;

more like /kodingwithautism/

Thoughts on my Euler 35 solution?

projecteuler.net/problem=35


from eulerlib import prime_numbers as pm

pl = pm.primes(1000000)

def primes_under_million(prime_list):
um_primes = [False]*1000000
for i in [v for i,v in enumerate(pl)]:
um_primes[i] = True
return um_primes

def circlePrimes(prime_list):
result = sum(1 for i in prime_list if isCircular(i))
return result

def isCircular(n):
r = str(n)
return all(primes[int(r[j:] + r[:j])] for j in range(len(r)))

primes = primes_under_million(pl)
print (circlePrimes(pl))

Curious, has anyone been able to confirm whether or not her retard moment involving the fast inverse square root function was actually a thing (that she later deleted) or if the entire image was shopped?

Probably an hoax made by misogynists.

Probably faster than mine

SICP, unless you really mean coding