/dpt/ daily programming thread

Old thread:

Red scare edition.

What are you working on Sup Forums?

Other urls found in this thread:

youtube.com/watch?v=PNRju6_yn3o
twitter.com/AnonBabble

Rust >>>>>>>>>> C/C++
desu

What are your most used terminal commands, Sup Forums?
#!/usr/bin/env bash

TOTAL=$(cat ~/.bash_history | wc -l)
LIST=$(cat ~/.bash_history | sed 's/sudo //g' | cut -d ' ' -f1 | sort | uniq -c | sort -nr | head -20)
echo "Most common out of $TOTAL commands:"
n=0
for line in $LIST
do
if (( (n % 2) == 0 ))
then
PCT=$(echo "scale=3; ($line / $TOTAL) * 100" | bc | sed 's/00$//g')
echo -ne "${PCT}%\t${line}x"
else
echo -e "\t$line"
fi
n=$((n + 1))
done

ls and rdmd file.d -f

kanna is shit

nano
make
./graphics
ls
man
clear
sshfs

kanna a cute

ls
cowsay
ssh

can't polish a turd

why is kanna bad?
obviously the titty dragons are best girls, but kanna is in no way bad.

I am genuinely scared of Red.

On one hand, it is such a massive gain in productivity for anything related to GUI's that you'd be crazy to not use it, especially once it matures. It takes something that is genuinely difficult in most other languages and makes it ridiculously easy. It has better metaprogramming capabilities than your average lisp dialect, and leverages that to give you crazy good parsing and GUI DSL's.

On the other hand, it's a weakly typed (when not compiled) language with prototypical OOP and a very high reliance on advanced metaprogramming techniques. It can suffer from javascript-like "undefined is not a function"-ish error messages. I can imagine that debugging that shit could turn into an absolute hell. Adding in the fact that it's easy enough for excel sheet normies and pajeets to use and be very productive with, I don't want to imagine the mountain of incomprehensible code that they might produce.

He's probably one of those elitists who read the manga first and uses the word "EOP" to deride secondaries who started with the anime.
Kanna isn't quite as THICC in the original manga, in fact there was another character that was left out of the anime who was THICC and well endowed but she looked too much like kanna and her story arc revolved around giving kobayashi-san a magic penis.

I want to see it become popular, it's going to be insane mad max world but with Indians instead of Australians litteraly accelerationism but for programming languages. Red is an ideological atom bomb

>why is kanna bad
if you don't know then you are also bad

She's no renge, which is why she isn't best girl. But she has personality, unless you're still butt-blasted about the irrelevant dub that no one but crunchyroll mouth-breathers watch.

what cpp build system should I use instead of hand rolled and simple makefiles
its getting annoying for longer projects with 40 files

cmake seems like absolute cancer

you won't find anything better than gnu make; what problems do you have with more than 40 files? it works the same regardless of the number of files

If the compilation process is identical across all 40 files, it's trivial to wildcard all your source files within a makefile so you no longer have to keep adding source files individually.
I hope you're compiling to object files, user.

He's just fucking with you. People tend to hate anything from Kyoani because it's the only studio that still puts some effort into the animation itself while most studios just produce halfassed animated garbage like Konosuba and Little Witch Academia.

>People tend to hate anything from Kyoani
Well if he hated it as a whole i would think he would have said that and not just a specific character. But you're probably right

its annoying to go and update all the manual requires and `pkg-config` things for each .o file

yes im using object files, but I don't know if its actually only recompiling the necessary ones. Pretty sure its just compiling everything all the time

we always hear about xyz new language that i am a bit jaded to be honest.

I'm honestly more scared of the excel sheet normies than of the Indians. Companies don't have to even hire Indians if they can just have their normie employee do it, kind of like how excel sheets are misused in many companies today.

Of course, if they hire Indian tech support to "fix" their shit...

makefiles can automatically rebuild dependencies if it detects that the .o file is older than it's constituent source file, this way you only have to rebuild the translation units that were edited since the last compile.
A massive time savings if your project is more than 10 files.

>emacs
>make
>./test
>ls
>ls | grep

I can understand the feeling.

This is a fully functional graphical email client in REBOL, the language that Red is an open-source version of:

view layout[
h1 "Send:"
btn "Server settings" [
system/schemes/default/host: request-text/title "SMTP Server:"
system/schemes/pop/host: request-text/title "POP Server:"
system/schemes/default/user: request-text/title "SMTP User Name:"
system/schemes/default/pass: request-text/title "SMTP Password:"
system/user/email: to-email request-text/title "Your Email Addr:"
]
a: field "[email protected]"
s: field "Subject"
b: area
btn "Send"[
send/subject to-email a/text b/text s/text
alert "Sent"
]
h1 "Read:"
f: field "pop://user:[email protected]"
btn "Read" [editor read to-url f/text]
]

C. A. R. Hoare in An Axiomatic Basis for Computer Programming wrote: "[...] The axioms A1 to A9 are, of course, true to the traditional infinite set of integers in mathematics. However, they are also true of the finite sets of 'integers' which are manipulated by computers provided that they are confined to nonnegative numbers".

What did he mean by that? What about two's complement? Why only nonnegative numbers?

Makefiles.

What are the axioms?

How would you do this in Red!

A6: given that y

User registration system with PHP/MySQL/AngularJS

Yeah, no shit. If they weren't true it wouldn't be a field.

Is Go designed for brainlets?
Is Go good?
Why doesn't Go have generics?
Will Go 2.0 fix everything wrong with the language?
How can Go be bad if Ken Thompson worked on it?

yes
no
see question 1
probably not
because nu-pike is a lost cause.

Those all seem valid with two's complement at a glance.

It's rumored that Ken hates the language and that most of his ideas were rejected for "not being inclusive enough."

Please fucking help /dpt/. I'm fucking desperate because my parents railroaded me into a compsci degree, my textbook is a piece of absolute shit that doesn't even teach about programming in C, my professor talks about 20% of the actual material in lecture, and my TA's are worthless fucks who don't even show up to office hours, so I've been trying to survive on literally just google and stackexchange teaching myself everything. I already know uni is a joke so you can save yourself time telling me that it is.

I need help understanding how structs and unions work with memory space. I get that unions have a quirky behavior where basically everything uses the same memory address/bits and can get overridden easily.

I don't actually understand how structs allocate memory for their elements. They allocate separate bytes in memory for each thing? So does that mean that they use a bunch of different memory addresses for each thing, or do the things of the struct all use one memory address that they each get specific bytes of? Can I fuck with them and make the elements override each others' bits like I can with a union?

And then what happens in memory if I declare a struct that also has a previously-declared union inside it? How does the union's content get mixed in with the struct's shit in memory? Does the union's content get another separate memory address for its shit or does it have to share with the rest of the stuff in the struct?

please respond before I kms

rip in pieces user

It's never going to get any easier, C is basically the simplest programming language still in contemporary use.
If you don't understand simple things like byte offsets, I don't know what else to tell you.

>uni is a joke
only unemployed neets say this
t. unemployed neet

It gets easier with time and you don't need to understand any of that shit anyways to be a code monkey

could you share some good title resource on computer architecture and algorithms?

if you want to become a programmer, it is.

>i need to learn calculus-level maths to write software

You and I both know you're going for that little slip of paper and continuing the college racket because you can't get your foot in the door without one.

a struct is a description, a way of describing how to interpret existing bytes in memory
if you do
struct some_struct instance;

the values come from the stack
if you malloc() it comes from the heap
>So does that mean that they use a bunch of different memory addresses for each thing, or do the things of the struct all use one memory address that they each get specific bytes of?
no, there's a base address which you get if you malloc() or use & on a struct allocated on the stack
every field has an offset that you add to the base address to access it
>Can I fuck with them and make the elements override each others' bits like I can with a union?
nope, they're right after each other by definition, never overlapping
>And then what happens in memory if I declare a struct that also has a previously-declared union inside it?
struct something {
union {
int a;
char b;
} some_union;
};

creates a field with sizeof(type requiring the most memory), in this case int
if you access the field "b" it's only going to access the highest byte of the int
it's an way of saying that this block of memory can be interpreted in multiple different ways, in this case as a char or an int

Please post one of your Makefiles, I'm sure it can be improved upon.

scons

dumb frogposter

I haven't used Red, but Rebol was nice.

>implying a decent github isn't a viable sub in this day and age
especially if you apply to some new startup. But why work for others when anyone today can start their own potential million dollar company with just a year or two of wageslave bux

startups are a meme
silicon valley is a laughingstock to the rest of the country
the dream of some guys building a software shop out of their garage and becoming a multi-billion dollar multinational that serves the whole planet is a thing of the past

>startups are only in commiefornia
>programming is more relevant and easier than ever but somehow the possibility of becoming rich off it is a dead concept
>despite the big five throwing out hundreds of millions a year to buy out niche companies

are you willingly being this much of a baka?

fucking thank you god, all I needed was someone to tell me the basics of exactly what a struct is, none of my lectures or recitations literally ever went over this, they talked about other shit and then just randomly gave us a homework problem with structs and unions with the attitude of "oh hopefully you can learn this on your own xD"

Go look at some "startups" and how well they're doing.
They all get bought out by larger companies or simply die because their VC funding ran out.

Quick question, how do I prevent javascript functions from converting integer values to strings without doing dumb hacks like appending | 0 to all function arguments and returning toInt() in every function that deals with numbers?

use typescript

A struct is an aggregated type.
In a struct, each of the fields lies in a different, but contiguous, address.
Space is allocated for each, according to the type's size.

An union is an amalgamated type.
In an union, all fields lie in the same address, and overlap each other.
Space is allocated for the widest field, and others will overlap it.

Both only care about the size of the contained types, not their nature. They won't treat any type differently.
What is it that you do not understand?

If i need to make a wrapper of C library on C++, then which method is better?

making C style global variable to store the variable, and using namespace to reduce the scope of the function that call the original C-lib's function,

or

making a class or struct with the variable in private block, with method as the C-lib's function call.

I know with the struct or class method, it's safer since the function to close / uninitialized could be placed on object's destructors, but if I accidentally make multiple instance of the class, then it will be double-initialized.

Which is Sup Forums's preferred way to do it?

Building a VRRPv3 daemon

reminder that arrays are pointers

Are you asking to shove C++ namespace hell into a clean and neat C library?
I guess you could fake it with the C preprocessor string paste operator and a namespace(your_lib) macro that expanded to the original function name.

Is it for you or for others to use?

Only as a type, not as a declaration.

in C this is just

C is the only language that matters though.

The wrapper's function only to reduce the amount of code writing for future code made by myself.
for example is a single function that initialize whole display, window, and waiting for XEvent on Xlib.

>In a struct, each of the fields lies in a different, but contiguous, address.

They're all next to each other's addresses? So you mean that if one field was stored at some address location α that the next field would be stored at the address location α+1, and the next α+2? In a byte-addressable machine that means that every address is one byte in size. Do you mean to say that the fields lie in a series of addresses (the number of distinct addresses depending on the size of the type, like an int getting four bytes or long long getting eight) that occur one after the other?

>I don't actually understand how structs allocate memory for their elements. They allocate separate bytes in memory for each thing?
Yes, each thing gets its own bytes, but they're all sequential. They're in the same block of allocated memory, which is at least wide enough to fit all of them at once with no overlap.
>So does that mean that they use a bunch of different memory addresses for each thing, or do the things of the struct all use one memory address that they each get specific bytes of?
The latter. It's all one block, and separate fields are separate bytes or words of that block. However, since each such byte or word is at a different position within the block, the fields still have different addresses. A struct is basically like a fixed length array that can be passed by value, has elements of different types, and has compile-time names for all its elements so you don't have to refer to them by number. That's pretty much all it is.
>Can I fuck with them and make the elements override each others' bits like I can with a union?
If you want to do this, the way to do it would be to have a union in your struct.
>And then what happens in memory if I declare a struct that also has a previously-declared union inside it? How does the union's content get mixed in with the struct's shit in memory? Does the union's content get another separate memory address for its shit or does it have to share with the rest of the stuff in the struct?
A part of the block allocated for the struct, as wide as the union's largest member and not overlapping any other members of the struct, is used for the union. Things in the union share that space and other things in the struct stay out of it.

So if you had a struct like this:
struct example {
int a, b;
union {
int c;
char d;
};
int e;
};

It would look like this:
[a gets this space | b gets this space | either c or d gets this space at any given time | e gets this space]

>unifags trying to show how smart they are by spoonfeeding a frogposter
Just stop, there's no hope for her

yes, most of the times.

"most of the times", because usually fields need to be aligned in memory. so, say a struct like this.
struct {
char a;
uint32_t b;
uint64_t c;
}

say X is the base address of this struct, then a would be located at X and span 1 byte, but because uint32_t needs to be aligned with an address "multiple" of 4 bytes, it would be located at X+4 and span 4 bytes, and, uint64_t needs to be aligned with a "multiple" of 8 bytes, it would be located at X+8.

essentially 3 bytes are "wasted" in this struct, in between a and b.

>literally being so selfish you can't comprehend the concept of trying to help someone understand something purely out of desire for them to understand it
Just stop, there's no hope for you

That's gay dude, are you gay?

>tfw you've lost count of the amount of bytes wasted in c++ classes.

Yes, but wanting to help someone doesn't have an associated sexual orientation, or generally even a sexual component of any kind.

k homo

please elaborate

Not him. But could you clarify the advantage of using union than just a simple casting?

also, since in C++ struct and class basically a same thing, is the struct in C++ still locate memory like this? If so, how to they implement the struct method?

None, because I use this script I wrote to delete duplicates on login:
#!/bin/bash
set -e -o pipefail
# Delete duplicates oldest-first from .bash_history while preserving order
# and removing trailing whitespace.
TMPFILE=$(mktemp)
sed 's/\s*$//' "$HOME/.bash_history" | tac | awk '!x[$0]++' | tac >> "$TMPFILE"
mv -f "$TMPFILE" "$HOME/.bash_history"
I also utilize HISTIGNORE in my bashrc for general asinine commands like ls, cd, etc.

The main purpose of a union is to ensure alignment compatible with any of its fields.

Under what conditions will the same code compile differently or should the question be phrased the other way around.

I want compile code on two different machines and have the compilation result in the same thing. Language is C if it helps.

>Graduate next semester
>Have basically learned nothing over what I learned through K&R and fucking around with C#
>Advisor laughed in my face when I mentioned some schools I wanted to attend a graduate program at
So I should just drop out and go be a hobo on the west coast right

>Advisor laughed in my face when I mentioned some schools I wanted to attend a graduate program at

normies btfo

No
Reasonably
Doesn't need them
Not if you have the impression it's already a broken language
It's not, Sup Forums just hates anything that isn't C. See: Java, JavaScript and any variants, C#, Rust, Haskell, Lisp, Python, Ruby, etc.

I don't even know why, I have a 3.9 GPA and placed in the 89th percentile on the GRE

Undergraduate level CS is code monkey school. Graduate level CS might as well be a completely different program. You need a very strong mathematics background and it has little to do with excelling in your standard CS class.

I'll ask here because /sqt/ is not helpful.
Where can I read about modern computer architecture? I know abstract concepts from my classes but my real life knowledge stopped somewhere around pentium III era, and I'd like to get up to date. It's not like I don't know anything past year 2000, I do, but it isn't consistent and in chronological order.

Intel dev manuals

I've taken more mathematics classes than I have CS classes.

Maybe he was laughing at a shitty choice in school and not the notion of you going to graduate school entirely?

Nope, I said my top pick was Uni of Washington and "probable shot" was Uni of Utah, both of which are very good schools.
Pretty sure he's just an asshole, but it still killed me inside.

Not him, but a method in C++ doesn't take any memory in a class.

class Foo{
int x=0;
void bar(){
++x;
}
};

To the compiler, this is almost the same as:

class Foo{
int x=0;
};

void bar(Foo *this){
++this.x;
}

But the difference is that a pointer to bar will take space on the virtual-table if there is one and of course that it's use is scoped to the class.

tfw too retarded for move semantics and rvalue reference

Yeah, my initial thought too, but I was hoping for something more... digested.
Not that they aren't any good, it's just that I think they might be to raw. I might not know what to filter out and what not.

It wouldn't even be mentioned in the vtable if it's not a virtual method.

So, "what is programming useful for, and what can you do with it?"
I have yet to find a really succinct answer to this question.

Obviously: writing programs, interfacing more directly with your computer.

I guess what I'm asking is "Why learn programming?" and for that matter, what is the entry point for computer and programming comprehension, and is there a linear sequence of skills/items to pursue?

Did you all just learn yourselves, or is it necessary to get a degree in computer science to be able to competently program?

Hacking seems like an interesting pursuit, but it seems like you need a degree of mastery in order for that to be a viable pursuit.

I'm asking for your thoughts, keep the masturbatory elitism to yourselves.
>Why is there such a connotation of elitism to the tech savvy?

>what is programming useful for
Anything you can make it do
>and what can you do with it?
Literally almost anything.

>Why learn programming?
Because you find it interesting. Not everybody needs to learn, that shit is a fucking meme. Just like not everybody needs to know how to build their own house from scratch, or rebuild their cars engine.

>Why is there such a connotation of elitism to the tech savvy?
Because absolute retards come through 24/7 having figured out a single thing and act like they're master programmers.

Don't feel bad
youtube.com/watch?v=PNRju6_yn3o
Honestly, as efficient as move semantics are, I'd rather kill myself than go through the debugging of it

>Mfw i just signed a contract for a major economic-solutions software company only rivaled by 2 other companies in their field, one of which is Microsoft
>Mfw this means i just started a career in JavaEE

Ya, it's so much easier to do in Rust. The borrow checker makes it all trivial, which also allows Rust to have pass by move instead of pass by value as the default for all functions.

just went till 2023, we'll get you then!