/dpt/ - Daily Programming Thread

BASIC Edition

Old thread

Other urls found in this thread:

ideone.com/89Y7iy
userscripts-mirror.org/scripts/review/162257
ideone.com/dN3QA8
github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/math/Vector2.java
github.com/robpike/filter
twitter.com/SFWRedditVideos

Haskell is a complete joke when it comes to practicality. The developer tool stack sucks, the defacto standard compiler is grindingly slow and horribly badly written and virtually impossible to build much less develop, the REPL is a toy, the libraries are atrocious and the community consists almost entirely of smug weenies.

In contrast, the OCaml community are quieter because they spend their time solving real problems and shipping production code rather than publishing research papers about The Sieve of Eratosthenes (see Page on hmc.edu). Oh, and they're honest.

OCaml has had very solid support for concurrency for over 15 years now. In fact, 15 years ago the heavily concurrent MLDonkey peer-to-peer file sharing client had hundreds of thousands of users (that's probably more users than all Haskell programs ever written combined). No similar success story exists for Haskell.

Haskell has a huge number of very poor quality libraries. OCaml has far fewer but much higher quality libraries. If you want linear algebra then OCaml has lacaml. If you want fourier transforms then OCaml has FFTW. Incidentally, FFTW provides the fourier transform routines used in MATLAB which has millions of users and it is written in OCaml. No similar success story exists for Haskell. OCaml is vastly superior when it comes to parsing, with many extremely high quality parser generators available mostly along the lines of standard industrial tools like lex and yacc (ocamllex, ocamlyacc, menhir, dypgen, camlp4). I'm not sure Haskell has any such tools and most developers use a quirky parser combinator library called Parsec that is quite simply shit. To give you some idea, I wrote a Mathematica parser using lex and yacc in OCaml and Wolfram Research bought it. I tried to write the same parser using Parsec and found it to be a nightmare in comparison and nobody is going to pay for that.

Othet than 'muh indy games'
what use is there for java outside servers?

This. Haskell is overcomplicated and unclean. Anyone that likes it should kill themselves.

Enterprise CRUD software written by Indians

Look what I found at the fiction section of the bookstore

Pooing outside of loo

Oh and ghetto memory leaks exist in java

(You)
(You)
(You)

-

Daily reminder that today's date is 100/1000/10000 in binary

reposting from a previous thread:

I'm trying to program something that has to do with IPv4 addreses and subnet masks, but I'm running into a weird error.

I have the user input a multiple of 8 (for the subnet mask) and store it in a vector of type "byte" (I have the statement somewhere in my program:

using byte = unsigned char


)

But when it runs, the program outputs the value "/377" which I've read is octal for 255
std::cout subMask;
std::vector subnetMask = {0, 0, 0, 0};

if(subMask%8 == 0) //If it's a valid subnet : "Classful addressing prescribed only 3 possible subnet masks (8, 16, 24)
{
int subCounter = 0;
for(int i = 0; i < subMask; i+= 8)
{
subnetMask[subCounter] = 0xFF;
std::cout

This is the Lord's year if 666+666+666+6+6+6

>+/- 2000 years

What is the best way to do this?

In WPF I compare 2 selected image "controls'" by opacity, so the program will check if their content id is "equals" to each other.


Basically a doubleanim happens that increases the selected images opacity to 100% and then a timer compares their content, if it is not equal then their opacity will change back to 25% and the selection disappears.

Cannot post the aource code cause i am on mobile, but how would YOU do it?

My solution seems to complex and I feel there is a way to make it more "lightweight".

The same as any comparable language?

>Daily reminder
That's not how daily reminders work.

You are printing a character type. You terminal provably shows it as "\377". You can verify this by redirecting stdout to a file and then using a hex editor to inspect the data.

To fix formating, just cast the character type to int when printed: (int)subnetMask[subCounter]

I'm having a hard time grasping what you're actually trying to show or do, or I'd recommend a solution.

Gotcha! Thank you very much!

forgot pic

>OCaml
>concurrency
Shame about multithreading though, eh?

Yes, Haskell has warts. Its standard library is a disaster. Monad shouldn't have fail. It's missing huge numbers of typeclasses. I wish it had a means of enforcing totality. IO could be defined better, in terms of operational or free. But good luck implementing lens, or semigroupoids, or free, or mtl, or any other high-quality Haskell library in any other language without a huge amount of pain and sacrifice. You just can't.

C++ has a type system that, existentials aside, can compete with Haskell

C++ is such a fucking mess I don't see why anyone would willingly use it

Design by committee is a terrible thing

No, it doesn't.

Yes, it does

So I have a bunch of boost tests which are in separate cpp files, all testing a class which is within in a hpp file

If I change code in my hpp file, the compiler runs through each cpp file to see if there are any errors. Is there any way to stop this? I'm only testing one cpp file at a time, so I don't need it to check every single cpp file each time

Rails is taking that over

Ah shit I probably should have mentioned, I'm using C++ within Visual Studio 2015

By whose metrics?

Entirely pulled out of my butthole.

But the amount of shitty indian rails code I've seen, my man...

I'm playing around with functional in C++ and some of this seems inconsistent.

auto intPow = [](const int& base, const int& pow)->int{
int val = 1;
for (int i = 0; i

I just found out my uni teaches people Java as a first language on any line that involves programming (IT, CE, CS, SE etc.)
What should i think of this?

Ooops screwed up the formatting but demo here ideone.com/89Y7iy

Most unis seem to do that

That does what I wanted, thanks

That's pretty standard. It sucks, since Java is a noisy language for learning, but it's extremely common nonetheless.

can I make money off developing solutions to the average retard who wants to make gaymus?

It's fine, I guess. There are worse things than Java, like C++.

My university switched to C# for programming 101 recently, and I've seen the same with other programs. The rest of my major was done mostly in C#, too.

Some are using Python for a first language now.

If the snap judgements that could be made about you based on your post are any indication...no. No, you can't.

pls elaborate on that.

How do you recover from falling for the CS meme

I see. Java does seem a lot less intuitive than python, and it's harder to figure out what's going on when you are just starting out, so i suppose you would get a better feel of how to go about stuff in python, since it's less cluttered.
Thanks!

>functional in C++
Why would you not use an actual functional language for this? Are you like the JS and Python babbies who can't learn any other language?

Can you exclude the ones you don't test from build? Select the cpp and settings->whatever->Excluded From Build: Yes.

Or open the XXX.vcproj and add Yes inside the tags of the inactive compile units.

It's only a meme if you're bad at it.

c++ is designed to be multiparadigm

it's perfectly fine to do such a thing like that especially when you want to have your program compiled to native assembly and not some byte-code interpreted virtual machine bullshit.

>implying functional languages have to do that

C++ is a jack of all trades and master of none.

Keep digging that hole.

it's possible it does

maybe

Your sentence makes no fucking sense, and I don't think you have any idea what sort of product/service you'd sell.

that worked, thanks

How do I stop being bad at it?

No one has hired me and I am going to die of poverty in four months.

Do you live in the US?

certainly not in a convenient fashion or syntax

template
struct Functor {
template
std::function fmap(std::function);
}


Functor::fmap(func)

Yes.

Okay, now go make lens, mtl, and RankNTypes work.

if you mean what product, I mean basic editors.

maybe some unity scripts.

I want to make a mugen clone, and selling the license for commercial games.

Great!

Turns out you're clinically retarded, or completely autistic in interviews.

It's piss-easy to get a solid job in the most basic of programming roles.

Ok, thanks.

Do you have a github portfolio? Where in the US are you looking for work?

>no existentials

Tried to do a simple file writer in C++, but I'm not getting the same performance results when I compare the result to equivalent settings in Crystal Disk Mark, so I guess something somewhere is wrong.

Writing 100 MB to a harddrive, I get 50 MB/s in CDM but 200 MB/s with this.
Writing to a ramdrive, I get 1800 MB/s in CDM but 300 MB/s with this.

#include
#include
#include

#define LEN 1024*1024*100

using namespace std;

int main() {
char * writeThis = new char[LEN]();
clock_t a, b;
ofstream gfw;

a = clock();

gfw.open("garbagefile.bin", ios::binary);
gfw.write(writeThis, LEN);

gfw.close();

b = clock();
cout

Those libraries are my bread and butter in Haskell.

This is a flawed benchmark. You are only measuring how long does it take to copy some data from your buffer to libc buffer to kernel's buffer. Your data is unlikely to have hit the disk when you close the fd.

For a bit more meaningful test:

* Prevent libc (or what the fuck the "gfw" is) from buffering your writes, use raw unix/winapi system calls.
* Prevent kernel from buffering your writes, use proper flags/ioctls.
* Avoid having to copy the data from buffer to buffer. Consider for example memory mapped IO or whatever is the norm on your platform.

please help

i know nothing about programming, but seeing all these people who write "should of" instead of "should have" online is driving me insane. i will do anything to get rid of them or fix them.

i want to develop a firefox add-on that replaces every instance of "should of" with "should have". where do i start?

You do not need a firefox addon, just learn to write a userscript, it will work on every browser, it's much easier to make and does not break with every browser update.

thank you! i will look into this and report back if i keep being retarded

Just take this and make the necessary replacements userscripts-mirror.org/scripts/review/162257

Sorrry to say that, but an addon like that already exists. FoxReplace.

You ever just open your IDE/editor and stare at it for a while, like half an hour, and then close it? "Whelp, I gave it a shot..."

[spoiler]You ever do that for a month straight?

I have class with a function:
public > {
public abstract void insertLocation(T location);
}

so it looks like this (hint: OrthogonalLocation extends Location):
public class OrthogonalSpatialDataStructure extends SpatialDataStructure{
@Override
public void insertLocation(OrthogonalLocation location) {
}
}
so why do I get this autistic error?

you could do strict MTL and lenses

wow, i had no idea about this. it seems to work, so thank you!

Any C++11 bros here?
I need some help. I have a simple game with a list of entities: std::vector. Now I want Entities to be able to store references to other entities. However, since the vector stores unque_ptrs I can't just copy them. Also, entities can be destroyed at any time. My ideas were:

1. Use a weak_ptr... but you can only create weak_ptrs from shared_ptrs, not unique_ptrs.
2. Use a raw pointer... but then you cannot know if the referenced entity still exists and you risk dangling pointers.

Is there any solution?

Also, you might be wondering, why not just store shared_ptrs in the vector? Well then I run the risk of accidentally extending the lifetime of entities by keeping some reference around in another class. I want to guarantee the entity being destroyed when the vector no longer stores a pointer to it.

Replace this "should of".
I inserted some unicode zero width joiners in thereto make this a bit more challenging.

Do you have a particular reason for needing generics?

Strictness makes me sad.

absolutely. it needs to accept Locations with 2d or 3d vectors and any other interface extending it. really depends on the implementation of the implementation of the SpatialDataStructure class.

One should use generics whenever possible. Parametricity confers many benefits.

Because you're using Java.

wow, I hate java now

I mean, you're not wrong in most of that. But I think that Haskell's done a whole lot of good too and has some really nice features that I wish OCaml would get. The shortcomings of Haskell's ecosystem (tooling, compilers, standard library, etc.) are a result of a bad community, not a bad language.
anyways, I think I still prefer Parsec to lex/yacc for a lot of things. it's weird for big parsers, but it makes error handling so much simpler and it lets you write tiny code for simple parsers so ill probably prefer it 9 times out of 10.
this

Post the signature for Location.

>it's fucking real
ideone.com/dN3QA8

public interface Location{
}

Any second now the butthurt Java monkeys will crawl out of their mancaves and say that it's because you don't understand caching and that there is not anything wrong with it

Your options are reference counting (shared_ptr + weak_ptr), garbage collection (probably not what you want to include in a C++ project), indirection (store a key to a map instead of a pointer), or implementing something yourself on top of raw pointers.

If there are no cycles in your data, the "implement something yourself" option could be helpful.

Couldn't you have shared_ptrs in the vector and weak_ptrs in the entities? You would have to make sure you don't keep shared_ptrs around in the entities but as long as you had functions in the entities put shared_ptr = weak_ptr.lock() on the function stack rather than as a member it should automatically be released.

template
struct Maybe {
T& get() { return *ptr; }
const T& get() const { return &ptr; }

bool isValid() const { return ptr; }
void invalidate() { item = nullptr; }

private:
T* ptr;
}

std::unique_ptr

const T& get()
should be *ptr

for a non-heap version

struct Maybe { T Item; bool valid; }

>$CURRENT_YEAR
>not using Go

Post signature for Vector2

from there it's all libgdx

github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/math/Vector2.java

Rob Pike pls go

business applications requiring multi platform support and rapid releases for each platform.

Thank you guys, the "indirection" approach looks promising, I'll look into that.
If all fails I might just go for the shared_ptr approach.

Using the code you've posted, it compiles fine.

CL, Scheme or Racket?

SBCL, gcl, clisp, guile, chicken? Something else entirely?

I want to be like the greybeards

not everyone is a faggot, unlike you

does boost support mock objects too? is it better than google test/mock?

not for me. had to change it all and now I have to cast. not that great but whatever

EMBRACE THE SIMPLICITY

ALL YOU NEED IS 'FOR' LOOPS: github.com/robpike/filter