/dpt/ - Daily Programming Thread

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

Attached: miku dab.png (1062x783, 40K)

Other urls found in this thread:

youtube.com/watch?v=5QYpD428hAQ
esri.com/library/whitepapers/pdfs/shapefile.pdf
twitter.com/NSFWRedditImage

Masturbating

They give up crucial functionality and become effectively non-Turing complete.

Heap allocation is pretty uninteresting. It can be considered side-effect free (at least outwardly) because it doesn't interfere with existing allocations. The only "interesting" thing it can do is fail due to OOM, which is in FP is usually assumed to never happen and thus just crashes the program. Linear types (or monad abuse) are then used to prevent pointer misuse such as use-after-free.

Or garbage collection, which is more common.

Working on a software, which will give real time advise to poker players, basically a semi-bot.
There are tons of things to consider though, mainly how I can build a good model with limited computational ressources.

Can someone make me a program (in the Jow Forums sense of the word) to read and actually finish pic related?
I've tried before but I always get burnt out or bored.

Attached: 51TGEPRTDNL._SX377_BO1,204,203,200_.jpg (379x499, 33K)

that book is a meme (seriously)

C is a legacy language, user. Why do you wanna learn it? Do you also wanna learn COBOL and FORTRAN?

Ok.

I need it for a lot of courses in my college.
I mean I already know how to program in C, I just want to finish the damn book to be "an expert".

Attached: 1524453702984.jpg (366x380, 20K)

When I read about new stuff, first I just read the whole book and I know I will only understand like 20%, but it gives me a broad overview. I just read it fast, I read it in every situation when I have free time.
Later I go more in depth.

Are you learning C, or are you learning programming in general?

Its a shit book for learning C as a beginner. Start with something like C Primer 6th edition. Just make sure to do all the exercises.

Haskell encodes imperative procedures as an abstract datatype. It doesn't give you any way to run a procedure via a function, but it does give you functions that can combine procedures together into larger procedures. It turns out this is enough.

getChar is not a function, it doesn't vary by any argument, and it's certainly not a Char. It's not an 'x'. It's an imperative program.

putChar is a pure function that gives an imperative procedure given a character.

getChar >>= (\c -> putChar c) expresses an imperative procedure that echoes one character input.

>There, it is done by monads
The fact that you can map functions over procedure results (fmap), collapse procedures that compute procedures into combined procedures (join), and make do-nothing procedures that give pure results (return) is certainly convenient, but it's a distraction if you just want to know what they are.

Don't use that book
CS50x (free course)
Modeling with Data (has an extensive first part tutorial in C)
21st Century C (a bit advanced, but covers important modern things such as gdb, valgrind, git, make, has an appendix which quickly covers basics)

>(in the Jow Forums sense of the word)
read 3 sets of 10 pages after waking up. Don't forget the oats.

>I mean I already know how to program in C
Ahh, then also Modern C (free pdf)
Expert C Programming
Mastering Algorithms in C, for some algo/data structures/complexity side of things, but using C

>CS50x (free course)
I actually learnt most of my C by doing CS50. Except the Psets felt really heavy and actually difficult.
The difficulty gap between each of them felt very steep for a brainlet such as myself.
Maybe I'll try again though, it might be easier than to actually sit and read a book.

Attached: 1514701406674.jpg (645x729, 49K)

*blocks your path*

"Oh hey user, I just finished writing that compiler"

How do you react?

Attached: quil.png (1095x629, 286K)

>Mastering Algorithms in C, for some algo/data structures/complexity side of things, but using C

Yeah this sounds very interesting.
Thanks a lot everyone.

I dont talk to women

fuck it, () = ap

Is this a girl(male)?

>The fact that you can map functions over procedure results (fmap), collapse procedures that compute procedures into combined procedures (join), and make do-nothing procedures that give pure results (return) is certainly convenient, but it's a distraction if you just want to know what they are.

You are right, that's why I wrote the stuff about returning computations, but "returning computation" is not that google friendly if you just want to learn about monads.

>female "programmers"

>>female "programmers"

Attached: meh.jpg (600x450, 34K)

How come she wrote a compiler if the dislikes computers?

In order to not have to deal with computers of course.

of whom did you quotate

Normally I wouldn't complain about the OP image but this one is just idiotic.


Found myself in a bind. I need to make a CRUD API using MongoDB, and I have a design problem: How do you handle documents with files in them?
For example, we have a user object
User: {
name: String,
email: String,
avatar: File,
...
}

And so I would expose a POST endpoint where people can create such a user. Now there's a problem with editing. Obviously you don't want to send a whole new File every time the user updates some metadata.

So you could separate the File from the user as a reference. But then how would you set up the CRUD endpoints?

Feeling threatened, sweaty?

Avatar is an integer, which is rowid in the avatars table. Foreign key constraint.

Misread the question.
Have a table keyed with username, value = file, another table with username and metadata. Then just have an endpoint that updates the value in the avatar table with whatever you post there and key from login cookie.
This is easy in PHP, at least.

im working on absolutely nothing and i came to this thread to steal ideas but there's nothing interesting help

yeah hold on a second let me just get into your head and find out your skill level and the type of projects you're interested in

The way I do it is I index images by their SHA256, and use that as an ID to reference the image. So you get
{
"name" : "John Smith",
"email" : "[email protected]",
"avatar" : "d1bc8d3ba4afc7e109612cb73acbdddac052c93025aa1f82942edabb7deb82a1"
}

So I should have a separate Upload endpoint which only touches the avatar

well in MongoDB it's simple enough to just use the Unix timestamp as a reference, which is the default ObjectID. I suppose SHA256 also works, I could consider collisions irrelevant in my use case

I was asking more along the lines of what does the actual creating, reading, and updating look like

In C# how would you search for an object in a list of objects given it has a certain element?

In C# you would not have a List, that would be stupid

You have to treat the file as separate from it's metadata if you want to achieve that kind of behavior.

Store metadata alongside the file in the document and then you can either have it embedded on the User or referenced as mentioned above.

This is down to your application layer, not the DB layer.

What would be a better alternative?

In all statically typed languages--where "var" and such constructs are looked down upon--there is usually a good reason.

Using the proper type means that you will get magnitudes more support from the static analyzer, aka "the autocomplete". Microsoft makes extremely good static analyzers (Intellisense) and you would be making a mistake to not make use of them.

Having said that, when you are dealing with data, the types need to be well known. If you are parsing a JSON object from a MongoDB database, chances are there is a model schema that you can build your classes and types around.

There are almost no cases where there is no known schema and thus no applicable type, being forced to make everything "Object". In this case you would be using NLP and Machine Learning, but chances are you are not working in this field, and you are framing the problem wrongly.

Don't index images by sha256. Either index images by username of their holder, or index sha256 hashes by username of their holder if you want to save space.

Just discovered a new fetish

Wrote a scraper for indeed.ca to collect the incomes of software developers. Here are some graphs

Attached: d3e9a92dd9f3373e3bcb7dc5b5feca2a.0.png (596x616, 98K)

now create a nested histogram with buckets based on cities in the US

Will do when I get home

Wait, what's a nested histogram?

I made it up to describe a histogram containing histograms.
Bucket first by city and then by income level. I guess you could say it's more of a hash table

?

Attached: images.png (219x230, 2K)

youtube.com/watch?v=5QYpD428hAQ

I have no idea why OP made it miku.

do you know what a compiler is?

To achieve peak programming performance, the following are required:
>striped socks
>striped fingerless gloves
>colored nail polish containing glitter
>hrt
>fursuit
>latex gimp suit over the fursuit
>vegan diet including hot peppers, minimum of 200,000 scoville heat units per day

>Don't index images by sha256
In my use case this is perfect, but I tend to prefer append-only databases anyways.

more like

Attached: 3d-histogram-map-us-election-best-25-2008-election-results-ideas-on-pinterest-american[1].jpg (736x582, 95K)

How are you going to solve it with the endpoint then? Better have a separate ChangeAvatar endpoint.

Nah

No, you just use multipart/form-data, scan the file as it comes in to compute the sum, then do a lookup to see if it exists already. If it's not in the form you don't change it, which souldn't be an issue for "deleting" your avatar because that should be a separate button altogether for UX reasons.

But why would you download and then upload a binary file every time someone wants to change something in the metadata?

>If it's not in the form you don't change it

type-level programming is a disgusting hack, prove me wrong

>guess what I'm so angry about so that I can tell you that you're wrong and still not elaborate!
that's not how any of this works, user

Is anybody using GraphQL in production?

What are some of the challenges that you're facing with it?

Attached: og_image.png (1200x630, 143K)

do you mean "object" as in literally object/System.Object, or are you just speaking generally? and are you searching for the object by reference, or by value?

a List can be perfectly reasonable. it's the standard way to have a List which can contain any object. you can access some common/major functionality through System.Object's interface alone. sometimes you want/need total genericism and/or don't need any more derived functionality

generally (when possible), a List constrained to a particular type or interface, so that the parts of the contained items your code requires are guaranteed to exist. unless your code needs to be totally generic as i mentioned above

>In all statically typed languages--where "var" and such constructs are looked down upon
>Using the proper type means that you will get magnitudes more support from the static analyzer
uh... what? "var" is not looked down upon, and nothing about it is dynamic or polymorphic. it's just static type inference - primarily simply so that you don't end up having to write out the same potentially verbose type signature twice in the same line, once on each side of an assignment. the compiler knows the type of the expression to the right of the assignment operator at compile time (because it knows the type of every valid expression at compile time, because that's literally what static typing is). "var" just says to infer a variable's type from that expression. IntelliSense gives you the same information for a variable of inferred type

>There are almost no cases where there is no known schema and thus no applicable type
there is a fairly common case; the generic case. that is, where all types are applicable

>In this case you would be using NLP and Machine Learning
are you high? what the hell are you talking about

>sometimes you want/need total genericism and/or don't need any more derived functionality
literally never happened before.

>"var" is not looked down upon
In C#. Read the sentence closer.
In other languages, "var" indicates dynamic typing.
I know what type inference is.

>the generic case
Which resolves to merely type inference. There is a type, and that type can implement a known interface, which is the preferred way of dealing with generics.

>what the hell are you talking about
Try to extract named entities from this post and then perform knowledge based completion on it.
There is no schema.

Looking for youtubers that constantly upload C/C++ related development videos.

Attached: [HorribleSubs] JoJo's Bizarre Adventure - Diamond is Unbreakable - 18 [720p].mp4_snapshot_08.05 (1280x720, 101K)

Look for books instead. Your brain is so fried that you can't learn anything without watching some fuckwit drone on and on for an hour.

If all else fails, try conferences instead. At least they tend to be well written and rehearsed.

Dabbing?

what ever happened to minimalism general?
i really miss that desu

i miss catheter general

GraphicksMagick, ImageMagick, or something else, for C and SDL2?
I have no purpose, just playing and learning.

Anybody know what I am doing wrong. I want to copy only a portion of the file but it does the whole thing.

FileStream fs = new FileStream(fileIn, FileMode.Open, FileAccess.Read);
using (BinaryReader br = new BinaryReader(fs))
{
//Goto offset of file
fs.Seek(fileOffset, SeekOrigin.Begin);

//Create directory to save file
System.IO.Directory.CreateDirectory(Path.GetDirectoryName(fileOut));
using (FileStream output = new FileStream(fileOut, FileMode.Create))
{
fs.CopyTo(output, compressedSize);
output.Flush();
}

}
fs.Close();

using (BinaryReader br = new BinaryReader(fs))[/cide]
and they say c# is better than java

its basically the same thing in java

On C is there a way to scan a string into an array and place each letter on a different slot of the array?
Both scanf() and gets() scan the whole text into one slot.

Attached: 1339112127540.jpg (849x866, 538K)

what? it's impossible for a string to only take up 1 element of a char array if it's longer than 1 character
are you stupid?

well, fuck me, seems my issue is a completely unrelated thing.

tell me user, I'm willing to help

Nah, I think I have this under control.
Thank you anyway

Attached: 1454653139047.jpg (221x225, 8K)

>In C#. Read the sentence closer.
>In other languages, "var" indicates dynamic typing.
but it doesn't in C#, nor is it looked down upon, yet you said
>In all statically typed languages--where "var" and such constructs are looked down upon

>literally never happened before.
it happens plenty. for example, you might have a List, HashSet, Dictionary, etc which needs to be able to contain any given object, where all your use case needs to be able to do is add/remove/find/detect items by reference, enumerate them, write them as strings, get their type information, etc which can be done with no more than the interface of System.Object

>Which resolves to merely type inference.
>There is a type, and that type can implement a known interface, which is the preferred way of dealing with generics.
no it doesn't. "List" isn't type inference, it's polymorphism. and it's more generic than a List constrained to any given interface, because that still requires the implementation of that interface. all classes implement System.Object's interface because all classes derive from System.Object. "List" works for all classes including those you did not author which are unaware of your interface. what is "preferred" is to constrain usage no more than necessary. if your use case does not require more a derived type / constrained interface than System.Object, using one only serves to introduce an arbitrary limitation. when further constraint is unnecessary, "object"-based polymorphism is not "stupid", it's standard practice

>Try to extract named entities from this post and then perform knowledge based completion on it
that has nothing to do with "var", type inference, "object", or polymorphism. it's obvious that you won't be able to achieve compile-time completion in that case without a schema, because that scenario is clearly dynamic in nature. it's completely unrelated

Do you add documentation to the class, constructor or both?

Neither, because OOP is trash.

How does shared lib works?
For example :
The shared lib consists of this
//thelib.h
void interface_set(int);
int interface_get(void);
//thelib.c:
#include "thelib.h"
static int global_a;
static int global_b;
void interface_set(int){ /*...*/}
int interface_get(void){/*...*/}

Now there is another shared lib consists of 2 .c files that wrap the "thelib" shared library
//wrapper.h
void interface_do_a(void);
void interface_do_b(void);
//wrapperlibmain.c
#include "wrapper.h"
#include "thelib.h"
static int t;
void interface_do_a(void)
{
interface_set(/*...*/);
/* ... */
t = interface_get();
}

//wrapperlibsecondary.c
#include "wrapper.h"
#include "thelib.h"
static int n;
void interface_do_b(void)
{
n = interface_get();
interface_set(/*...*/);
/* ... */
}

Does the global static variable connected to each other?
Does the wrapperlib.so allocate both the static global variables n and t when loaded?

is there a way to generate client classes for a REST service, like wsdl in xml?

Reposting from previous thread:
Hi guys
I'm currently working on reading Shapefiles. I am using documentation:
>esri.com/library/whitepapers/pdfs/shapefile.pdf
It says:
>The integers and double-precision integers that make up the data description fields in the file header (identified below) and record contents in the main file are in little endian (PC or Intel ® ) byte order. The integers and double-precision floating point numbers that make up the rest of the file and file management are in big endian (Sun ® or Motorola ® ) byte order.
I have swapping endianess of bytes figured out but out of curiosity, can anybody tell me why is it made that way? What's the purpose? What are the benefits?

>Does the global static variable connected to each other?
it's part of the same translation unit so yes.
>Does the wrapperlib.so allocate both the static global variables n and t when loaded?
yes.

you tend to read low-order bits first so little endian is slightly faster or something

>tfw too shit at communication to hold down even a programming job
i just want to code dammit
worse, i dont know how to fix it

Attached: 1530086419898.jpg (400x400, 24K)

at least you get past the interview
I'm going to be stuck on SSI till I kms

I'm writing an API which is not middleware. In fact, it is expected that the only consumer of this API will be other APIs. Should I return exclusively JSON errors or HTML errors?

FileStream.CopyTo()'s second argument tells it how large a buffer to allocate, not the amount of data to copy. and you're not actually using the BinaryReader for anything in this case (it's basically just a wrapper/adapter for a Stream that adds methods for reading individual chunks (and sequences of chunks) from the Stream as sized/typed data). if all you want is to copy part of the file, you should be able to do that with just FileStream by doing something like:

using (var streamIn = new FileStream(fileIn, FileMode.Open, FileAccess.Read))
{
byte[] data = new byte[compressedSize];
streamIn.Read(data, 0, compressedSize);
Directory.CreateDirectory(Path.GetDirectoryName(fileOut));
using (var streamOut = new FileStream(fileOut, FileMode.Create))
streamOut.Write(data, 0, compressedSize);
}


you don't need to call Flush() or Close() because those will get called when the FileStreams are disposed at the end of their respective "using" blocks

>What are some of the challenges that you're facing with it?
the java implementation is awful
its hard to make db queries efficient, you'll end up making multiple queries instead of a single one with joins
if your schema isn't easily representable as a graph, your gonna have a bad time

>yet you said
Splitting hairs. C# is in fact an outlier where "var" refers to type inference and not dynamic typing. We're wasting too much energy on trying to argue the semantics of a sentence that was purposefully designed to be expedient rather than pedantically correct

>List, HashSet, Dictionary
Most people aren't standard library implementers, and if you look at the source code of common data structures (especially graphs) in C++, you will find them to be very restrictive in their types.
Use cases and pragmatism generally work against being fully generic, and outside of standard library development I see no use for classes operating on fully generic objects.

>it's obvious that you won't be able to achieve compile-time completion in that case without a schema
The point of the original post was that it is preferred, for the purpose of static analysis/autocomplete/Intellisense, that the schema is known beforehand, whether the use case is inherently dynamic or not is irrelevant, because these are scenarios that real people actually run into.
A more common scenario would be a FUBAR NoSQL database with unspecified schema.

It's 8 chapters. Each Chapter took me 3-4h doing all exercises.

4*8 = 48h
Divvy that up how every you like.
1 chapter per week. 1 chapter per day. X # of chapters per day.

Only Javeets look down on type inference.

But Java has type inference now. That leaves only Cniles with their weakly typed shitlang.

Will using an intptr_t instead of a void* cause issues wrt to aliasing?

>anime

Attached: 0.jpg (1280x720, 144K)

Except every Java dev out there forbids its use.

Is there any way to take a file from another branch in git?
I have 2 branch and each of them modify a different file.
Branch A modify foo.c and introduce a new file foobar.c, while branch B modify branch bar.c,
but when I'm in branch B and merge the branch A with git merge A , git only modify the foo.c and doesn't add the new file foobar.c, even though the last commit in branch A contain both foo.c and foobar.c.
Is there any way to get the foobar.c to branch B other than copy it to non-git directory and recopy it back to the branch B?