/dpt/ Daily Programming thread

Not Anime Edition

Other urls found in this thread:

wiki.haskell.org/Frag
github.com/tsgates/cclookup
lud.cc/programming/emacs-cpp-doc/
twitter.com/SFWRedditVideos

>when you want to make your own game engine but you end up writing a GUI library

r8 my stupid shit
void Slider::updateBit() {
if (scroll < 0) // limit leftward scroll movement
scroll = 0;
else if (scroll > bitMaxX) // limit rightward scroll movement
scroll = bitMaxX;
/* Update Values */
if (scroll != bitMaxX) {
value = std::ceil(scroll / bitJump); // round value up because floats to unsigned int
scroll = value * bitJump; // jump scroll to exact value position to make slider "clicky"
}
else // force to max value if bit is fully rightward (fixes rounding issues)
value = maxValue;
bitX = xPos + scroll; // apply actual screen coordinates
}

>not anime edition

so this isn't a dpt


sage

Lisp is the most powerful programming language.

Well most games do have guis. Even many of the ones from the NES days.

>play a game
>get four hours in
>trigger a cut scene right after death
>stuck in a T-pose and can't respawn
>figure re-killing myself will work
>game crashes
>when i load the save it's an instant crash

This is why the games need to be written in functional languages.

it's a bit tougher when you're making a tycoonish game that needs basically a complete widget-set that supports mouse+keyboard.

If I were to do this all over against I'd probably use nanovg.

what is the most anime programming language

Lisp

how to prepare for an embedded programming in C interview?

I didn't know functional languages could handle data corruption.

It's not data corruption, it's invalid state & bad QA

A functional language can't modify data therefore the data can't be corrupted and you'll never be able to save the game

Are you suggesting that functional programming languages can never crash or softlock?

Why OP??

PREVIOUS THREAD:
Stop slacking off.
The double linked list are broken lately

If I'm dead, I'd never be able to trigger the cut-scene, so I'd never get stuck in the invalid state in the first place. Because I'd be handling state properly, instead of what i assume are a bunch of flags.

>going backwards
>not only going forwards

if I use C++ only for the convenience of ability to declare variable anywhere in the code,
should I change to C98?

No just use C++ fuggidaboutit

You'll also never be able to run the game well, and no one will be able to read the monad hell of the source code.

wiki.haskell.org/Frag

I mean look at this beauty. Pure functional programming power.

Actually, user, could you write a monadic program to draw a rotating cube for us please? Opengl 3.3+ please. No fixed function pipeline for you.

>implying I'd be using Haskell

In c++, I want to store a bunch of names into an array

then I want another function to display these names in a 2D table with 3 columns and x rows that depend on how many names are in the array

How would I even start doing this? It seems really complicated

>look at source code
>see this
fucking dropped.

Do people actually use Go? Is it any good, or fun to code in?

you'd create a 2D string array and print it out with a for loop in a for loop.

if you need it to be dynamic you can use a vector of string arrays.

it's super simple.

is asking someone to write a simple json parser from scratch a fair interview question?

I took a compilers course like everyone else but how the fuck am I supposed to remember that years later?

Use a single-dimensional array. When you pretty-print it, use a nested for-loop: the outer one iterates by threes, the inner one iterates over those. Faster and less convoluted than the multi-dimensional (e.g. array of arrays) approach.

Yeah I think so. It's not like you need any of those parsing algorithms you studied in compilers. You can totally ad-hoc that one.

>How would I even start doing this?
By making an array that stores a bunch of names. Then you'd make a function that displays those names in a 2D table.

But seriously, you'd use a loop inside a loop like said in First loop goes through each name (creating the rows of the table)
Second loop adds the stuff for the column of that name

So what would you be using?

ml

code for quads
#include
#include
#include

struct Column {
Column(const std::string &_row1, const std::string &_row2, const std::string &_row3):
row1(_row1),
row2(_row2),
row3(_row3) {}
std::string row1;
std::string row2;
std::string row3;
};

int main() {
std::vector rows;
rows.emplace_back("whatever", "yes", "no");
rows.emplace_back("ditto", "x", "");
rows.emplace_back("another", "test", "null");
rows.emplace_back("whatever", "word", "cuck");
for (const auto &row : rows) {
std::cout

yea, I was able to ad hoc a recursive descent parser after being reminded how to do it. just seems like a bullshit interview question. I even like programming languages and have experience writing grammars and shit but didn't remember shit about implementing parsers.

bit manipulation, threading, low level implementation shit like kernel features, obscure c features like volatile, literally everything in the job description

D

sorry, row1/2/3 should be named column1/2/3. Variable name is misleading.

not functional

We studied it in a functional languages class. Really? That would suck if it's true. Why not? Is it "applicative?"

It's not functional because some very important pieces (IO) break referential transparency.

Just because it has functions doesn't mean it's functional. If you wanted, you could do functional programming in C. But you'd never be able to write to the screen.

How about if I made a small C preprocessor which required you to annotate side effects on a per-function basis and forced these annotations to propagate all the way up to the main?

who here is /UTF-8/ source code?

C++ is an expressive language.

It's never came to my mind, to use reference object in for-range loop
for(const auto & ob : list)


whenever I use for range loop, I noticed sometimes the RAM usage jump because creating the ob object,
and ends up using the standard iterator methode:
for(auto ob = list.begin(); ob != list.end(); std::advance(ob, 1))

iterates look ugly to me. const auto reference seems to be a popular way to do object range loops when I was learning, makes sense to me. Also it stops the destructor from getting called which actually was an issue for me at one point.

Currently working on a genetic algorithm to find the 'best' strategy in a iterated prisoners dilemma.
Ive set up a bunch of randomized strategies (bitstrings of defect / cooperate - CCDDCD etc) to face off against one another. The ones that end up with a high score (fitness) will progress to next generation within their children.
Anyone have any ideas on how to create a strategy for the IPD based off the end results of the GA?
The end result being about 200 'fit' strategies. How can I use these strategies as a look up table for my new strategy?
Hope ive explained myself ok... Programming this in Python with the intended use of implementing through Axelrod package.

Does it look really stupid if my projects on github get rewritten entirely a few times over the course of dozens of pushes? This one project in particular got rewritten twice, in increments, starting around commit #100 and finishing around #150. Am I just not planning enough?

Who cares?
If your project is improving that's all that matters.
I refactor whole modules dozens of times until im satisfied.

I am working on a game and finishing up my UI, all that is left is to implement are these things. This looks to me like a paginated listbox, so I started out trying to make something similar to a winform listbox. Thing is, I don't understand MVVM at all. Is it as simple as giving my Item class a public Control ToListItem() implementation and then refreshing the list items every time an item is added, removed or updated to the player's inventory?
Is there a better alternative to listbox that I'm not aware of?
I know this feel

>tfw my only project on GitHub is a Pac-Man clone
>tfw should probably do something highbrow because I'm trying to get into grad school but I enjoy making games
>tfw brainlet

you feel like rick deckard?

You can do highbrow game stuff. What about an artificial intelligence engine that you can plug into games for testing? That's fun to make but still "sophisticated"

All I did this month is a file renamer script and a web crawler. What's the point?

he feels like raping robots

how to make a for range loop in c++ exit prematurely at a certain condition??
what i meant is this kind of code
for(auto i = v.begin(); (i !=v.end()) && ((*i).is_legal()); std::advance(i, 1))

break

other than that.
break; is ugly and hard to do in a nested loop.

it's better using goto than break;

>break; is ugly
Well ending a loop prematurely is bad design anyway. Re think how you want to do things.

I write a lot of loops that look like:
for (;;) {
// do things
if (x) break;
// do more things
if (y) break;
}
But it's expensive to do lots of checks like this, obviously.

Is this true?
Where can i find an explanation of why?

It's not logical.
Think about if assembly lines in factories were designed to be stopped and started to get something in an arbitrary state. You should design all your code to be absolute.

I design my code so it uses the least ram and processing according to my machine.

fuck imagining assembly lines, what a waste of time.

Trying out Rust. Borrowing and lifetimes make sense to me, not sure why they're controversial.

Thinking in good design will correlate in good performance. And you won't have to debug and refactor shitty ad-hoc solutions every month.

Takes time to get used to. The strict move/ownership semantics of Rust actually makes the perfect sense. But at the same time, careful what you wish for.

Do you code?
the idea that breaking loops "early" as in not through the for/while parameter is crazy.
how would you recommend organizing a loop with multiple multiple different break parameters that depend on the last check getting ran first.

the only way i can think of organizing
according to you is:
// do things
while (!x) {
// do more things
if (y) break;
// do things
}


which is 10x as retarded.

please shed light on my ineptitude.

what are x,y,things,more things, and things1?

>Do you code?
ill take that as a no.
Clearly you dont even pesudo-code.

So please stop giving out advice.

>expecting decent advice on pseudo code with 0 references
You seem to be suffering from chronic brainletitis &/ pajeetism, lad.

in all honesty, it doesn't look that bad. pretty readable for Haskell and the project isn't super huge. if you want to see crazy Haskell code look at some type class hell.

How do I embedded sepples?

>embedded
almost meaningless in this context
look at the documentation for the specific hardware you're targeting and make a simple project that tests the hardware's capabilities
chances are someone else has already done a simple project like this for whatever device you want to run on, so use google

Hey friends.
I tend to look up documentation for C library functions rather often using man pages
M-x man [RET] [RET]

I want to get back into C++ (technical interview soon), and was wondering if there's anything similar to to man pages for C++.

I read about these plugins, but am not sure how good they are:
github.com/tsgates/cclookup
lud.cc/programming/emacs-cpp-doc/
Thoughts?

>Try to install Visual Studio 2017
>Select E drive for installation
>90% of the files still need to go on the C drive
>C drive is an SSD and doesn't have enough room
REEEEEEEEEEEEEE!

>what is IO monad
>what is State monad
>what are monad transformers like StateT

how fast would ytdl be if it was in C

I didn't actually really look at the source code desu. It looks like he's using a very neat DSL for most of the state to avoid monad hell, so I'll have to take a look at it later.

It was more shitposting about how that's the most sophisticated haskell game I could find and it's a bad quake clone with worse graphics than a late 90s game and no AI.

functional languages may make it easier to reason about what the state of your program is at any given time, but they will not save it from getting stuck in a bad state, the programmer still needs to make an effort to not write bugs in the program's logic, doing this is literally what programming is

you don't even need monads for state
{state | field = new_field}

It is significantly harder to get invalid state in functional programming.

I wish I could see the coolest software in our universe
I bet there are some aliens with some seriously kickass software

>Bawwww this experimental game written by one guy 12 years ago as an undergrad thesis doesn't live up to muh modern FPS games

stupid wincuck

Gee, why would I program in the OS that the software is intended for?

...

Fucking peel, you have OS layer, peel, VBox, peel, TEXT PROCESSOR peel. what's so ununderstendable about that? There is nothing like that. Once you do INTERFACE you do it in INTERFACE langluage and it works on EVERY platfrom.

except it's not, even if you incorrectly set a flag somewhere using it, the compiler isn't going to magically detect that you did that, you still need to manually add checks somewhere in your program to make sure that the flags aren't in a bad state

Not him, but think of it this way: if you can calculate the end ahead of time you can possibly get better optimized code because you aren't constantly checking to see if you need to do something differently.

It's usually cheaper to calculate the end ahead of time than constantly checking "if y" or having it in the for loop itself. Every branch is expensive and you want to have as few as possible.

Split your code into two loops early and only work on that one if at all possible.

That's ALL there is user. Haskell will never be practical for gaems. Prove me wrong by writing something decent.

Also that guy may have been undergrad but he's clearly an autistic haskell wizard judging by how poorly written his paper is.

Have you actually done FP beyond hello world?

>the compiler isn't going to magically detect that you
And also, that's actually false in languages like Idris if you make a state machine.

>Haskell will never be practical for gaems.

I don't think you understand what goes into making a good product. Reminder that if you're older than 25 then the majority of games you grew up playing were likely written in assembly

>Prove me wrong by writing something decent.

Okay, get me a couple million dollars so I can hire a bunch of developers, artists, project managers, marketers, HR, accountants, lawyers, etc

You don't need to have a couple million dollars to make something decent faggot.

The best selling game ever was made in the last 10 years by one dude in some basement in a faggot country in Europe.

yes, putting your flags in a bad state is a logic bug, the compiler will never ever be able to detect those because it doesn't know what they mean

except if the state machine runs at runtime and not at compile time then no, it won't help at all

>except if the state machine runs at runtime and not at compile time then no, it won't help at all
That's the thing. It won't even compile with invalid state. Because the states are statically checked.

It should also be noted he wrote the game in Java, and the performance was (and still is) terrible.

Give the task of creating a vector trace of an image, tracing all the pixels that have alpha, how would you find the the pixels to start your trace from?

Exception, not the rule, the majority of games you see on a store shelf are not like that. They are made by normal people with jobs.

Pretty sure Tetris sold more copies.

>how would you find the the pixels to start your trace from?
map and filter

>magical static checking
If they are then all you've done is encode logic in the types. And type bugs are possible, especially in miranda based languages.

Because as it turns out you have to write types, and anything you write is a vector for bugs.

Even then a reasonable game is not one state machine but possibly hundreds of concurrent state machines. So good luck entrusting ensuring that the overall picture is coherent to the compiler.

But unlike the haskell game, it can't run on a 586 when rewritten in C.