/dpt/ - Daily Programming Thread

Old thread: What are you working on Sup Forums?

Other urls found in this thread:

tomasp.net/academic/papers/joinads/joinads.pdf
tomasp.net/blog/fsharp-variations-joinads.aspx/
microsoft.com/en-us/research/project/the-f-project/
youtube.com/watch?v=YQs6IC-vgmo
youtube.com/watch?v=9BVq4JqEFZY
github.com/ocornut/imgui
fstar-lang.org/
fstar-lang.org/papers/mumon/
regexcrossword.com/
twitter.com/NSFWRedditGif

Rewritting the GNU + Linux kernel in Haskell; minus the Poettering parts

Trying my hand at Gameboy programming.

>doing X platform programming
>wrapping X platform and doing what you usually do
What do you aim to do?

succesfully wrote a graphics driver and memory manager for Gnu Turd, going to write the first game where you are an indian running from evil poos and you gotta trick them into falling into a loo

What is the best algorithm for sorting a doubly linked list, gee? Someone asked me days ago. I have my humble opinion but I want yours.

Eventually plan on doing a roguelike or some shit on it. Also, getting bank switching set up on this bitch is a pain in the neck. Documentation is shit for gbdk, and everybody's hosting their own fucking forks on github because the developer basically gave up.

>sorting a doubly linked list
>linked list
>sorting
>using a linked list
>any year
I don't have an opinion on it. If I ever need to sort it I don't make it a linked list. (or the structure I'm using is sorted by sorting references to the list)

>sorting references to the list
Wut? How is that better and what does that even mean?

merge sort

Reverse engineering some shit.

It's not 'better' as a linked-list per-se. But it's more about wrapping the linked list in a non-linked structure because it's better.
What I mean is to just an array of node pointers. When sorting I'd just dereference the node and sort the node pointers array based on the value in the node it's referencing. When inserting a new node i'd have to make a judgement call if the amount of nodes being inserted between each sort is big or not. If not I'd just keep a small 'unsorted nodes' array that's checked after a search is done.

Yes it's a clunky system but I'm certain it's more efficient and easier to handle (while doing sorts). But that's just because linked lists are absolutely retarded. There's no sensible reason to use them.

If you have a linked list you should have a binary tree or any tree really instead.

>There's no sensible reason to use them.
Sounds like you're absolutely retarded.

Which programming language should I start with?
**I don't like compiled languages; takes too much time**

mongojs

Same yet different question, I script in ruby, should I get good with c++ or java?

>I don't have an opinion on it
because you don't have algorithms knowledge
>If I ever need to sort it I don't make it a linked list
yeah, too complicated for your css brain
>we have this linked list because it's the most efficient way to handle the most common use case
>in some rare occasions, we need to sort it; how would you do it, pajeet?
>lel, I just make an array and work with that, linked lists are too hard for me
you are the shit of Sup Forums

Riding off this question, if I wanted to learn programming to better understand computers and maybe pick up programming old systems for fun as a hobby, would C be the correct starting point? What's considered the best resource for C? I'm reading Learn C The Hard Way but I've seen some people say it's shit, it seems like the author made a lot of people upset talking smack about a book that was held in high regard so I don't know how legitimate those claims are or if it's just asshurt.

>author made a lot of people upset talking smack about a book
actually, he doesn't know what the fuck he's talking about, because he doesn't actually know C (by his own admission), he just looked over it with the purpose of writing a book

I read this post and thought "wow, the MtFs are all programmers meme is true" then noticed I clicked the wrong tab.

bump

C++. Make native extensions for Ruby.

Go. It compiles as fast as most interpreters take to start.

Can someone tell me what color scheme this is?

Working on a tool for beginning computer science student using g++ for c++. The tool will simplify compiler errors so g++ doesn't throw an 800 line error when the > are the wrong way on I/O.The scope is not limited to just I/O errors, it'll cover about 90-100 beginner C++ mistakes.

californian dildo

Why?

Also, when is the dependent type revolution finally starting. I'm waiting.

t. theoretical physicist

It's not going to happen. Just like how the monad revolution did not happen.

Scala is going to revolutionize effects in the next 10 years, so watch out.

python

ok so F* (fstar, verified language) has dependent types and you can execute it by generating it into F#/Ocaml

no idea how it would look however

if you're going to be using meme languages why not just use idris?

So... Gameboy shit...

Memory partitioned into 2 32K "banks" for program ROM, 8K of RAM. First 32K bank is untouchable, second 32K bank can be swapped in and out, and will likely be needed for sprites, music, and other game code. A function in the second bank can't do the logic of the switching, because otherwise it would end up stuck somewhere in the middle of a function in another code bank, and glitch everything up. Thus, first bank acts like a very small kernel managing everybody else. And it's a kernel that has to fit in 32,768 bytes, some of which may need to be reserved for displaying the Gameboy logo upon bootup if it is to be transferred onto a flash cart for real play (yeah, real Gameboys check for a sequence of code that displays their logo)

Are there any resources on how to implement different image segmentation algorithms? Have to do that stuff for class and right now I'm failing to implement a quad tree.

Wait, woops. Meant 16K banks. Entire address space for the two banks is 32K.

performance?
and you have Refinement Types as well

How do we unify nominative and structural subtyping?

>when is the dependent type revolution finally starting
The fire rises, brother.

F* is not verified.

Idris has an LLVM backend.

>not using joinads
tomasp.net/academic/papers/joinads/joinads.pdf
tomasp.net/blog/fsharp-variations-joinads.aspx/

>Abstract.
>Modern challenges led to a design of a wide range of programming models for reactive, parallel and concurrent programming, but these are often difficult to encode in general purpose languages. We present an abstract type of computations called joinads together with a syntactic language extension that aims to make it easier to use joinads in modern functional languages.

>Our extension generalizes pattern matching to work on abstract computations. It keeps a familiar syntax and semantics of pattern matching making it easy to reason about code, even in a non-standard programming model. We demonstrate our extension using three important programming models – a reactive model based on events; a concurrent model based on join calculus and a parallel model using futures. All three models are implemented as libraries that benefit from our syntactic extension. This makes them easier to use and also opens space for exploring new useful programming models.

>F* is a verification-oriented dialect of ML
microsoft.com/en-us/research/project/the-f-project/

Wasn't this ages ago?

it's still only an extension

>Don Syme commented · February 04, 2016 02:53
>I think my position on joinads is fairly well known. The proposal is most definitely interesting from a research language design perspective.

>However the typical "bang for buck" tradeoff analysis just doesn't convince me that this should be in F# itself.

>F#
>still no HKT

Ok where does a linked list perform (memory/processing power or both) well?
Is there any situation where you'd have better performance than an array, dynamic array or C++ vector?
Any situation where it's better than a tree?
>trees need balancing
Not all trees _need_ balancing. And note how a linked list is just a worst case of a tree.

Sounds like you're absolutely retarded frankly.
>linked lists are too hard
No. They're really easy. Sorting them works on the same principles an array can be sorted. The difference is that you have two different types of sorts. Sorts that sort the nodes and sorts that sort the values/data.

Either way it's just about inserting the nodes or swapping values.
Also note how nobody else answered.
>You don't have algorithms knowledge
I have no idea how anyone can say that when I'm making such an obviously true statement.
The reason I technically don't have an opinion on it is obviously not because I don't know what it is. If you have enough values that you need to sort them in a performant way you don't use a linked list. It's as simple as that. If you're sorting your ~1000 node linked lists and wondering about what the best algorithm for sorting it is you're being retarded. Either it's premature optimization or it's simply you being retarded. Don't do bubble sort. But for something that small you can do insertion sort.

Also here's why linked lists are bad:
youtube.com/watch?v=YQs6IC-vgmo
Even this moron gets it.

I hate when morons like you make a mockery out of the field by pretending that programming is comptuer science.

That doesn't mean at all it's verified.
Coq, Isabelle, Mizar and dozens other languages are "verification-oriented", but themselves they do not have formally certified/verified implementations.

youtube.com/watch?v=9BVq4JqEFZY
github.com/ocornut/imgui

>where does a linked list perform
where you need lots of inserts and removes without invalidating iterators; I'm not surprised you don't know, obviously you lack experience and high performance applications are clearly not something you've ever had to deal with
>an obviously true statement
nah, you're just a retard that thinks he's now good because he did fizzbuzz
>If you have enough values that you need to sort them in a performant way
the question was how to sort a linked list, you dodging the answer shows that you don't have algorithms knowledge
>It's as simple as that
this is proof you haven't gotten past fizzbuzz-level programming; protip: real applications are more complex than "ok, now we need to sort stuff! let's just use an array and call it a day; doesn't matter if we only sort rarely compared to insert/remove, rajesh here only knows how to sort arrays"; only morons rush "simple as that"
>Also here's why linked lists are bad
if course, retards like you can only get knowledge from stackoverflow and youtube, you're incapable of critical thinking to even ponder why the fuck lists even exist if """everyone says they're bad"""; did it occur to you that most of the "lists are bad" cargo-cultists don't have a clue what the fuck they're talking about and base their conclusions on retarded use cases where they shouldn't have used a linked list in the first place? of course not, you don't have a brain to question """youtube proofs"""! fuck off
>make a mockery out of the field
you don't even get close to the field, you shit; go on with your html programming, worthless fuck, and don't bother replying, I'm not wasting any more time with sub-humans like you

In C++, what's the best way to distinguish variable name from method name?

m_NAME
a_NAME
_NAME
others?

>The latest version of F* is written entirely in F*
fstar-lang.org/

Don't, it's retarded

If I git gud at C, how transferable are my skills?

I don't see a point since you need parenthesis to use a method. I do differentiate structures and classes by making them start uppercased though.

I know it's retarded but I don't have a choice.
I have a class that has a variable called id, and I have a method also called id which returns id, but that won't compile because C++ can't differentiate between a method and a variable with the same name.
So the variable has to be called something else.

>where you need lots of inserts and removes without invalidating iterators
Everyone gets this one wrong.
youtube.com/watch?v=YQs6IC-vgmo
You're retarded.
>retards like you can only get knowledge from stackoverflow and youtube
No I generally read shit. I posted that because it's plainly obvious to anyone who knows anything about computers and the only kind of person who wouldn't know this already is someone who I'd rather see executed than be forced to work with. Yes, you know the things we actually use to run software. A linked list is a long list of cache misses. That's why it sucks ass. And it always will. A vector wins in performance down to the single element array. Arguably that extreme case is because the single node has two pointers and will evict something from the cache for no reason. I suppose I can concede they're the same if all our program does is access the node/array.
m_ is pretty good. But I tend to use that for member rather than method. Not that it really matters.
>best way
Whatever helps you type quickly. Prefixes are good because most people use tab/whatever-completion.
This guy makes a sensible choice and uses a lexer for his editor but is strongly opinionated against people who don't. For no real reason I think.
>git good at C
Depends on what you mean. Knowing C as a language (just syntax and how to write basic programs) isn't really much to learn, but it's pretty much the basics of programming and . Learning C like a language autist is a lot of work and gives you very little. You understand programming better knowing C.
Compile errors for no reason is the problem. I takes more time than correcting it the first time you wrote it.
>I have conflicting names in my struct/classes
Not a good reason to decide on something.
I think your three suggestions are all equally fine. a_ and m_ are descriptive and if you have an editor which lists members for you it's convenient too.

Why the fuck would you have both?

Even if you wanted to prevent someone from externally modifying id, since it's internal why does it need to be called id?

3rd in not allowed
call it ident, identity, the_identity, whatever the fuck

It seems like want to know more about computer organization. try an introductory book like Code, by Charles Petzold. If you want something more comprehensive, read Computer Organization by David Patterson. And John Hennesy.

Again, that doesn't mean it's verified. The F* type system is not even strong enough to provide such guarantees as soundness and completeness.

How come when I make statements like this I get tons of complaints?
There's technically no compiled languages. You can write a C interpreter. But I'm not retarded so I wouldn't tell you that as an answer.

Also, straight from the authors:
>F* is programmed (but not verified) in F*
fstar-lang.org/papers/mumon/

>Everyone gets this one wrong.
What are you referring to? First, the linked video has nothing to do with the quote. Second, it's a complete strawman: "Here's a scenario where nobody with half a brain would think to use a linked list; Guess which one is faster: the linked list or the array?" That's not how reasonable people use linked lists.
>A linked list is a long list of cache misses
Only if you use them when you shouldn't. There is no one absolute data structure perfectly fit for all use cases. Trying to shoehorn everything in arrays (because of unfounded cache concerns) is not always optimal.
>A vector wins in performance
Depends on the use case.

Which language is best first language: Java, C, or Python? I've heard Python teaches bad habits you need to unlearn.

If I have this string:
"the price is 40.45,02 shekels"

How would I write a regex to pull only "40.45,02 shekels"?

Is there a way to calculate the time window between two dates with respect to leap years WITHOUT checking every year in a loop if it's a leap year or not? I don't want to pre-calculate a 9999 long array and sieve through it, bros.

How to make my algorithm more efficient?

Forgot to say, the amount of . or , in the number is unknown.

>Only if you use them when you shouldn't.
>Depends on the use case.
Except the video I linked showed you the opposite. The video is literally a "find where to insert the value" (linear search) "insert the value". For a linked list that's walk all the nodes (hit a cache miss every time you look at a value until you find the correct one) and insert (change pointers). VS linear search on an array (super likely no cache-misses because computers are awesome) and insert the value (shift all values forwards 1 and insert the value).

That's what he was talking about. I'm not gonna find a paper on it for you because it's OBVIOUS. It's been known since way before that Cppcon talk. If you're so retarded that you trust your professors to know jack shit about computers then you should probably just off yourself rather than getting more debt that you will leech from your parents (if you're lucky) or country (bums cost money).

I don't see a use-case where a linked list would be better. They've isolated themselves in ways that make implicit data-usage (stuff like sampling every N bit in an array having some significance) impossible. They're useless. You'd write them only if you don't have a dynamic array type in your language and you don't really feel like implementing it. And you don't care about performance. Or maybe if you want it to be slow. Which I don't get, just do a few sleeps here and there while using a vector instead. Wasting CPU time is just cruel.

>I've heard Python teaches bad habits you need to unlearn.
Retarded people say that. It's the 'no braces/nosemicolons' meme. It takes you maybe a week.
I'd recommend C though.

\d*\.\d*\,\d* shekels

>coding anything date related yourself

Have fun going insane.

can you explain this regex, please?

>How to make my algorithm more efficient?
Post it?
I hope that's not what you described.
You figure out how leap years are determined. Determine how many leap years there are in the interval you have, add that many days. Do your normal time difference.
>doing dates
>attempting to do them correctly
Don't do this.
[\d\.\,]+ shekels

Yes. I escape things arbitrarily in regex because I'm sick of errors.
>but you're now accepting \ in certain implementations
I don't care.

It's just an exercise bro.

Checking to see if a year is a leap year is easy. How to efficiently get the total amount of leap years within a time window is exactly what my original question was about. Any tips? Because right now I'm doing +4 every iteration and checking iteratively.

Just copy it into regexr.com 3dmkh

\d = digit
* = zero or more
\. = escaped period
\, = escaped comma
shekels = literal string

post your algorithm already dude

Apparently you don't need to escape a comma. Still works tho

i prefer regex101.com , though. thanks
thanks

Well limit the amount of iterations by something. I don't know leapyears well so I can't optimize the algorithm. But they only happen every 4 years OR some other set of years (like every 19 years iirc?).
So just do for(int i=0;iregex101
Nice site.
>thanks
His doesn't work according to spec though. It only handles 1 period and one comma

could you write it like this?
[0-9]*\.[0-9]*\,\d* shekels

Which one is best for a beginner to learn?

I think a more appropriate regex is
\d{1,2}(\.\d{2})*,\d{2} shekels
assuming that I'm interpreting the question correctly.

Practically the same, you could do [0-9]*\.[0-9]*,[0-9]* shekels as well

>Which one is best for a beginner to learn?
I don't know. I haven't learned all of them as my first language.
Only C.
I can say that Java was really bad for beginners I've known.
Yes. But I don't see why you would use both [0-9] and \d in the same regex. \d is 0-9
What I posted here
>[\d\.\,]+ shekels
Does exactly what you said
It catches:
32,.98,.328,.,.,..2,32,. shekles
329.,8328,.,.,..2,32,. shekles
and more sensible things like
343.343,32 shekles

But maybe you want it more constrained despite what you said..
It's very simple.
[\d\.\,] //character set of 0-9 . and ,
+ matches as few as possible of the characterset while trying to match (match until there's a space in this case, if there's something other than space it just doesn't match)

CodeEval fuckery.
#include
#include

int main (int argc, char **argv) {
FILE *fp = fopen(argv[1], "r");
char card[21] = {0};
char squash[16] = {0};
int sum = 0;

while (fgets(card, sizeof(card), fp)) {
int idx = 0;
int i;

for (i=0; i

How similar is Python and C? I'm thinking about getting the basics with Python and move on to C.

Besides the fact that they're both imperative languages, they aren't similar at all.

They're not very similar. I wouldn't want to discourage you from learning python first. But I suspect you may feel C is a bit annoying to deal with after python. Without understanding why it is that way. If you go the other way you get that python is convenient but slower.

Also Python supports OOP. Which I find is dangerous for newbies. But that's political.

Go with either, just do at least an hour of programming today.

I've been meaning to do some CodeEval challenges again.

for (i=0; i

Less readable.

Boss is away and I'm hungover so I figured I'd do some.

for (i = 0; i < 16; i++)
sum += (squash[i] - [0]) * ((i & 1) + 1);

Wait, I got that backwards.
for (i = 0; i < 16; i++)
sum += (squash[i] - [0]) * ((i % 2 == 0) + 1);

>less readable
>compared to
user you're not just hungover. Get to the hospital.

>the price is 40.45,02 shekels
#!/usr/bin/perl
my $str = "the price is 40.45,02 shekels";
print $1 if ($str =~ /(\d+\.\d+,\d+ shekels)/);

>Less readable.
can't you read what's in there?

for (i = 0; i < 16; i++)
sum += (squash[i] - [0]) * ( !(i&1) + 1);

I said less readable, not unreadable.

I realised another error in my code.
[0] is supposed to be '0'.

There was a guy here a while ago doing challenges with regex, does anyone remember the site he was using?

Might have been me actually.
www.hackerrank.com

Just found it actually
regexcrossword.com/

Are you fucking 12. Try something for complex mate.

Calling yourself a programming would imply you can even read a book built for adults.