/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: yuki3.png (500x492, 350K)

Other urls found in this thread:

gameprogrammingpatterns.com/contents.html
youtube.com/watch?v=KkMDCCdjyW8
stanford.edu/class/archive/cs/cs106b/cs106b.1158/lecture-videos.shtml
twitter.com/NSFWRedditVideo

first for nothing

Second for C

Attached: 1547506211203.png (1920x1080, 1.84M)

Have you got your copy yet, /dpt/?

Attached: Code_Ahead.jpg (1200x840, 109K)

seconding this

(fourth (for (common lisp)))

Five for godot

Attached: icon.png (64x64, 3K)

sixth for sextants

Attached: Sextant.jpg (1044x1386, 624K)

Employed Haskell programmer reporting in

Attached: 1524823550282.jpg (1280x720, 66K)

>come up with a unique CS concept or program idea, at least as far as coming up with it myself and never having encountered it before
>search it up and it's already been done in multiple languages and multiple implementations
What's the goddamn point? I swear, when contemplating how to efficiently lookup items in an array, I once came up with the general idea for a hash table on my own before even learning about such data structures. Of course 1 minute later I realized this was a standardized CS concept and felt silly for not already knowing it.

Employed Ada programmer reporting in

i know how you feel
difficult to come up with something new and original

are they succesful and well established in your area? If not, then dont worry. You still have a chance.

if you want to do something new you need to dive deep, stumbling across something simple and new is one in a million

>tfw im going to get kicked out of my cs phd program for doing fuck all because of depression
>tfw im unemployable because im a sperg who fails every programming interview
>tfw i made a popular open source library on github but got no donations from it so i cant support myself with it
>tfw im going to disappoint the handful of people who supported me
failure reporting in

>>tfw i made a popular open source library on github but got no donations
freetards on suicide watch

Rust demiagender programmer reporting in

>tfw born too late to be part of the CS/Programming boom of the 1940s-1970s
>tfw born too early to pioneer affordable quantum computers

born just in time to code in java and c++ though

Attached: 1528344315612.jpg (1024x768, 149K)

>born too early to pioneer affordable quantum computers
What do you mean?
IBM has just begun to sell the first commercial quantum computers and they're certainly hiring.

>tfw born too late to be part of the early days of Ada where the DoD was pouring billions into stupid shit involving it.

Rust*
fixed

I swear there is one guy here completely obsessed with Ada and nobody else cares in the slightest

>IBM isn’t making its quantum computer available to buy but rather to access over the internet.
So it's basically mainframe years all over again where you have to be in the special club to be invited? I wouldn't qualify this as affordable.

no, what do YOU mean
they haven't 'just begun to sell' they have a device that supports 8 qbits or some shit

there is nothing wrong with liking a language

Attached: ada-strong-1120-grey.png (1120x1120, 145K)

So I want to use macros in C, and I have a use case where no other solution will work as well in the code base. They aren't nasty macros, they are to do some compile time manipulation of strings used in the program. If it was C++ I would use constexpr but whatever.

Are there ways I can place a limit on valid arguments to a macro? Say I want to limit argument x of my macro to only accept int's < 100? So if you pass x to the macro > 100 it'll error at compile time?

by all means, you just don't need to force it upon everyone else

Use a function and inline it.

Nothing
Don't have any ideas
Last time I worked on anything was August last year

Attached: 9s5y5uc71c521.jpg (2172x3000, 727K)

looks verbose as shit
literally verbose, uses too many actual words

I don't want inline functions though. I don't want any function calls at all. I want the strings setup correctly at compile time.

Use an inline function, and use a wrapper macro to faff with the arguments if you need to.

am i not allowed to talk about my language like the rest of you do? ada posts make up probably less than 5 posts on average in /dpt/.

it's just you talking to yourself
take a hint

just fucking make a sexual rpg with some text and images

your bullying will not limit me. i dont beg people to use the language i simply make statements about it which are perfectly fine in a thread about programming. not everything has to be about c, c++, and java.

I'm not bullying you I'm telling you to stop being obnoxious because nobody cares

just because you dont care doesn't mean no one cares. go be a jerk somewhere else.

I'm sure one day you'll find that person

How are you all enjoying Rust 1.32.0? It's been a few days to test out everything new. Getting rid of jemalloc by default is a huge plus for the language since it was holding it bad on several small platforms. This is turning out to be a real winner when it comes to replacing C. No ISO committee circlejerking and holding it back based on corporate interests in the board members. Just pure passion for making a good safe language and not being afaid to keep it up to date.

Attached: .png (648x454, 115K)

awww the nerds are flirting

first for my programmer gf

Attached: __clerk_nagato_and_nagato_yuki_lucky_star_and_suzumiya_haruhi_no_yuuutsu_drawn_by_core_mayomayo__e84 (538x600, 118K)

You can do stuff like
#define TEST 150

#if TEST >= 100
#pragma message ("TEST >= 100")
#pragma message ("Compilation will now halt.")
#error
#endif


(Check your platform for the correct directives for preprocessor messages and halting compilation).

>limit argument x of my macro to only accept int's < 100
Just be aware that TEST has no real type, it just expands to the literal 150.

I have a macro MY_MACRO(x)
I want to check that the values for x are fulfill some constraint. Is there a way to do this at compile time?

No. Preprocessor is not a language. What you want is a macro system akin to Lisps or Rust and so forth where it is itself a programming language that outputs target language code.

Is this code valid yet?
fn my_func(_a: &mut i32, _b: &mut i32) {
}

fn main() {
let mut array = [1, 2];
my_func(&mut array[0], &mut array[1]);
}
I'm not interested in you shitty meme-lang when it fails to do basic shit like this.

Attached: 1545439289095.jpg (681x635, 116K)

Make an array[100] somewhere
Subscript array[X] in your macro(X) prior to any other expansion
Compilers will warn about out-of-bounds subscripts

Use a _Static_assert.
It's not easy to work into every macro though, as it counts as a statement.

Why would you do that when you can do:
fn my_func(_arr: &mut [i32], _a: i32, _b: i32) {

}

fn main() {
let mut array = [1, 2];
my_func(&mut array, 0, 1);
}


The borrower is preventing your use case because it's ultimately not safe or good code, sorry buddy. Bad C code isn't allowed in Rust.

That's not the point, idiot. Why can't a pass two mutable references (or one mutable, one not) to a function when they're both clearly different integers?
It may be a library function for all I know.

Preprocessor directives only expand once, so after the macro expansion is done, you can't do that on the preprocessor level. However, you can do that with static assertions.


#define INDIRECT_INT(x) #x
#define STRINGIFY(x) INDIRECT_INT(x)

#define MAX_VAL 100

#define MY_MACRO(x) \
static_assert( (x

To some degree, yes:
struct limits { //up to 5 as example
int v0:1;
int v1:1;
int v2:1;
int v3:1;
int v4:1;
int v5:1;
};

static struct limits limits = {0};

#define limit_n(N) limits.v##N = 1

int main()
{
limit_n(2); //ok
limit_n(6); //error
}

It breaks invariants in the language and optimizations. The problem is not the two different integers you borrowed. It's that you borrowed two integers from the same mutable vector. You now present the danger down the line in the call that you could be modifying that vector concurrently. Yes, this is regardless of whether or not your application is single threaded or not. If you must do this and know it is safe with your code written then call it in an unsafe block.

Thanks this is the best option here.
Also why isn't there some kind of constexpr string in C++ yet? I'd love to do this without macros but as far as I can tell there is no good way to do constexpr strings in C++.

For starters, it's not a vector: it's an array. Its size and allocation is fixed. That is not an issue.
Multiple threads modifying different members makes no fucking difference.
>It breaks invariants in the language and optimizations
False positives are far worse than false negatives. Good job designing an unusable piece of shit.
I don't understand how a sane person could defend something as simple as this.

What do you mean by constexpr string? Are you talking about string literals, or std::string, or what?

Literals, std::string, char*, I don't care which.
I would love to be able to do constexpr stuff with strings at compile time, and dump these crusty macros. But as far as I can tell there is no simple way to do string processing at compile time at the moment. My macros only do basic things, append some constant values to the strings etc. I'm already using constexpr to pre-calculate some numerical values the program uses.

>For starters, it's not a vector: it's an array. Its size and allocation is fixed. That is not an issue.
It's irrelevant to this point
>Multiple threads modifying different members makes no fucking difference.
Once again, it's not about the members. It's the fact that you have two mutable references pointing to part of the same array. I don't know why you are having such a hard time comprehending this.
>False positives are far worse than false negatives. Good job designing an unusable piece of shit.
Your code is inherently unsafe for language whose selling point is memory safety and concurrency. If you use want to do unsafe operations feel free to wrap it in unsafe { }

If you can't see the problem with having multiple mutable aliases then you are a brainlet :)

How is an array of 2 integers literally any different than two separately declared integers in this case?
Jesus christ, you are so fucking retarded.

You continue to focus on the individual integers and not the array they belong to. As suspected, you are a brainlet. Have a good day.

Show me your best meme data structures, /dpt/

Attached: memes.png (627x110, 8K)

#define bunneh \
(\__/) \
(='.'=) \
(")_(")

Trying to transfer C++ code into Rust :DDD

Does this complie?

What operations are you trying to do?

yes I think, as long as its not used.

Any good haskell resources you recomend?

What's this?

Basically just appending stuff to strings at compile time. The specifics to append vary by platform.

At the moment this is working nice
char *str = MY_MACRO("my string");

becomes
char *str = "my string with platform specific garbage appended to it";


Some of the macros take other arguments and I want these to be safe - if you use a macro with invalid arguments I want it to be a sensible error.
The project is basically C but I do have a C++ compiler so I thought about using constexpr instead of macros. But turns out doesn't work for any string type.

If you used a good language you wouldn't have this issue.

Weird, I've been working with godot lately. Pretty comfy and much better than gamemaker imo for 2d gamedev.

Attached: hugsnotdrugs.jpg (490x451, 22K)

brainlet here

So I've been dicking around with a python book for the past month or so. I found something that has an immediate applicatin to my job by using openpyxl. I have a couple of dozen excel files that need some cleaning up. I thought maybe I could write a script in python to do it for me. I've been at it for like two hours, I can't fucking delete multiple blank rows. If I do a loop it gets stuck forever. Online tutorials are dick. Anywhere I can figure this shit out before I get an intern to manually delete about 200k rows of shit and then quits halfway?

Wish I got to pick which language I get paid to write.
Which high performance language could do compile time string generation better?

my nigga

Also, the node/scene system is super programmer friendly to where gamemaker tends to be friendly to beginners in general.

What is your problem? You have excel spreadsheets, with a large number of blank rows that you want to remove automatically?
I know literally nothing about excel, openpyxl, or python, but the pseudocode for your algorithm will look like this:
row = 0; // start at row 0
while (row < total_rows) { // while there are still rows to process in the spreadsheet
if row is empty { // check if a row is empty, if it is delete it
delete row
} else { // if a row is not empty, look at the next row
row = row + 1
}
}


How does openpyxl handle rows? I know when you delete a row in excel normally all subsequent rows are moved up 1. And excel let's you scroll off infinitely, is there a way to get the maximum number for a row with actual content in it in openpyxl?

more pythonesque psedo:
row = 0
while row < total_rows:
if row is empty:
delete row
else:
row = row + 1


Have you tried an approach like this? What is the issue with it?

A compiler for a little Lisp language for the JVM.

It just bugs me there's no proper way to return multiple values from a function on it.

Rust

>It just bugs me there's no proper way to return multiple values from a function on it.
multiple return values are nothing more than sugar coated structs or in Java's case objects.

Sadly it needs to run on embedded platforms afaik Rust doesn't support our platform.

Have you submitted a bug report? Are you sure it's not supported or just not fully regression tested?

Are there any good sites for learning GENERAL game programming?

I wanted to try making a roguelike/simple text based RPG. The problem is every time I find a tutorial or whatever, they just link a library and say "Do this and ta-da you have a game!" I want to learn how to code a game loop. I want to build my own combat. I want to learn general concepts I can apply to any game I want to design.

>GENERAL game programming
You won't find one that isn't specific to a language sadly.

I suppose I should've clarified that. By general, I mean general CONCEPTS. I'll happily learn C# and Unity or JS or Python and PyGame or whatever to make a game.

I just want to be able to learn the concepts I can apply to all languages.

For example, I learned about finite state machines in Java a while back and have been able to use those concepts to GREAT success in Python and LSL. Yet if I do Joe's Roguelike Tutorial™ all I learn is how to import RogLib and create an instance of combatEngine(). I want more than that.

I think it's the openpyxl itself.

mport openpyxl


wb = openpyxl.load_workbook('2015 E.xlsx')
sheet = wb.active


i = 1

while i in range (1, sheet.max_row):
if sheet.cell(i, 4).value is None:
sheet.delete_rows(idx=i, amount=1)
else:
i = i + 1

wb.save('2015ECopy.xlsx')

This one doesn't get stuck on a loop but it also doesn't do anything. The most I've been able to do is delete the first blank row. Someone on stackoverflow mentioned in some ancient post that it doesn't recognize rows, only cells, so maybe I can just get it to copy and paste itself upwards. I also tried starting from max range and working my way down but that puts me on an endless loop.

gameprogrammingpatterns.com/contents.html

Have you taken a look at online intro-to-programming courses?
Not sure what you're experience is, but here's a couple

VERY basic intro (in Java); youtube.com/watch?v=KkMDCCdjyW8

Next-class (C++). This might be more your speed.
stanford.edu/class/archive/cs/cs106b/cs106b.1158/lecture-videos.shtml

gamesfromscratch has a bunch of stuff but it depends on what you want to do.

C++/SDL2 is pretty rough if you don't have patience for the rendering stuff. Otherwise Unity for 3d and Gamemaker for 2d are both popular. I'm one of the godot anons and I can't recommend it more.

>open link
>singletons
>close link

>This chapter is an anomaly. Every other chapter in this book shows you how to use a design pattern. This chapter shows you how not to use one.

Text based games dont share that much in common with real-time video games
Implementing RPG combat systems can quite literally be taking tabletop RPG rulesets and data tables and writing them into the computer

Thanks a bunch! I'll check it out.

I have a few times but it's entirely possible those weren't the kinds of beginner courses I wanted/needed. Thanks for the links! I'll give those a watch.

Right now I'm cool with sticking to basic stuff. 2d side scrolling or topdown is probably as complex as I'd be interested in going right now. As I said, I'm not opposed to Unity/Gamemaker or whatever. It just seems that the tutorials I've found are: Hey download my module. Done? Alright download my sprites, copy these bits of code and there you go. You cloned my game!

Still, thanks for the suggestions. I'll look into it!

I have created a VERY basic "Look, go, where, quit" sort of game.

The two biggest hangups I've had are:

- Turns. There's two ways, I think, to do time/turns in a game. Either EVERYTHING takes their turn at the same time on player input like in Tales of Maj'eyal or other roguelikes. Or it's all real time and the game is constantly running like MUDs. I don't really know how to accomplish either properly. I worry that what if I had AI in real time? The AI could take advantage of the player due to zero latency. If I go turn based... How do I even do that?

- I don't care a ton about graphics but I think it could be cool to do ASCII graphics like Nethack. I'd even go as far as hand crafting maps if I could. I THINK I know how to do that but I'd probably go about it the wrong way.

The reason I'm hung up on these primarily is that I feel like there's PROBABLY a "proper" way to tackle both of these. I want to avoid making something that's garbage cause I misunderstood the concepts.

Every object has a "TakeTurn" method and when the player makes an move you run over all the objects and execute that method

Is it really that simple?

I thought that was a possible solution but it just seemed inefficient in my head. I'm probably overthinking it.

It is that simple
but you will need a seperate loop for rendering the game or handling the user interface which runs every frame or based on events, depends what you're working with

Structs are nothing more than sugar coated multiple values.

>Structs are nothing more than sugar coated typed continuous memory
FTFY