/dpt/ Daily Programming Thread

Previous thread What are you working on Sup Forums?

Other urls found in this thread:

u.teknik.io/Eclba.zip
dragonwins.com/domains/getteched/bmp/bmpfileformat.htm
fileformat.info/format/bmp/egff.htm
msdn.microsoft.com/en-us/library/dd183391.aspx
twitter.com/SFWRedditGifs

Hey ladies

fuck opengl

making a csgo cheat in java

why not just work on a game thats actually good?

so someone who's been programming for 8 years and never done anything, is like someone who sings in the shower claiming to be a musician?

Programming can be different things to different people. But you're right they shouldn't parade them selves off as a 'programmer' if they probably can't do anything beyond fizzbuzz. But then again, most web devs are probably on the same level and have a much larger ego.

More like somebody can fix his own car but doesn't tune a huge dildo on top of it just to show off.

See: You can write pretty impressive code and still never get it to the point where you have a finished product to show.

why sizeof(struct) in seppels always result in the power of 2?

I'm working on a project that will grab info from one of our servers, store it and then use it to generate reports or other querying needs. Probably takes ~5 seconds to build right now, though I think a lot of that is due to linking. I'd have to check later.

>why sizeof(struct) in seppels always result in the power of 2?
It doesn't, though. It's probably just a multiple of 8 due to struct padding.

Should multi-dimension arrays be a core-language feature, or a user library, /dpt/?

Reposting from a previous thread.
extern "C" affects both function declarations and function pointer declarations. This is because C and C++ ABIs may differ not only in name mangling, but also calling conventions, so you must do something like this to be completely correct.
extern "C"
void cfun(void);

extern "C"
void (*cfun_ptr)(void) = &cfun;
Please correct me if I'm wrong. With those assumptions, these are my two questions.
>1
Are function pointers passed into extern "C" functions also assumed to be extern "C"? Do function pointers in extern "C" structs use C ABI?
extern ""C"
struct Foo
{
void (*fptr)(void);
};

extern "C"
void takes_fptr(void (*fptr)(void));
>2
Is it possible to generalize a function pointer using the C ABI as a modifier on its type? Take for example this case.
extern "C"
void cfun(void);

auto get_cfun(void) -> void (*)(void)
{
return &cfun;
}
I'd like to be able to state that the return type is a function that uses the C ABI.

Ow yeah, I just tested and it always the multiple of 8.
Why it's padded anyway?

Good question
I was going to make it for css but theres a lot more resources for csgo

should arrays be a core language feature?

Because the members have padding requirements.
struct pair
{
u32 x;
u16 y;
};
If two pairs are in consecutive memory without padding, then x will not be word aligned and the processor probably won't be able to load it like it should.

well if you can fix your car you've got something marketable. Im talking about a poster 2 generals ago who said they were 20, had been programming since 12, and had 0 projects/work experience. The parallel that you'd drawing with automobiles is like someone who has been changing their oil and reading car magazines for 8 years wondering how to become a mechanic

Trying to convert a semi regular 3d point sets into images. Pic related (1st view)

My main problem is getting 1pixel/1point view set up programmatically. Too far zoomed in (2,3,4 views) and there are gaps between the points, too far zoomed out (last view) and the points overlap. At the optimum zoom (set by hand, 5th view), one 3d point is represented by one 2d pixel, this is what i want to set programmatically.

Im faking orthographic view with 0.0001 fov, but this shouldnt be a problem.


Also when rendering to a texture, can i set the background color value to float NAN or +-infinity?

>Why it's padded anyway?
Because 64 bit CPUs read 8 bytes at a time from addresses that are multiples of 8, so if you have, say, an int that starts at an address that isn't a multiple of 8, the CPU has to read 16 bytes and then do some shifting and masking to get your int from the two 8-byte cells it spans. This is obviously slow, and on retro hardware, it would simply crash. So the compiler puts some useless bytes between the fields to ensure that every field starts on an address that is a multiple of 8, and then adds some extra padding (if necessary) to the end of the start, to ensure that if this struct starts at an address that is a multiple of 8 (protip: it will, if you use malloc), you can safely put another struct right after it and all of its fields will also be correctly aligned.

I made a program that uses IDA* to solve sliding puzzles. I recently added a transposition table with Zobrist hash keys and finally got it working. It sped it up a decent bit but not as much as I expected it to, it still takes 3-5 seconds to solve 15-puzzle's with ~50 move solutions, and it still can't solve puzzles with solutions of over 70 moves.
I've been wracking my brain trying to get it to solve hard puzzles but I just can't get it to work.

I originally wrote everything in Java, I spent the past two days rewriting it in C thinking that it would be faster, but its the same.

I can't help but think I did the transposition table wrong, it speeds up the search a good amount, but if I tweak it even a little bit the search becomes unstable and it sometimes wont find the optimal solution. When it's unstable though it can actually solve the massively difficult puzzles (78-80 moves) in seconds. I can't figure out why the changes I make would even affect it like that.

There's no difference between a single dimension array and a multiple dimension array.

>interview at a company that uses scala
>during my visit, I discovered that they ban scalaz, cats, and shapeless in their codebase
>because not enough people are interested in learning how to use any of them
>essentially just want to write "[slightly] better Java"
I actually feel a little angry about this.

C++ question.
I have a settings file for my program, it's just a bunch of "key=value" pairs that I read line-by-line as strings. I have a bunch of unordered_maps for the different variable types. Is this retarded?

example:
unordered_map m_uint_map;
unordered_map m_bool_map;
unordered_map m_string_map;

and here's a usage example of the function I call to write one of these maps to the file:
template
inline void UserSettings::write_map(ofstream &file, const unordered_map &map)
{
for (auto it = map.begin(); it != map.end(); ++it)
file first

I forgot to point out that the second value in the map is the pointer to the address of the variable that it gets stored in. For example assigning the maps looks like:
m_bool_map["fullscreen"] = &fullscreen;

>What are you working on Sup Forums?

Exploring the deepest, darkest corners of Racket. Advent of Code 2017.

haven't you finished exploring them yet?

>that font

>haven't you finished exploring them yet?
Lisp is metacircular, so it has an infinite number of dark corners.

Did the compiler also pad primitive datatype?
For example:
void func()
{
short data[3];
//do stuff with data
}

Did the func() consume 16 byte of memory in the stack instead of 12?

Nothing a transfinite induction can't do.

>"This library is too complicated for most people here so we don't use it."
Can you seriously imagine this being acceptable if the language were Java or Python? Or being so stubborn that you refuse to even attempt to learn something new for your job?

This isn't really correct. 32-bit ints only need to be aligned to a 4 byte boundary, for example, and SIMD data is faster if it's aligned to even larger boundaries than 8 bytes.

That won't be padded because arrays have the same alignment as their elements.

>Did the func() consume 16 byte of memory in the stack instead of 12?
Yep, I think so.

Omg this mother fucker with raket, go fuck you self dumbass

The software industry is fucking idiotic what else is new.

>32-bit ints only need to be aligned to a 4 byte boundary, for example, and SIMD data is faster if it's aligned to even larger boundaries than 8 bytes.
Wouldn't this be platform-dependent? I was simply explaining the general principle.

simd operations work on 128 bit data so the data should be aligned to 16 byte.

>That won't be padded because arrays have the same alignment as their elements.
Why wouldn't it be padded? If you then go ahead and allocate an 8 byte long, wouldn't you lose 4 bytes after the array?

advent of code ends on 24 december

it's taking you 24 days to program something?
are you making a game or something/?

I tried that advent of code but parsing input with iostreams is such cancer

>simd operations work on 128 bit data so the data should be aligned to 16 byte.
Okay, but whether or not your code compiles to SIMD operations is platform-dependent, as is the alignment requirement of 32-bit ints. The general rule is that X-bit CPUs will use an X-bit memory bus and read X-bit chunks from X-bit-aligned locations. It's not 100% accurate, but it's a good enough generalization to explain to someone why the fuck his structs are being padded.

Then you shouldn't have specified 8 bytes in the first place.

Yes, but you didn't put that in the original code...
Padding for structs is different than padding local variables on the stack, because structs are always padded so their size is a multiple of their alignment.

How long is everyone’s sprints at work? We are at 2 weeks but there’s been talk of dropping it down to 1 week sprints

scanf is enough most of the time

Hey guys

I'm trying to send a message from my Client class to my Server class using TCP.
The .isBound() method seems to show the Server detects the client , but I have no idea how to send the message now.

Can anyone one give me a tip on how to do this?

How do I get people addicted to the games I make so that they will spend money in the microtransactions?

Fuck off Tim

I got a shitton of cash to spend. What books should I buy /dpt/?

>Then you shouldn't have specified 8 bytes in the first place.
Maybe not. He said it appeared to be powers of two, so I figured he's running into 8, 16, 32, which you are likely to get for small structs on a 64 bit platform, so I went with the 8 byte thing. I could've said "word-aligned", but that would've been equally inaccurate and more confusing.

>Yes, but you didn't put that in the original code...
He asked if it will consume 16 bytes of stack space as a followup question to my explanation, which assumes a 64-bit platform where everything is word-aligned. In this scenario, I'm pretty sure it would consume 4 extra bytes. sizeof won't tell you that, but whatever goes next on the stack will come after a 4 gap byte (at least as far as I understand).

Make it fun, make a lot of the non-gameplay elements, customizable. Smite recently did this and has unlocks for everything from jump stamps, to the loading screen, to the backing animation, to global emotes, etc

I can give you pdfs to a bunch of really good c++ textbooks, I dont think you should buy something you're not 100% sure you have the time and effort to complete

Actually, I see where I'm wrong now. There's hardly any reason for an architecture to require that everything is word-aligned. I guess the important thing is that primitives shouldn't span across word boundaries.

You got those PDFs? I could use some C++...

>sizeof won't tell you that, but whatever goes next on the stack will come after a 4 gap byte (at least as far as I understand).
Only if it needed to be word-aligned.

Exactly.

Andrei Alexandrescu Modern C++ design will blow your mind desu
u.teknik.io/Eclba.zip

I suck at haskell
How do i make a program where the user inserts two different chars, a list, and it returns me a list composed of elements that start with the first char and ends with the second one?

so far i got
search4Words :: Char -> Char -> [String] -> [String]

On of my biggest weaknesses as a programmer (of which I'm sure there are many) is that I feel a cumpulsion to do everything myself, from scratch.

I need remedy that. How do I learn to find usefull and free libraries that solve whatever problem it is I'm working on?

use partition, e.g.

search _ _ [] = []

search start end xs =

let (_, afterStart) = partition (== start) xs
(searchSection, afterSearch1) = partition (== end) afterStart
in searchSection : search start end xs

main = do
input1

>I need remedy that.
no you don't. The "reinventing the wheel" stigma is fucking stupid and is why we get left in shitty places. If you feel like you could make a better X, then make it, don't settle for subpar anything.

you sound like a retard in CS101 who thinks making linked lists and hash maps is cool, you'll grow out of it when you stop blogging about it on Sup Forums

will enrolling in a college degree slow down my path to becoming a dev, due to not having a lot of time to write code and what not for the first two years? Should i skip the college and just learn to code?

lolol

10 PRINT "HELLO WORLD"
20 GOTO 10

search4Words :: Char -> Char -> [String] -> [String]
search4Words a b strings = filter (\word -> (word /= []) && (head word == a) && (last word == b)) strings

I'm all for the learning aspects of reinventing the wheel -it's how I usually justifiy it to mysef- but the reality is that you don't get very much done that way.

>If you feel like you could make a better X
On the contrary, I always think everything I want to do has already been done multiple times and better, and whatever I can managa to hack together will be inferior to existing solutions.
At the least I should learn to find and evaluate existing solutions to determine if there is something I can do to improve upon it.

I'm not a retarded computer scientist. I'm a retarded software engineer.

oh i was thinking he wanted multiple searches in one string

Distributed worker listener/dispatcher in ReactPHP. Kill me.

>ReactPHP
what an unholy abomination.

>I feel a cumpulsion to do everything myself, from scratch.
>I always think everything I want to do has already been done multiple times and better, and whatever I can managa to hack together will be inferior to existing solutions.
I find your deep autism highly relatable. I manage this by focusing on niche problems.

>niche problems.
All my interests are quite mainstream. Lately I've been wanting to write my own mp3 decoder. Sounds like a *great* use of my time, right?

>working on a dead format
Contribute to ogg then

>All my interests are quite mainstream
Maybe you're not autistic enough, then, because I often run into situations where I want a relatively simple but highly specific tool, and no such tool is available, but I simply cannot settle for a general-purpose one that doesn't work exactly the way I want. It's a win-win: I get to reinvent some wheel from scratch, but in a way that renders comparisons to industrial-strength wheels irrelevant, and in the end I satisfy my other autistic desire for a program customized exactly to my liking.

thats what i thought.
no college for me

>Contribute to ogg
What's there to be done on ogg?

Ogg is deader than mp3 at this point. Mp3 is still a popular format, and with the last patents expired this year it's now free to use.

>dead
Read: reliable and used everywhere
>ogg
Read: Freetard format used by nobody

Don't take advice from fa/g/s.

>Ogg is deader than mp3 at this point.
it's superior to it in every way.
>Read: Freetard format used by nobody
except everybody in the music world who convert down .wavs to a user-friendly format

I can't settle for general purpose tools or 3rd party libraries simply because actually figuring out how to use them seems so daunting that it seems easier to just build everything from scratch.

I actually looked into implementing and ogg decoder a while back. I had three reasons for not doing that.

1. There is that newer format that i've forgotten the name of from Xiph Foundation, that basically makes ogg obsolete.
2. The ogg normative standard is defined in terms of the reference implementations. So that would just mean i'd be doing nothing more interesting than copypasting code.
3. An mp3 decoder is more useful simply due to the format being widely used. And there for would be more satsifying to work on.

Unfortunately it looks like I'd have to accept point 2 anyway, and look at the ISO 11172-5 reference implementation for mp3, becuase I can't get a hold of the full normative ISO 11172-3 document without paying the standardization organization many monies.

Can anyone send link for a bmp image specification?
The one that I use here :
dragonwins.com/domains/getteched/bmp/bmpfileformat.htm
and
fileformat.info/format/bmp/egff.htm
Isn't really working. I follow the specification but windows photo viewer can't read the data.

How do you guys feel about Qt?
I'm looking to go beyond just CLI stuff with C++ and designing GUIs sounds like a good first step. But I know there are a few options to choose from.

msdn.microsoft.com/en-us/library/dd183391.aspx
Maybe this will help?

Allthough I suspect it's you doing something wrong.

>muh GUIs
The only valid answer: HTML5 + Javascript.

Is GUI design a meme?

Qt made me cry. I hate Qt.

If you stick to using the QtCreator IDE you should be fine, though.

The only alternative to Qt I can think of is GTK

>I hate Qt.
Why?

I also have Windows forms, which comes with VS. But there seems to be a lot more documentation on Qt.

Not him. But I wonders how easy it is to understand Qt?
GTK+ is such a nightmare. The tutorial and documentation reference is a mess.
It's very similar to everything in r/restofthefuckingowl except hello world.
Hello world is the only one that have explanation.

Mostly because it's a bloated mess that's a pain in the arse to integrate into your build pipeline.
I won't deny that it can be a powerfull too though.

Yeah, I guess there's Windows forms. Have practically no experience with that. Seems babby tier. Might be good as an introduction for a noob.

Or you could go more hardcore and work directly agains the Windows API, if you're working on Windows.

My best suggestion, though, is to go with whatever feels best best to you. With whatever seems appropriate for accomplishing what it is you want to do and which documentation you find most readable.

And there is also this option Though you'd have to get js to interact with your backend application, and I have no idea how to do that.

What are some projects for a beginner in Python that force one to learn interesting and relevant skills?

Or, alternatively, what is a good question or paradigm of thinking that will motivate a beginning programmer to think of a project?

>go more hardcore and work directly agains the Windows API
have fun with that mess.
I'd rather use Qt.

>Mostly because it's a bloated mess that's a pain in the arse to integrate into your build pipeline.
It's a standard library with a great GUI toolkit. You gotta go full Qt before you get the dividends.

Card games are fun to make.

>search4Words :: Char -> Char -> [String] -> [String]
>search4Words a b strings = filter (\word -> (word /= []) && (head word == a) && (last word == b)) strings

A think i discovered today is that function arrow is applicative, so in theory you should be able to do something like this:

search4Words a b = let and = liftA2 (&&) in filter ((/= []) `and` ((==
a) . head) `and` ((== b) . last))

now its pointfree. while one can argue if this form is much nicer, i really enjoy how you can do mathematical messing around in haskell.

Understanding documentation is a skill in itself, that takes experience.

I don't want to make myself seem like some huge GUI expert. I haven't actually used GTK, so I can't compare, and it's not like i've used Qt a lot either, but from what i remember the documentation was pretty straightforward.
It was just a horror to actually get to compile if you don't want to use their custom tools.

How can I convert a hex string to a ByteString in Haskell. And how do you write lookup tables in Haskell. The only thing I could think of was to do this for changing an Ascii value to its corresponding hex value. Yes, I know it's retarded.

hexToBin :: Word8 -> Word8
hexToBin 0x30 = 0
hexToBin 0x31 = 1
hexToBin 0x32 = 2
hexToBin 0x33 = 3
hexToBin 0x34 = 4
hexToBin 0x35 = 5
hexToBin 0x36 = 6
hexToBin 0x37 = 7
hexToBin 0x38 = 8
hexToBin 0x39 = 9
hexToBin 0x41 = 10
hexToBin 0x42 = 11
hexToBin 0x43 = 12
hexToBin 0x44 = 13
hexToBin 0x45 = 14
hexToBin 0x46 = 15
hexToBin a = 0

why do you always use this image that reminds me of /prog/?

hexToBin = subtract 0x30