/dpt/ Daily Programming thread

This is /dpt/, the best subreddit of Sup Forums

Pair programming edition.

In this thread:
r/programming
r/compsci
r/ReverseEngineering
r/softwaredevelopment

/!\ ** Read this before asking questions ** /!\

mattgemmell.com/what-have-you-tried/
catb.org/~esr/faqs/smart-questions.html


What are you working on?

Other urls found in this thread:

retrotech.eu/netrunner/
blog.plan99.net/modern-garbage-collection-911ef4f8bd8e
qr.ae/drvVS
qr.ae/drvm8
yager.io/programming/go.html
nomad.so/2015/03/why-gos-design-is-a-disservice-to-intelligent-programmers/
java.dzone.com/news/i-don’t-much-get-go
dtrace.org/blogs/wesolows/2014/12/29/golang-is-trash/
lessonsoffailure.com/software/google-go-not-getting-us-anywhere/
lessonsoffailure.com/software/googles-go-not-getting-us-anywhere-part-2/
lessonsoffailure.com/software/google-go-good-for-nothing/
gist.github.com/kachayev/21e7fe149bc5ae0bd878
learnxinyminutes.com/
aliexpress.com/item/Tada68-Mechanical-keyboard-gateron-swtich-65-layout-Dye-sub-keycaps-cherry-profils-enjoypbt-keycap-cherry-profile/32807055607.html
twitter.com/NSFWRedditVideo

First Fortran C.

Second for scheme

/dpt/-chan, daisuki~

>not racket

thank you for using an anime image

>What are you working on?
Exploring the darkest corners of Racket

i don't see any instruction decoding in your code. do you consider exit as an instruction?

Pretend I'm an idiot and explain to me the difference between an expression and a statement in a way that I can understand.

what would be the best way to point at files in a directory in python so i can manipulate them?
a dictionary?

It's a statement if you put a semicolon on the end.

Racket is a Scheme

Use lists, all other containers are bloat

idiomatic racket code doesn't look like your usual scheme code.

an expression is evaluated to return a result.
a statement is executed to produce an effect.

All valid Scheme programs are valid Racket programs.

>i don't see any instruction decoding in your code. do you consider exit as an instruction?
Yeah basically, the whole point is that the trivial bytecode VM has only two instructions, 0xff which means halt (represented by CRT exit function) and anything else is a nop. Obviously a real VM with stuff like variable-size instructions, separating the instruction word into bitfields for opcode, addressing mode, operands and so on would be much more complicated.

An expression has a value, a statement not necessarily. And some expressions can't be used as a statement, but only part of one. printf() is a statement (because it means something on its own) and also an expression because it does return a value. goto hell is a statement, but not an expression, because it has no value. 2+2 is an expression because it has value, but not a statement in a meaningful sense since it doesn't actually do anything unless assigned to something as part of a larger statement.

wrong. racket lists are immutable.

Use binary, all other languages are bloat.

Use the nourishing song of the universe. All other languages are bloat.

Go is a really comfy language.

It's like C and Java had a baby but C was sexually assaulted by Javascript around that time period so it's not known who the father really is but the baby is still cool.

We are making a web browser! WEBSITE: retrotech.eu/netrunner/
IRC: #Sup Forumsnetrunner channel on Rizon
Come and join

Sounds like an awful language when you put it that way

Kindly show a valid Scheme program (R5RS) that is not a valid Racket program.

Daily reminder that testing is for code monkeys.
Axiom array : Type -> Type.
Check array.

Axiom length : forall T : Type, array T -> nat.
Check length.
Arguments length {_} _.

Axiom nth :
forall (T : Type) (i : nat) (a : array T), i < length a -> T.
Check nth.
Arguments nth {_ _} _ _.

Axiom mk_array :
forall (T : Type) (n : nat), (forall i : nat, i < n -> T) -> array T.
Check mk_array.
Arguments mk_array {_ _} _.

Axiom mk_array_length :
forall (T : Type) (n : nat) (f : forall i : nat, i < n -> T),
length (mk_array f) = n.
Check mk_array_length.
Arguments mk_array_length {_ _} _.

Lemma trivial1 :
forall (T : Type) (n : nat) (i : nat)
(f : forall i : nat, i < n -> T),
i < n -> i < length (mk_array f).
(intros T n i f H1).
(assert (length (mk_array f) = n)).
(apply mk_array_length).
(rewrite H).
(apply H1).
Qed.
Check trivial1.
Arguments trivial1 {_ _ _} _ _.

Axiom mk_array_nth :
forall (T : Type) (n : nat) (f : forall i : nat, i < n -> T)
(i : nat) (Hi : i < n),
let Hmk : i < length (mk_array f) := trivial1 f Hi in
nth (mk_array f) Hmk = f i Hi.
Check mk_array_nth.

Definition duplicate : forall (T : Type), array T -> array T :=
fun T a => mk_array (fun i Hin => nth a Hin).
Check duplicate.
Arguments duplicate {_} _.

Theorem dup_has_same_length :
forall (T : Type) (a : array T), length (duplicate a) = length a.
(intros T a).
(unfold duplicate).
(apply mk_array_length).
Qed.
Check dup_has_same_length.
Arguments dup_has_same_length {_} _.

Lemma trivial2 :
forall (T : Type) (i : nat) (a : array T),
i < length a -> i < length (duplicate a).
(intros T i a H1).
(apply eq_ind with (x := length a)).
auto.
symmetry.
(apply dup_has_same_length).
Qed.
Check trivial2.
Arguments trivial2 {_ _} _ _.

Theorem dup_is_same :
forall (T : Type) (a : array T) (i : nat) (Ha : i < length a),
let Hda : i < length (duplicate a) := trivial2 a Ha in
nth a Ha = nth (duplicate a) Hda.

>goto hell is a statement, but not an expression, because it has no value

hell is a label, it has a value equal to some memory address or offset

>Not written in Go

>reading comprehension

eww

But i dont need theorems with idris

Why would you not like a language with C performance but without the autism so you can actually enjoy using it

while Q is not empty:
u ← vertex in Q with min dist[u] // Node with the least distance will be selected first
remove u from Q
In this pseudocode , how would you find the min_dist[u] without a costly min() or sort() function?

(define a (1 . 5))
(set-car! a 5)
(display a)


that's the least efficient technique for instruction decoding.

from least to most efficient

1 conditional jump (your)
2 jump table
3 pre-decoding

I'm a stupid namefag and I should kill myself

>theorems
Those are just programs.

>golang

blog.plan99.net/modern-garbage-collection-911ef4f8bd8e
qr.ae/drvVS
qr.ae/drvm8
yager.io/programming/go.html
nomad.so/2015/03/why-gos-design-is-a-disservice-to-intelligent-programmers/
java.dzone.com/news/i-don’t-much-get-go
dtrace.org/blogs/wesolows/2014/12/29/golang-is-trash/
lessonsoffailure.com/software/google-go-not-getting-us-anywhere/
lessonsoffailure.com/software/googles-go-not-getting-us-anywhere-part-2/
lessonsoffailure.com/software/google-go-good-for-nothing/
gist.github.com/kachayev/21e7fe149bc5ae0bd878

What language are you talking about? Surely not Go.

How can I make money off of programming without ever having to leave my neetcave to go to college with others or attend job interviews and eventually become employed and work alongside others?
How do I make money with programming by myself independently? Options like crypto trade bots for example and other jewery

This post barely makes any sense.

Oh yeah those are a bunch of trustworthy sites we all recognise by name alone

hell is an expression, but goto hell is not. Goto is in the very abstract sense, a "function" that takes an expression (label) as input, but has no return value; like a call to a void function, it isn't an expression, because it doesn't give you a result you can do anything with.

>go to college
Is it possible to get a non-webdev job without a degree nowadays, when CD grads are a diamond dozen?

I thought it was only a meme

>Linus indents 8 spaces
>Stallman indents 2 spaces

Is Linus compensating for something?

I opened one up and it had a detailed example of Go's deficiencies. This served to reassure my dislike of Go.

linus doesn't know how to change the defaults

Good point, however in a real bytecode VM the instruction decoding wouldn't be the only overhead; if the VM instructions are more complex than machine instructions (which they often are) then they'd have to be implemented by functions each of which amounts to at least several instructions by itself.

when will python get the break all statement?

8 spaces is standard.

best tutorial/online course to learn Python (and programming in general)?

The only sane indentation is 4 spaces.

learnxinyminutes.com/

Comparing it to python and saying "omg it doesn't support so therefore it sucks" ignoring the fact that it's supposed to be a simple C like language

A what?

#include
struct S {
// three-bit unsigned field,
// allowed values are 0...7
unsigned int b : 3;
};
int main()
{
S s = {7};
++s.b; // unsigned overflow (guaranteed wrap-around)
std::cout

So are Windows and JavaScript, that doesn't mean they're good.

>Linus indents 8 spaces
Don't forget to also komment your kode!

>a "function" that takes an expression (label) as input, but has no return value; like a call to a void function,

functions are a mathematical concept that has not counterpart in programming.
a function takes an argument, is declarative, and does return a value.

seriously, you shall stop referring to c for explaining computer science or mathematical concepts.

expressions based computation: lambda calculus
statement based computation: turing machine

>Windows
>standard
lol

No, it compared to Rust and Haskell and the inability to write generic functions in Go. And then it goes on, literally a page of thorough examinations of the utter spew Go is.

So now show the Rust equivalent.

Research shows that 3 spaces is ideal, but programmers have a natural aversion to non-powers-of-two

It's a unix standard, so it is good.

>functions are a mathematical concept that has not counterpart in programming.
I meant "function" in thte C sense - i.e. a construct that takes 0 or more arguments, and may return values or have side effects. Mathematical functions are expressions and not statements, since they have no side-effects there is no point in "calling" one without assigning its value to something.

What is ``unix"?

is "virtual" in c++ the same thing as "abstract" in java?

What languages should I add or remove from this list. I'd like to cut it down/grey out some until later. I'm for sure learning c/c++ right now using "Programming Principles and Practices Using C++ 2nd Edition" by Bjarne Stroustrup. I'm also using other resources and learning mathematics as I go along but I'd like to learn 2-3 other languages along with C++ that I can use as a good foil to gain a greater grasp of the concepts that I'm learning with C++. I've used C# for about two years and want to gain a greater grasp of the fundamentals of programming/mathematics/computation. I'm not trying to get a job programming right now, I don't really know if I'd want one in the future, but I'm just genuinely interested in communicating with computers and making them do shit. I've also thought about getting some lego robotics stuff to learn some embedded/robotics programming but I've reserved that for later on in life when I have more space and free time. Sorry if this is a dumb question, or a vague question with lots of opinionated answers. Pic related is what I've set up from asking this question phrased differently before and from looking at the Sup Forums wiki as well as looking at the programming book repository as well as just looking at wikipedia, youtube videos etc.

remove none
add lua

Does anyone have any good references to sql server query plans and how to compare them?

Remove Python
Remove Haskell
Remove Java
Remove Scheme
Remove Idris
Remove Javascript

Add OCaml
Add Haxe

Final List: C/C++/Haxe/OCaml/Bash and love :)

In my programming class I'm supposed to implement a linear sort and binary search, everything has gone fine except the linear sort part I've been stuck on for days.

On an array of any size greater than 500, the last 5-10% of the elements after the linear sort algorithm are all identical, and sometimes the command line in the IDE scrolls irregularly or freezes and I have to clear the buffer or kill the program. Is my computer just too old and too weak to process an inefficient algorithm on progressively larger lists without hitting some kind of limit in the IDE?

Not quite.
virtual means the method can be overridden. This happens by default for all Java instance methods and doesn't need to be marked, but you need to explicitly ask for it in C++.
class Base
{
virtual void sayHello() { std::cout

Check out my fizzbuzz
from itertools import count, cycle, islice
from operator import add

def fizzbuzz():
f = ["", "", "Fizz"]
b = ["", "", "", "", "Buzz"]
it = zip(map(add, cycle(f), cycle(b)), count(1))
yield from (s or str(n) for s, n in it)

print(*islice(fizzbuzz(), 100), sep='\n')

so the methods are virtual but you don't have "virtual class"?

#include

#include
#include
#include

static double pop (std::stack &s) {
if (s.size () == 0) {
throw "empty stack";
}
double x (s.top ());
s.pop ();
return x;
}

static double add (double x, double y) {
return x + y;
}

static double mult (double x, double y) {
return x * y;
}

static double sub (double x, double y) {
return x - y;
}

static double div (double x, double y) {
return x / y;
}

static double (*getop (const std::string &word)) (double, double) {
if (word == "+") {
return add;
} else if (word == "*") {
return mult;
} else if (word == "-") {
return sub;
} else if (word == "/") {
return div;
} else if (word == "**") {
return pow;
} else {
return NULL;
}
}

void parseword (std::stack &s, const std::string &word) {
double (*op) (double, double) (getop (word));
if (op != NULL) {
double y (pop (s));
double x (pop (s));
s.push (op (x, y));
return;
}
std::istringstream iss (word);
double x;
iss >> x;
if (iss.fail () || !iss.eof ()) {
std::string message ("unknown word: ");
message += word;
throw message;
}
s.push (x);
}

void mainloop (int argc, const char *const *argv) {
std::stack s;
for (size_t i (1); i < (size_t) argc; i++) {
parseword (s, argv[i]);
}
double x (pop (s));
std::cout

Haha wow really user? You're lucky then. I've had to deal with Indians a lot. They're smelly (no meme, it's the first you notice, poor hygiene I suspect), intentionally deceptive, have very low work ethic and terrible at their job when they actually do it.

Just last week I had to re-write a piece of code to program a SOM via a serial port because pajeet sent 1 byte at a time over the line. Making the process take 18hours. I should have checked his code before hand. After I batched the write()s it took 30s. And I found a case where he didn't parse the hex file right. Luckily it wasn't applicable for the hex file I had to use.

They're a terrible time sink and I keep telling the boss about these instances. He just thinks they need code review and he leaves it for them to review themselves. Doesn't work obviously. They don't even use subversion as instructed and breaking version numbers is the norm.

Avoid Indians at all cost.

I'd like to be able to make a website/server and actually use it. I want to be able to make multiplayer games and have them function properly even if its just for meme hobbyist projects. I'd like to be able to understand networking for both my own home by being able to network and securely set up devices as well as be able to host and build web/server applications that I can actually use for personal usage. I just added your suggestions and I'm going to try and read through and filter them later using the information gathered. Thank you for your responses. I assumed Javascript/HTML5/CSS was just the way web pages were built? I also think SQL is the primary interface to access databases? I don't know I've never really built a webpage or a database before.

I assume I'm going to have to tackle all of those things separately as different learning activities/projects.

No.
Though, the second example *is* an abstract class.

>haxe
Isn't that some scripting language for flash or something?

> I assumed Javascript/HTML5/CSS was just the way web pages were built?

Haxe can transpile to JS, so no problem here.
You can also use the Wt Toolkit (C++), so no problem here.
HTML/CSS is necessary, but i'm talking about programming languages anyway.

> I also think SQL is the primary interface to access databases?

Yes.

Would you recommend sololearn To learn coding

ActionScript 3
C++
C#
Flash
HashLink
Java
JavaScript
Lua
NekoVM
PHP
Python 3

>syntax doesn't matter
APL isn't as ugly as sepples but I think it's fair to say you would not program in APL because of the syntax.

It's not pretty. But I'd do apl over c++.
At least you can look at code and actually see what it's doing without knowing every other piece of code like in C++.

Does this actually work? Does it have mod2^3 behavior? I didn't know C could do that. C is so high level it's crazy.

Is there any language really worth looking at when I know a few (C, C++, C#, Java, Python, JS) and am productive in them?

Yes, OCaml.

Can you please elaborate why is it worthwhile?

best source to learn Python as a first language and to learn programming in general?
please help, desu

I'm not a good programmer. In fact, this is one of my first "projects" ever. What's a fun tiling algorithm for tiling windows? I'm trying to create a tiling script of KDE. At the moment I'm just splitting Windows but it's troublesome if I close the biggest window and leave the smaller ones.

Also, my carpal tunnel is getting real fucking bad, what do?

Fast and safe.

the rust """"""""equivalent"""""""" would be exceedingly verbose

And I forgot, one of the easiest language to use.

>Also, my carpal tunnel is getting real fucking bad, what do?
get a real keyboard and learn to touch type properly

aliexpress.com/item/Tada68-Mechanical-keyboard-gateron-swtich-65-layout-Dye-sub-keycaps-cherry-profils-enjoypbt-keycap-cherry-profile/32807055607.html

Where can I learn more about C tooling? Stuff like advanced compiler options, debugging, unit testing, makefiles, etc... C books don't really cover that king of thing.

I am trying to call a function from another file in C++, but it doesn't work.
I just get the error: 'aaa' was not declared in this scope.
Why doesn't this work? How do I bring the function into scope?
Here are the files.

main file:
#include

main()
{
aaa();
}


functions.cpp:
#include
#include

void aaa() {
std::cout

You're using which indicates an installed library include, rather than """ which indicates an included in your project directory.

I changed it to "functions.h" in both files, but the error still persists.

do something with your makefile

problem is, I don't know what to do with it.
anyway here it is. I'd be glad if someone could help.
CC := g++
SRCDIR := src
BUILDDIR := build
TARGETDIR := bin

EXECUTABLE := main
TARGET := $(TARGETDIR)/$(EXECUTABLE)

# create a list of code-files
SRCEXT := cpp
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))

CFLAGS := -c
INC := -I include

$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@echo "Compiling $

is functions.h added to your project?

I think so.
At least the compiler doesn't complain.

That's a little too much for compiling two files.

$ g++ -I. -o prog main.cpp functions.cpp

If you understand that command, you should be able to simplify the makefile and also understand why it didn't work in the first place (tip: #include vs. #include "header_which_is_not").

a-anyone?

thanks for the help.
The mistake was trivial. I changed the function name in the wrong file...

with $ g++ -I ../include -o prog main.cpp functions.cpp everything compiles now.
I just need to figure out why the fuck the make file in doesn't want to link.

Let's say I have an Erlang/Elixir application. I want to make a nice GUI frontend so the user can access and control this headless Erlang/Elixir application. That should be possible, right? Can anyone point me in the direction for finding info on how to get two separate applications running on the same PC to communicate with one another?