/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

github.com/gmpl/FSharpPlus
github.com/gmpl/FSharpPlus/blob/master/FSharpPlus/Samples/Haskell.fsx
pastie.org/10872554
pastebin.com/9ywRVfzG
pastebin.com/awcALW3Y
pastebin.com/YqQZQe4u
youtube.com/watch?v=FnGCDLhaxKU
pastebin.com/0hgT1cxG
twitter.com/NSFWRedditGif

>3 posts early

consider completing sudoku

>traps

First for Java

Hime back in the OP!

Batch import script for rtorrent, since I'm moving from an ancient version of uTorrent.

Giving freelancer a shot.
Also if anyone wants me to make something I'll do it in exchange for 15 bucks or 1 billion ISK in eve online :}
Totally serious.

Make me a sandwich and mail it to my house.

1 billion ISK is like 30 dollars you bitch

give me haskell or give me death!
github.com/gmpl/FSharpPlus
github.com/gmpl/FSharpPlus/blob/master/FSharpPlus/Samples/Haskell.fsx

I know it's almost completely useless, but I love the concept and look of Befunge. Can someone recommend a good interpreter?

how do i decode a base64 string as binary in C? i need to write it to a file as a test but google doesn't help much for this

I like the way the code looks too, saw befunge fizzbuzz

Which base64? Anyway, the answer is a switch statement and shift operators.

Planning to learn Lua -- which version do I choose, or does it matter?

When in doubt choose the newest version. It most likely doesn't matter, it's not nearly the horrible wasteland that python 2.7 vs 3 is.

Are there people who consider themselves programmers who don't know how to write in C?

I get it if C might seem dated but I honestly don't know if there's a more fundamental language to modern day programming.

Java

I am on a team that mostly works in Java and everyone on it at least learned C in school. Hell at my school, every class pass the introductory level courses were mostly in C. (Hell, my 101 was in C)

Any other options I should add?
usage: rtorrent-add.py [-h] [--utorrent] [--start | --no-start]
[--preserve-priority | --no-preserve-priority]
[--preserve-ratio | --no-preserve-ratio]
[--preserve-location | --no-preserve-location]
[--preserve-all | --no-preserve-all] [--copy]
[--root ROOT]
FILE [FILE ...]

rtorrent import utility with batching & uTorrent resume file support

positional arguments:
FILE one or more files to import

optional arguments:
-h, --help show this help message and exit
--utorrent, --uTorrent
whether the input should be treated as uTorrent resume
files
--start, -s start torrents on import (default)
--no-start, -S do not start torrents on import
--preserve-priority, -p
preserve priority (includes files) if
possible/applicable (default)
--no-preserve-priority, -P
do not preserve priority
--preserve-ratio, -u preserve ratio if possible/applicable (default)
--no-preserve-ratio, -U
do not preserve ratio
--preserve-location, -l
preserve location relative too the download root if
applicable (default)
--no-preserve-location, -L
do not preserve location
--preserve-all, -a same as -pul
--no-preserve-all, -A
same as -PUL
--copy, -c copy torrents to rtorrent sessions directory
--root ROOT, -r ROOT override rtorrent's configured download location

Either use a library, or make some ugly hack that looks like this:

pastie.org/10872554

Disclaimer: I have not actually tested the big endian version, and this does not run on middle endian platforms at all.

Algorithms you should know, or you're probably a code monkey
>simplex method
>FFT
>ford-fulkerson
>IDA*
>PCA
>gram-schmidt procedure
>burrows wheeler transform
>eigenvalue centrality measure
>support vector machine
Note that these are all highly useful algorithms and not academic masturbation, yet many programmers don't understand these

>I went to college so I'm not a code monkey
k

(p -> q) != (!p -> !q)

redpill me on these algos

(p q) = (!p !q)

Yeah but that's not what the post said

try learning those by yourself without formal upper education, i.e., paid professors. it's practically impossible, unless your daddy engineer supports you, which is obviously unrealistic to say the least.

p ~> q != p -> q

C is an extremely important language to know because a large portion of our system level infrastructure is built on it. Most language interpreters are written in either C or C++. Libraries for cryptography, graphics, and other computationally intensive tasks, are written in C or C++, and given a wrapper for other languages. Nearly every other programming language has a foreign function interface to talk to C, because if they didn't, they'd basically be screwed out of every popular software library. To put things into perspective, if I want to use .png images in my application, no matter what language I'm using, I'm either using libpng or a library that uses libpng, which means I'm relying on some C code someone else wrote. I'm also relying on zlib, which is also written in C.

To put things more succinctly, all of the building blocks that make up a modern computing system are written in C. To not know C is to not know how any of your tools work.

If you're looking for anything else that might be seriously important, arguably Javascript should be understood at least somewhat by everyone. It's an ugly as shit language, but if C is the language to understand system software, Javascript is the language to understand web software. If it runs on a browser, it's either Javascript or deprecated.

books are better professors

sure, but then, if you aren't learning this stuff in college (or some educational institution), you probably don't even have spare time to do it.

Woah! You truely are OFF the rails tripfriend

I liked his cameo on that erlang movie

and he doesn't even know C

nobody in this thread knows C

All of this just astounds me when I come across someone who doesn't really know C. Thanks for the context on the ecosystem of libraries and tools (which I didn't really consider) that use C, I wasn't even considering that.

hmm apparently I did something wrong since this has been running for 6 hours

it has to close 30 tags for each entry, but it still shouldn't be taking this long

I know C

Any good resources on translating languages? Mainly thinking C++ to other languages (probably lua). They have to be equivalent though.
The reason for this is live code reloading/live code editing. Should I go that route or just put constraints on the project and do DLL reloading?

This is intended to be a teaching tool. I'd prefer to have users write C/C++ (might even make some subset of C++ illegal for political reasons). It's quite an ambitious project. I'm just not sure how to deal with this one detail. It'd be nice to be able to have more code inspection (because it's a teaching tool this is pretty important to be helpful) but I can probably organize stuff in the back end to minimize those issues. I don't want to arbitrarily constrain the user though. Stuff like taking a pointer to a global variable would be problematic with DLL code reloading. But it's solvable. Just not easily. So sorry for being distracted but the tldr is:

Should I translate C++ into Lua for code reloading purposes or deal with the issues you face with DLL live code editing?

you're in over your head; I'd recommend picking up a simpler project

>Get the external behaviour of a program
>Implement it

Have a service that deals with RSS torrents neatly.
Also give labeling options. And sequential/first and last piece first options.

>in over your head
Motivate. Sounds more like you're projecting user. Why is translating code to an intermediate format for ease of use not valid?
I said a lot user. I'm not sure what you're referring to exactly when you say 'external behavior of a program'. What program specifically? The user? That wouldn't be enough.

That seems overcomplicated; base64 encodes a string of bytes so byte ordering doesn't matter. While an application may care, the encoding doesn't.
pastebin.com/9ywRVfzG

Hmm I forgot about RSS, could definitely be something that could say run as a cron with the URLs as the files.

It's one of the reasons I often recommend C as a first language. Aside from the easy syntax, you've got a whole host of stuff you can learn from that makes up all of the software you use on a daily basis. I believe programmers should be encouraged to dig down into shit and find out how it works.

Generally any resource on compiler writing should work... lex, parse, make symbol table, make AST...

Although you're compiling C++, so honestly I'd recommend instead that you look for a good book on how to tie a noose. You may need it.

Well forget that pastebin, I'm too tired to be programming right now.

Figures as much. It's a dirty hack I wrote a while ago originally in C++ anyways.

Welp just finished my own base64 parser as an exercise.
pastebin.com/awcALW3Y

>Although you're compiling C++, so honestly I'd recommend instead that you look for a good book on how to tie a noose. You may need it.
>yfw correctly parsing an AST in C++ is literally undecidable

Speaking of compilers and undecidability, I'm working on a language now with a dependent type system where type terms are literally the same language as expressions (so type checking means running an evaluator). I'm going to see how it works out and if it fails miserably. I'm not entirely sure how type equality is going to work, if I should force function purity, and if evaluation should be lazy or eager (I'm trying to get away with eager).

Java
class Foo {...}
class FooBar extends Foo {...}

@MyAnnotation
void doStuff(Foo foo) {...}

void main() {
FooBar fooBar = new FooBar();
doStuff(fooBar);
}


Can I somehow use annotation processor to check what the declared type of foo param (FooBar in this case) during compile time?
In other words, access information about variable the method was called with.
Currently I check this via reflection in runtime every time method is called.

The whole point of Java subclassing is that types are downcasted and can only be determined at runtime.
You could use overloading instead?

I'm working on a nixie tube clock using a Motorola 68HC11 microcontroller. I've programmed the entire thing in assembly because that's what I'm most comfortable with. I'm a EE major so my programming skills are probably sub par compared to most of you Sup Forumsentooman. Was hoping someone could take a look and tell me what you think. Is it good? Is it shit? Constructive criticism? I know I should have more comments in my code. Threw it together in a hurry.

pastebin.com/YqQZQe4u

I could not churn out 500 lines of assembly, and I'm sure most of Sup Forums couldn't either, shit. Nice job.
Next time try Forth

Thanks. I should add, it's been tested and it functions properly. Never heard of Forth. I'll look into it. Not sure if it will be of any use on that particular microcontroller. I seriously need to brush up on C. Too many other things going on in my life.

In real app things are more complicated and I can't really use overloading.
I still have to use reflection to call different methods from Foo's subclasses. The only alternative I see is to make Foo aware of all its subclasses and add all their methods to it to overload later.
Currently it works just fine, it's lack of compile time checking that makes me uncomfortable.

Hvis du forstår ikke Haskell, må du slå av datamaskinen din akkurat nå.

Nu blir Pajeet arg igen

what would y'all recommend as a good I intro to OO languages?
my mentor is big on FP, and so I only really know Erlang/haskell/racket/etc atm.
I'd really like to branch into more common languages

Scala

>Although you're compiling C++
>tie a noose
Aye. It's not necessarily my compiler really. The intent is to have a teaching platform where a user has basic library functionality that's kinda fun to use (think scratch, except not scratch the language). What I'm building is essentially an IDE but the presentation is entirely different and is intended to have much more knowledge of where the user is. There's very few IDE's that focus on learning. And most don't even have memory presentation as an integral part of the program. I haven't found an IDE which does basic stuff like annotating the memory window with whatever you have in your watch window/autos window. Just doing that would open up a better understanding of software and discourage the problematic view that execution time doesn't matter.

C/C++ doesn't get all these fancy teaching tools. So I want to make a fancy teaching tool. And I have good ideas to make it appealing.
>I know I should have more commends in my code
Yes. Far more comments if you're just gonna throw it at people who don't even have any idea of what you think is wrong with it.
Frankly looks like you're bragging. As misguided as that is.

What language has the best module/library system?

I've made a fuckton of tools but they're all in separate languages and its hard to make them all work together. So I want to recreate this little ecosystem of mine under 1 umbrella.

Amazingly enough, Javascript is the best one I found... But Node's dumb event loop makes the idea of doing any computation silly.

Does Sup Forums know the answer

>What language has the best X
>I gave a fuck about performance
C.

Python and JS, easily

Go

I think you mean C++
He said module/library system is important

I think single-h file libraries are OK.

Tbh senpai I'm not quite sure what he meant by module/library system because it sounds too complicated to belong in any reasonable software.
If that's just what you call the languages import/include/using system I still hold C is better than C++.

C++ uses the same "library system" as C, but now the ABI is unstable.
There is seriously no reason to use C++ over anything.

namespaces

Well if you plan on writing software that tries to remotely decipher C++ code you're going to have a really difficult time.

>intermediate format for ease of use
you don't even know what the fuck you're talking about, let alone how you could possibly accomplish it; picking c++ as your source language to be translated speaks volumes about your inexperience

You get to write my_shit::function instead of my_shit_function. Great.
It's totally worth fucking with the ABI just for that.

IDEs

>There is seriously no reason to use C++ over anything.
Templates, constexpr, RAII, namespaces, lambda expressions, real reference types, and if you really want it, it also supports object oriented programming.

retard

Suggestion: instead of compiling C++ to Lua, compile LLVM bytecode to Lua. That way you can just use Clang to handle the C++ parsing part. As a bonus, you get a Rust to Lua compiler for free.

>it also supports object oriented programming
That is a massive downside though.

Supporting it fucking isn't
It doesn't make you use it

>RAII
When will this meme die? It's pointless and is basically a workaround to avoid exception issues.
>templates
Shitty metaprogramming language. Easily replaced by babbys first meta-programming library attempt.
>reference types
Never got the appeal. Maybe if you had a language with super strict anti-aliasing rules.
>OOP
Sounds rather minor. Really I don't think it's positive as a whole. Sure, it's a typing convenience sometimes.
Well you should avoid people who do. So there's your downside.

It bloats the language

Lua doesn't have goto. Even then you'd end up with REALLY ugly resulting Lua.

You will get fags who write libraries in that style.
Also, extra bloat in a language is a bad thing and leads to thousands of subsets of a language that see use. Just look at C++.

>you should write everything by yourself without using libraries written by third parties
that's the problem with C++: everyone picks a different subset of what they consider reasonable to use

>freedom is bad because other people will do what I don't want them to

Solving the linking problem of C is something no build system I know does well.

As in, I can't build a bunch of libraries forming a tree of dependencies and have any of them build and link all those projects. I can't make a change in a library and then build the project that uses it to observe the effects of that change.

One of my projects is actually a Makefile-based system that does just that: it uses a concept of a "workspace" that I invoke the build system in, telling it which project to build. Projects declare other "projects" they depend on, and they get built to satisfy dependencies. All build artifacts end up in a $workspace_prefix/build/{objects,shared-objects,executables} and it automatically adjusts PATH for executables and dynamic linking; it even supports building in tmpfs

And it's still not good enough.

>Python
Why's it's module system good?

>JS

JS would be my choice were it not for the eventloop of Node.js, which makes programming in general impossible. Any long computation will bottleneck the whole thing. There's a workers pull request on GitHub that will add execution as a form of background I/O, it looks promising but it's "on the TODO list for v7".

Why's it's module system good?

>C++
>libraries

Unstable ABI. Virtually useless language for any application which won't also be built in C++ with the exact same compiler down to the version.

I mean developing a set of functions and data structures, packaging those up as a "module", and then importing those in the applications.

This is because my tools are a natural fit for the libraries. I made some functionality and the one off script that used it was actually quite small. Then I needed that exact functionality in another application... In another language, and it was awkward

it's like you have a mental illness

That's partly the reason I considered limiting the C++ to a subset. I consider it a bad language. It's just the best option right now.
>picking c++
The point is to teach C++. So that's just a given, it's not a choice.
>speaks for your inexperience
C++ shouldn't be taught? Sounds rather opinionated.
>you don't even know what the fuck you're talking about
Well I know that LUA has good (imo) introspective properties. It's interpreted so it allows for a low iteration time which is a major plus.
I haven't looked into LLVM bytecode much.
Though I've reconsidered. It's probably going to be a mess dealing with the LUA if its translated becuase i can't assume a small change in C++ code produces similar LUA all the time. I probably won't support modifying datatypes for instance. If I were using lua directly that would not be hard to do. So I'm probably just gonna lex the C++ and use that to provide the user with the help they need. Shouldn't have been so dismissive of that other guy. It has some obvious issues.
My limited understanding is that the branching can be represented as switch/if statements. But I just know about it from watching this: youtube.com/watch?v=FnGCDLhaxKU

You don't have to use it. It's just there if you want it.

>When will this meme die? It's pointless and is basically a workaround to avoid exception issues.
Even if you completely turn off exceptions, RAII is incredibly useful as a means of resource management.

>Shitty metaprogramming language. Easily replaced by babbys first meta-programming library attempt.
Well considering the alternative in C is just macros, ask yourself this: do you really want to use a macro library to get all of your generic programming done?

>Never got the appeal. Maybe if you had a language with super strict anti-aliasing rules.
You can guarantee a pointer will always point to a valid object.

C++ supports goto. Still want to compile it to Lua?

>You don't have to use it
you're an idiot, but then again you don't even know C, so your opinions are irrelevant anyway
>You can guarantee a pointer will always point to a valid object.
no, you can't

>someone who knows fucking nothing about programming talking about how Ruby knows nothing about C

>That's partly the reason I considered limiting the C++ to a subset
This is definitely a good idea. But you still have a bunch of fucked up things like double templates >> vs shift right, templates in general I guess, and the often cited example
x * y(z);
could mean multiple different things based on context. You could try to iron out these fucked up edge cases or you could just parse C instead...

>My limited understanding is that the branching can be represented as switch/if statements.
This is true but it'll take some deciphering of a format that is suited for somewhat arbitrary jumps. It's like, converting something from english, to chinese, back to english. Or maybe english -> chinese -> spanish. Either way it gets kind of fucked by the intermediate step. Also I don't think Lua has "switch" statements.

>RAII is incredibly useful as a means of resource management.
How come Rust doesn't have full-fledged RAII?
I think that RAII _was_ a good thing way back then, but for example in the program I'm writing, by using smart pointers I'm literally better off by not declaring the deconstructor. Implementing some 4 constructors is absolutely absurd and should not be required of any sane individual trying to write code.

>resource management
What is a resource user?
I've had this discussion for years. Basically when you start asking these questions about what resources are RAII falls apart because it's a concept that has problems at the root.
>You can guarantee a pointer will always point to a valid object.
Pretty sure there's such a thing as reference invalidation.
You can use pointers in the exact same way and have the exact same benefits because it's no different really.
If you want to use references as a way of signifying 'this has been checked as valid'. That's fine. But don't say that it solves anything. It's just a coding convention at that point. Not a language feature. Doing
void foo(int* ptr /*Hey mr programmer, this function should demand of the caller that this pointer is always valid!*/){
/*----*/
}

Has the same effect. Sure, it's fine to have a single symbol for that. But it doesn't guarantee anything.

>If you want to use references as a way of signifying 'this has been checked as valid'. That's fine.
You could literally write code without a type system at all, and just do all of the correctness checking in comments and "in your head", but for some odd reason people don't do that...

I do that. But devils advocate here:
You don't share you head with other people on the project.

I mean I do correctness checking in my head. Not program without a type system at all. Obviously.

Learning my way around Arch. Successfully installed it yesterday as dualboot. Love it

Was in a thread yesterday that asked wheter C was functional or object-oriented, and one poster ( ) wondered if it was possible to do the following in C

let (^) x y = pown y x

let fs = List.map
let f1 = (*) 2
let f2 = (^) 2
let fsf1 = fs f1
let fsf2 = fs f2

printfn "%A" (fsf1 [0; 1; 2; 3])
printfn "%A" (fsf1 [2; 4; 6; 8])
printfn "%A" (fsf2 [0; 1; 2; 3])
printfn "%A" (fsf2 [2; 4; 6; 8])


I've made a solution, and although it has it's limitations, it is pretty generic.

First limitation is of course that you need to manually mind memory, and therefore I pass the output list as an argument to the function instead of allocating and returning it within.

Second limitation is lack of lambdas, I can't declare a function within a function. This is why I had to declare f1, f2 and fs.

Third limitation is that this only works on UNIX machines (tested on OS X and Linux).

Of course, one of the reasons I like C++ over C is templates and what you are able to do real apply functions (instead of hacking it with stdarg or with passing void* pointers around). In C++ you are also able to do operator overloading stuff like boost optional, std::function and std::bind are really handy in addition to state capturing lambdas (closures)

But without further ado, I present my C implementation of the above code :

pastebin.com/0hgT1cxG

>pls no bully

There is nothing wrong with references themselves, but C++ references are the most retarded thing in existence.
void my_fn(int &n)
{
// Mutate n in some way
}
and by calling it:
// Elsewhere
int n = 10;
my_fn(n);
assert(n != 10);
It fucking changes state invisibly. Way to make your programs way fucking harder to reason about.
There is NOTHING syntax wise to suggest that n might change.
When you see something like the C & operator, you know that n could probably change.

If it's not declared const, then you must assume it is going to change.

It doesn't have to change state

and as says, you should assume anything that isn't const is mutated