/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

en.wikipedia.org/wiki/Tracing_garbage_collection#Generational_GC_.28ephemeral_GC.29
reddit.com/r/legaladviceofftopic/comments/7c8x9s/is_this_legal_us/
en.wikipedia.org/wiki/Cycle_detection
youtube.com/watch?v=JPQWQfDhICA
pastebin.com/SmZYSbGq
stackoverflow.com/questions/39634504/is-there-anything-we-lose-with-monofoldable
twitter.com/SFWRedditVideos

Lisp is the most powerful programming language.

I'm writing a program where we have a market place for cars, where people can upload cars to sell.

Is this ER correct?

Explanation:
- a user can upload more than one car, but at least one
- the market place can have lots of cars, but at least one

Why are you drawing diagrams.

Making small steps towards writing demos. Learning lua and love2d.

OOP(TM)

Why was this man such a stick in the mud?

>what even is this readonly thing
there's often a need to get variables from a class, which forces you to either not give a fuck about access specifiers, which turns your class into spaghetti, or write getters, which shit up the class.

Thoughts?

>lying on your resume

JavaScript is a shit programming language

9fag tier post. have this (you)

lying is bad kid

fake

/dpt/ can't do the following:

* Average two integers
* Invert a binary tree
* Prove that 30 + 30 = 60

I'm currently learning Haskell but I'm confused on how you go about implementing data structures. As far as I know, everything in Haskell is immutable. So, if you want a data structure you're basically going to be making a full copy of it every time you want to modify it. How is this not horrifically slow and memory intensive? Seems like it would be impossible to implement anything useful considering how important simple data structures are.

>* Average two integers
impossible

>* Invert a binary tree
ambiguous

>* Prove that 30 + 30 = 60
it doesn't

muh laziness

>full copy
it's immutable, remember?
so you just keep a pointer - nobody's going to change it, after all, are they?

but you can do mutable stuff if you do it within ST or IO

int avg(int x, int y) {
return x/2 + y/2 + x&y&0x01;
}

inb4 lawsuit for patent infringement, fuck the MPAA

Hello, Sup Forums

Where should I start if I want to learn web development?
I don't have any previous programming knowing.

learn lisp

>distributed systems can only be written in erlang
Wew

>So, if you want a data structure you're basically going to be making a full copy of it every time you want to modify it. How is this not horrifically slow and memory intensive?
If you know something won't ever change, you never need to take "defensive" copies. Furthermore, immutability gives the compiler the ability to reason much more strongly about your data structures and many constructions can be optimized into mutations.

P H P

So, for a simple insert into a BST like this

data Tree a = Nil | Node a (Tree a) (Tree a) deriving (Show)

insert :: (Ord a) => Tree a -> a -> Tree a
insert Nil x = Node x Nil Nil
insert (Node v left right) x
| v == x = Node v left right
| v < x = Node v left (insert right x)
| v > x = Node v (insert left x) right


So, this code isn't actually making copies? The tree before and after the insertion are both completely distinct from each other. But, this doesn't require a full copy because the tree before the insertion is also immutable the tree after insertion can maintain pointers to reference its data without risk of it changin? Am I getting that right?

>Using switch-cases in this context

#include
char* doot = "onvctbyqmw";

unsigned long fib(){
static unsigned long num[2] = {1,0};
static unsigned char counter = 0;
counter %= 2;

return num[counter++] = num[0] + num[1];
}

int main(){
static unsigned long num = 0, magnitude, i;

while((num = fib()) < 100){
//printf("%d\n", num);

for(magnitude = 1; magnitude * 10

whenever you return a variable, you can imagine that as not being a deep copy but a pointer to it

if you actually do

(Node v left right) ... = Node v left right
At worst this copies a pointer to v, a pointer to left and a pointer to right, and at best:

n@(Node v left right) = n
would only keep 1 pointer

And for example in your other cases, the bits you don't change aren't copied, just a pointer to them is kept

>full copy
Nope. Take for example a function which inserts a node into a linked list. On average it copies only half the linked list. But it's not as slow as you'd think because functional language runtimes are designed for massive amounts of CONSing. For example, you might have an object pool of CONS cells which the program can quickly create from. So (good) functional languages aren't THAT much slower than C. You can ballbark it at 1-10x depending on language and code in question.

en.wikipedia.org/wiki/Tracing_garbage_collection#Generational_GC_.28ephemeral_GC.29

>Guys, inserting into a list totally doesn't copy N elements.
>It only copies O(N) elements.

Cool, thanks. Is there a good place to find simple, interesting programming challenges I could do with Haskell? It's difficult to really learn a language without something to work towards.

write an interpreter

which Reddit post does that come from?

I'm learning C as my first language. This program is pretty easy to understand save for one thing:

/* 16L07.c: Using an array of pointers */
#include
/* function declarations */
void StrPrint1(char **str1, int size);
void StrPrint2(char *str2);
/* main() function */
main()
{
char *str[4] = {"There's music in the sighing of a reed;",
"There's music in the gushing of a rill;",
"There's music in all things if men had ears;",
"There earth is but an echo the spheres.\n"
};
int i, size = 4;

StrPrint1(str, size);
for (i=0; i

reddit.com/r/legaladviceofftopic/comments/7c8x9s/is_this_legal_us/

If you want a challenge, make a text editor.

char ** str1 is a pointer to an array of strings. char * str2 is a string.

Strings in C are pointers to arrays of characters.

Reminder that Rust still doesn't have HKTs

This matters because?

I like to relate computer memory back to the numbered lockers you had back in high school. Each locker has an address (it's number) and something stored inside. Everything needs to be stored inside a locker, so everything can be identified by the locker number that it's stored in. A "pointer" is simply a locker that stores another locker's number. Of course, the locker storing the "pointer" must have it's own number, so you can have pointers to pointers to pointers, etc. C strings are simply arrays of chars. In this context you can think of an array as a pointer to the beginning of a set of concurrent lockers. The "char **" just means that you have an array of pointers that point to arrays of chars.

Thanks, this helps a lot

this matters for the same reason go having no generics matters

Is HtDP a meme, or should I stick with SICP?

also, how long will it take, if I program for 2-3 hours a day, to get decent enough to place in hackathons in my area? (LA, OC, SoCal in general)

Does C++ have anything in the standard library for reading structured text data? JSON, TOML, anything?

Basically no.

Doing well in hackathons involves knowing a lot of technology and being able to glue it together in a quasi-functional manner and using sleight of hand to disguise the faults. That's what hacking something together is. It's a useful skill, but it isn't what SICP or HTDP teach. SICP is about teaching you to write good, correct programs. If you only wanna do well in hackathons you should probably learn python. An incredible amount of shit is written in python so you really can often just import solution in a hackathon.

Because codemonkey's get taught that UML is at all effective in planning.

Is it difficult to make a breakout game in Java using Swing?

Distributed systems SHOULD only be written in erlang.

That and also working well in teams, which is the hard part for me.

How do I do arbitrary precision division?

I got the other basic operations (+,*,^,etc) but division is killing me.

does having a non-specified variable type like in ruby present a security hazard?
var = 5
puts var

var = 'hello'
puts var


as you can see here it doesn't give me any errors and my inputs are 5 and hello
unlike C or C++ which requires you to specify the variable type

How are you storing your values? As numerator/denominator pairs or as a decimal sequence? In the latter case you'll have to test for recurrence and raise an error or truncate.

what
the
fuck

Now I am even more scared to go to the interviews

How else would strings be done than char*? Disregarding the null termination issue.

Which languages have HKTs?

A pascal string is a nice start.
struct String { size_t size; char data[]; };

Performing operations on unknown variable types can cause a lot of undefined, unexpected, or yes insecure behavior.
As long as you're sanitizing input it shouldn't ever be an issue, but if you're really concerned just do a typecheck. Everything in Ruby is an object so it's pretty trivial to do.

This is a very nice idea

Made my C library to act maliciously if sepples standard library is linked to the program.

Long division?

#devilish

>Disregarding the null termination issue.
And there are C libraries for this. size_t, then char array, pointer goes to start of char array for reverse compatibility.
Is that it? Still pass by reference, etc.

user, this shit flooded everywhere on reddit.
Don't let it breach to Sup Forums

>user, this shit flooded everywhere on reddit.
Why do you know that?
I think you need to fuck off.

>muh sikrit klub
Not a useful post. Besides someone posted links earlier.

I'd recommend fractional data types over arbitrary precision data types. They're a bit easier. The long division algorithm is a pain. Also, it's more natural to compute transcendental functions since you can use easily infinite fractions or power series.

I guess if you do want to go through with the long division algorithm, you'll need this: en.wikipedia.org/wiki/Cycle_detection

How does it tell? Overriding a signal handler, calling a sepples function, and seeing if the signal handler is invoked?

my midterm project

#pragma weak
and test if mangled c++ symbol exists in the init function.

Acceleration should be different for each car, since dumbass drivers accelerate differently

Neat, but what's the difference in throughput compared to if the cars were perfectly aligned?

Haskell, OCaml, Idris, Agda, Purescript

C++'s shitty template system even has template template parameters which are sort of HKTs

hey Sup Forumsuys matlab Sup Forumsuru here again

youtube.com/watch?v=JPQWQfDhICA
>it's 2017 a.d.
>microsoft finally made a clear, good video explaining dlls
i'm unironically happy

(probably) dumb question time:

I'm trying to split up a large int into 3 bytes.
The method that people say to use is this:

byte0 = number & 255
byte1 = (number >> 8) & 255
byte2 = (number >> 16) & 255


but when I do this with say number = 2000, I get

byte0 = 208 = 11010000
byte1 = 7 = 00000111
byte2 = 0 = 00000000


so how would this be interpreted as 2000 = 11111010000?

>matlab guru
matlab cuck*
FTFY

Endianness

Our physical forms are gone, but our consciousness...
My consciousness still exists, perfectly, as a Lisp macro.

Matlab is confy
t. Chad engineer

That's right, though.
2000 (decimal) in binary is 11111010000.
Take your three bytes and slap them together:
00000000|00000111|11010000
Remove the leading zeros and shit:
11111010000

Why do you need this? Just curious

I wrote a circular Xor linked list in Rust:

pastebin.com/SmZYSbGq

Also, there is an easier way
int n = 12;
unsigned char* cp = (char*) &n;
unsigned char byte1 = cp[sizeof(char)-1];
unsigned char byte2 = cp[sizeof(char)-2];
....

Purpose of xorlist is to only store one ptr.

>sizeof(char)
>Bringing endianess problems into this

Oh, of course. Thanks!
header for a compression system
neat

It's a scam. Tell them you "called the police" if they contact you again.

If the cars are on a straight line tgen the first car will reach optimal speed and the rest will still depend on the car in front of it, so every cars will have less stops and gos in traffic

Fuck, that should have been sizeof(int)

GUESS YOU DONT KNOW ABOUT MY OTHER CAR

ignore this guy this

int i = 1;
printf("%d\n", i&1);


will print always 1 independently of endianess

That's exactly what it does. The XorList struct is just an accessor. The nodes themselves hold a number that is the xor of their neighbour's pointers.

1 is little endian too
11101000 &
10000000

If Haskell has HKT's, why is there such a push to rewrite standard abstractions without the higher order constructor? Such as monofoldable being objectively superior to foldable.

If you are using a HKT in Haskell for typeclass definitions, often this means you are doing something wrong. You can usually eliminate it and get a more general version that isn't overconstrained to uselessness by free theorems.

Monofoldable uses type families, many things to do with "mono" type classes are actually related to HKTs anyway (namely if you look at the nature of type classes and instances), virtually every Haskell program involves Applicative or Traversable, a few monomorphic things are really just a constrained hkt, etc.

For instance, you complain about foldable.
But then we could also talk about structures over which you can fold multiple element types.

A stack overflow answer will also tell you that you no longer have paramatricity (since you're using type families)

Hey /dpt/ I'm graduating as a software engineer soon and most my work has just been PHP/JS web dev. Recommended projects to really begin qualifying as a software engineer in the workplace?

In fact here's the stack overflow, both answers give you reasons:
stackoverflow.com/questions/39634504/is-there-anything-we-lose-with-monofoldable

Also what "push" is there?

Working through practical malware analysis.

Have a virtual machine set up with all the necessary tools and a pirated copy of ida pro because they charge like £2000 a copy even for individuals which even Adobe wouldn't do.

Make a website?