/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

mega.nz/#doc
twitter.com/AnonBabble

Haskell

C++

nth for Go is pretty shitty tbqh famalam.

*completely shitty
Go is the Go of shit languages

Java > C++

Why do people make fun of me when they find out that I write all my software in C?

>c style errors
>no generics
>shit standard library
I fell for the meme ;_;

You're doing unnecessary harm to yourself

Me too.

I kind of feel ya bro. I'm an SE student, and whenever we are given the option of choosing a language for an assignment, I always go with C. I get so much shit from it from other students, usually those same students are using Java.

It's overkill for most projects.
Keep writing in C. It's the language closest to God.

Because purposefully making things hard for yourself for absolutely no reason is stupid.

those java kids just want to make "apps" and justify the tuition they paid by shaming others that make the smarter choice

Part of being a good software engineer is knowing what tools to use for a project. Using one language for everything because you're comfortable in it, or because of some weird sense of it always being superior is a generally not wise thing to do.

Unless your project was either for a microcontroller, or called for extreme efficiency, then using C is just needlessly making things more difficult for yourself.

>c is difficult
java programmer spotted

>using the term 'tools' with regards to software engineerings
I hate your kind

Not that it matters, but it was for an assignment where we were to generate a bunch of files with floating point values, and then implement heap, merge, and quick sort in a language of our choosing and compare sort times.

I choose C, not because I wanted to "feel superior" but because I wanted a challenge and I always have felt more comfortable with coding algorithms in C. I use Java way too much for pretty much every other class anyway, so if given the option, I'll take something else.

and btw, it might have been easier to do in Java, but for me it was a valuable learning experience. I came out on the other side a better programmer. and isn't that the entire point anyway? When I'm an actual software engineer and I need sorting, I'll use a Java library.

define tool.

C GET request:

#include
#include
#include
#include
#include

#include
#include
#include
#include
#include

int socket_connect(char *host, in_port_t port){
struct hostent *hp;
struct sockaddr_in addr;
int on = 1, sock;

if((hp = gethostbyname(host)) == NULL){
herror("gethostbyname");
exit(1);
}
bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);
addr.sin_port = htons(port);
addr.sin_family = AF_INET;
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&on, sizeof(int));

if(sock == -1){
perror("setsockopt");
exit(1);
}

if(connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == -1){
perror("connect");
exit(1);

}
return sock;
}

#define BUFFER_SIZE 1024

int main(int argc, char *argv[]){
int fd;
char buffer[BUFFER_SIZE];

if(argc < 3){
fprintf(stderr, "Usage: %s \n", argv[0]);
exit(1);
}

fd = socket_connect(argv[1], atoi(argv[2]));
write(fd, "GET /\r\n", strlen("GET /\r\n")); // write(fd, char[]*, len);
bzero(buffer, BUFFER_SIZE);

while(read(fd, buffer, BUFFER_SIZE - 1) != 0){
fprintf(stderr, "%s", buffer);
bzero(buffer, BUFFER_SIZE);
}

shutdown(fd, SHUT_RDWR);
close(fd);

return 0;
}

Python GET request:

import urllib.request
urllib.request.urlopen("example.com/foo/bar").read()

*
#include
int main() {
read(urlopen("example.com/foo/bar"));
return 0;
}

how can a language that has literally 0 features be overkill?

ReQL is pretty nice
r
.table("test1")
.get(1)
.delete({returnChanges: true})
("changes")
(0)
("old_val")
.pluck("name", "SHA1")
.merge(
r
.table("test2")
.get(r.row("SHA1"))
.without("posts")
)
.default(null)

>Mega SDK uses C++
mega.nz/#doc
>java/javascript/node/java/ruby/etc script kiddies blown the fuck out

People that use C unnecessarily are like lumberjacks who insist on using an axe instead of a chainsaw to cut down a redwood because "it gives them more control" when in reality they're just luddite pieces of shit wasting their time.

C offers at best one major advantage over C++, and that's language consistency/cleanliness

Help. Every program I make I end up hating it on a design level.

Use more monads

What the fuck is a monad and why should A non functional user care about them?

C > OOP

Monads help encapsulate side effecting computations, e.g. IO, non-determinism, failure, access to an environment

If an image scraper detects an image that shares width, height, file size and md5sum with another image should it
1) download the image in full with the new name
2) make a symlink from the old to the new image with the new name
3) ask the user ???
4) something else

But does it apply to non-functional users? I use C++, so what would a monad look like in C++?

template
struct Vector {
static vector return(U elem);
vector map(T->U func);
vector bind(T->vector func);
}

I work at a Telephony company. I have access to API's that can make hundreds of calls. What should I do with this?

vector join(vector vect);

A Monad is how Haskell fanboys cheat at being "pure functional".

>T->U
This won't compile.

I know

(You)

it depends on what you're doing. if you want to be safe in the event that you accidentally delete the first image (either accidentally or whatever), wouldn't a symlink be a bad option? (do hardlinks keep the file around even if the target is deleted as long as there are destinations floating around? i honestly don't know; i only learned enough about symlinks to make them, which is admittedly pretty shallow).

if that's a concern, you want to download the image all over again (or at least make a copy; i figure Sup Forums sends md5sums via the API so if you get all the details you mentioned then you could save yourself the bandwidth and just make a copy of the local file).

if you're not worried about all that, i would probably make a symlink.

my kneejerk reaction is to ask the user all the time because invariably the most reasonable decision you make about this will be pants on head retarded to at least one of your users (and it'll either be your fault or theirs, but you'll definitely have to deal with them down the road). but you could satisfy this by making something toggle-able. for example, if you're talking about a shell script, just add a flag to deal with this circumstance (e.g. `--duplicate=(symlink|hardlink|download|skip|...)` and implement a default that makes sense to you personally).

>I know
Then what is it supposed to mean?

vector map(std::function);
vector map(T(*)(U));
vector map(someFunctorTtoU);

Call me maybe.

Give me your number and I will spam your number or connect it to a gay sex line.

Your job

>C is hard
I don't understand this.

I mean it's certainly more time-consuming but I've never come across any scenario where C is somehow outright more difficult than another language for a given problem.

C is also more fun than other languages in my opinion.

>C is also more fun than other languages
you have a strange opinion

What is the best language for general use that a beginner can learn? I'm not interested in web development.

unorinically Haskell

ironically Haskell

Toggle-able is fine.

How would you store the information between program runs?

An associative array (md5 -> list of files) stored in some kind of .cache place?

can someone please post the newest programming challenge thing ?

PHP is the most fun but I like C too.

Furthermore I consider that Java is shit.

TRIGGERED

>Java

Here's an example:

struct.def.mainchart.vrmm main()
poke.limit = pokelimit1
set:start_condition to === start.condition
{
{
{.
to screen.outdata -> text
prefix.start.memory.data.limit x01254-34(1)
garbage.collector = null
write.screen.outdata: ("Hello World!")\t\o\e
}
}
}What an elegant language!

C, it's like latin.

That's nowhere close to being valid java?

Sure

(Last digit of your ID decides)

Lol I don't think sorting is that much harder to do in C, nothing wrong with that choice.

>he did it the absolute mad man

haha i laughed so hard at your joke

I enjoyed this, thank you user
saved

rolling

In C++, I need to pass an argument to a lambda callback, but only sometimes. The type of argument will always be different.
Can I use a void pointer? Or should I use a typedef?

get

You do know that Java is constantly updated and expanded?

This was just a peek preview of the next iteration.

You're welcome.

But if you wanna GodHand-sort. Try COBOL + SQL. :P

Here it is in Racket:

"Hello World."

Herro /deepeetee/!

I'm learning myself C. And I'm looking for some tutorial on (n)curses. I want to create some terminal-style-"GUI".

Something like this would be cool, please.

How do I make a new Line in PHP?
I tried
echo "Hello World";
but it doesn't work.

...

Actually a really cool one for some sorting algorithms is haskell:

quicksort [] = []
quicksort (x:[]) = x
quicksort xs@(y:_) = quicksort [x | x

lol forgot the `quicksort` in front of the second list

use
filter (

roll();

I'm getting memed on, aren't I

fucking awful, sorry, also quicksort [x] = x instead of the awful quicksort (x:[]) I should go to sleep

Is SICP still worth it? MIT stopped teaching it last I heard.

yep also nice, I like how mathy it is with list comprehensions though.

quicksort [x] = [x] I'm gonna kill myself

No, it is actually a nice language

it's not 'more mathy' it's just more obtuse to optimisation and less clear to read
functional languages are already 'mathy'

SICP is still great but no longer the 'best for every possible case' if it even was.

If you're interested in a good intro to CS and programming, with a heavy theoretical side (lots of programming but it's all snippets) then go for it. It's a classic and it has wizards and magic and shit.

It's almost set notation though, and I've never seen a filter in a math paper.

Also I'm not saying my version is better, it's not. It's just to illustrate a nice, very math-like way of writing quicksort.

is this bait or are you just retarded?

Thanks family, i'll check it out

Depends on what you want to do. If you really don't have a clue, then if you come from an engineering background go C, if you come from a math background, go haskell; want to build something with a GUI or graphics easily and quickly go Java, otherwise go Python.

Be sure to check out the lectures (they are on youtube) too, they are really nice

aside from teaching lisp, what does one gain from completing SICP?

I need help.
This is my first time using OOP, and every time I call a library class function I have no idea what kind of value I'm going to get.
For instance (in C#) HttpResponseMessage.Content property.
What even is it, a string, another class, a struct, some JSON shit?
Every single time I do anything in this language I have to look it up in the docs, and it never resolves to anything concrete so I never know what to do with the return values I'm getting.
What do?

SICP gives a quite clear explanation of concepts still relevant today (functional programming, object-oriented programming, etc.) in a way that's a lot clearer than what you find these days.

Also SICP introduces you to many other fundamental concepts like computational complexity, recursion, etc. Even if you're already familiar, SICP will bring these concepts together in a way that clears the mind. It answers the question of 'what are we actually doing as programmers?'

Do you need a good math base?

>
That's the bold tag, you dumbfuck.
Use the
tag.

C way is faster tho

MY FUCKING SIDES

Not that guy

I was always into science and math, but it's more likely to make math a lot clearer. I took a philosophy from SICP which helps with a lot of my life.

Nah. Just some basic stuff. Most of the math in there that you may not understand is stuff you can learn in 10 minutes (complex numbers, prime factorization etc.)

That doesn't have anything to do with OOP, it's a typing issue. However you are in luck, as C# is statically typed, so figuring out stuff like this is trivial.

Let's say you have
System.Net.Http.HttpResponseMessage hrm;
Now whenever you type hrm. (note the .) intellisense will pop up with a list of properties and methods. You then type in hrm.con, it should highligh hrm.Content, and a little thing will pop up with the signature of the method or property. You can see that in this case it's System.Net.Http.HttpContent System.Net.Http.HttpResponseMessage.Content { get; set; }.

The first part (System.Net.Http.HttpContent) is the type, the second part is the name, the last part is shows whether the property is publically accessible, or what parameters to pass in the case of a method.

This is one of the main things I like about C#. Also if all else fails MSDN has great documentation, just search for HttpResponseMessage and you'll find the class with signatures of all its properties and methods, constructors and destructors, and so on.

It's IO bound so not really.

Can anyone help a C++ noob out? I'm trying to define the following as complex numbers and operations. I'm Googling around and every site is telling me a different conflicting way to implement these.

I need to implement below as complex numbers.
>a = (a.x, a.y) and b = (b.x, b.y)
And below as complex operations.
>a + b = (a.x + b.x, a.y + b.y)
>a * b = (a.x * b.x – a.y * b.y, a.y*b.x + a.x*b.y)

The same reason people would make fun of you for using a screwdriver as a hammer. I mean you can probably use the handle of a screwdriver to beat a nail down into a plank, but there's a concept of using the right tool for the right job.

C is good for a lot of things, especially when they need to be fast. C++ and Rust have nicer abstractions, but for most things they can be used in, C is at least viable.

But you don't always need the program to run really fast. Sometimes you just need the program to be made in 5 minutes, since it's going to run in less than half a second any way you slice it. For these sorts of tasks, interpreted languages make more sense.

(a + i b) + (x + i y) = (a + x) + i (b + y)
(a + i b) * (x + i y) = (ax - by) + i (ay + bx)