/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

wiki.c2.com/?AlanKaysDefinitionOfObjectOriented
rylev.github.io/words/blog/2013/10/03/erlang-is-the-most-object-oriented-language/
ghostbin.com/paste/toudj
gameprogrammingpatterns.com/
twitter.com/NSFWRedditGif

c++ is the greatest language of all time

What's with this religion bullshit over the last few threads, OP?
Only religion allowed on g is unashamed orthodox weebism.

Is there anything like type constraints in C++?

For example, proc fn[T : int | float](a, b: T)

I enjoy writing java code

data List(T: Type) {
nil,
cons(T, Self)
}

A discriminated union. It can be more space-efficient than the tagged version by indicating `nil` with a normally illegal null tail pointer.

type List(T: Type) = (tag: Bool, (| !tag) ^ (T, List(T) | tag));

impl[T] List(T) {
pattern nil = (false, ());
pattern cons(x: T, xs: Self) = (true, (x, xs));
}

A tagged union. `T ^ U` is the exclusive disjunction of `T` and `U`. In this case, it's inhabited because `!tag && tag` is unsatisfiable. It can be more ABI-friendly than the discriminated version because the layout in memory is well-defined. Discriminated union memory layout is not well-defined to allow for optimizations like the one shown for the first example. User-defined patterns can still be checked for exhaustive matching.

>I want the player to be able to ctrl+F to search through all items he's seen in the game, and that will be much fewer operations if the members of class_B/game_item are altogether in a seperate container I can iterate through
you mean like a diary that records where the player saw an item so he can go back and get it when he needs it? sounds like it should be a data structure of its own with a pointer to both the tile and the item.

The inevitable spread from when "christian" forums decided to start infiltrating Sup Forums around 2010-2013.
It has already ruined /fit/ I'm pretty sure /k/ and I'm pretty sure Sup Forums is on the list now

>Is there anything like type constraints in C++?
No. All you get is SFINAE.

...

why do you say that? If I have a doubly-linked list of instances of items_class, then those instances will already have branch/floor/x/y coordinates as members. Why would I copy the same information into a data structure that is organized in the same way? The reason I already want the same item listed twice is for computational efficiency: for ctrl+F, I want to be able to iterate through a list of items, and for drawscreen and monster AI, I want to be able to iterate through a list of x,y coordinates.

>not recognizing the one true belief system
pleb

I'll do that. My biggest worry is that I'm gonna get to some point where I realize that everything I've written is incompatible with some larger good design practice, and I'm gonna have to scrap it all. I already have 1k LOC, and don't want to get to 5k in time to find out that it only works on Linux, or it relies too heavily on pointers to save the gamestate, or that it's a convoluted spaghetti mess. However, I guess that is the nature of being new, can't know what you don't know until you know you don't know it.

Yeah, if you have proper references, sounds like you'd only gain something if you keep an itemsSeenLog: List[Item], since from what I understand you can access an item's location from the item, right?
>want the same item listed twice
Are you talking actual data duplication (as in, no longer doing Single Source Of Truth), or just referencing the data from multiple directions?

How can I route the code-completion list displayed in Visual Studio over to an executable? Or even just capture the list items as they pop up?

I am not asking for help, just seeing if anyone can point me toward the right direction. Already asked this elsewhere, can't get any info. Trying to look through VS but it would help if I had a tip from a more seasoned user.

I hope you're referring to the Church of Emacs, user.

That's why it's a good thing to keep asking, and share your thoughts.
Just don't forget to remind yourself - aim for a balance between getting shit done and getting shit proper.
>it only works on Linux
Port and test early, set up automated testing if possible. This is if other platforms are important enough. Go for at least smoke tests, whatever's easiest to have automated.
>relies too heavily on pointers to save the gamestate
Yeah, dunno what you're thinking about saving the game state. What do other projects in this class do?

I found out Windows 7 has a built in C# compiler, does anyone have any tweaks they make using C#?

It's just a women programmer wearing her programming hijab :)

Oh yeah, I now realize what I was missing. I will not have a itemsSeenLog, I'll just add a boolean "seen_by_player" member in the item class.

I'm not in a class, just been playing a lot of roguelikes and trying to write one. It's more work than I thought, mostly because I'm having to learn so much. My previous programming experience was just writing simple image editors in Matlab for uni.

its called intellisense

Thanks. Not sure why I didn't realize the entire code-complete process is handled through Intellisense. The more you know...

Ask again in ~2 years.

That's probably going to be hard as fuck, easiest way I can think of it to create your own code completion list using the Roslyn compiler by analysing the code tree yourself.

>>most of what i've found has dead results
>Look harder. Here's the basic idea: you pick a plane and use it to split space into two subsections: all the space behind the plane, and all the space in front of it; then, for each subspace, you pick another plane and repeat the process; keep doing this recursively until you reach some limit that satisfies you. When you're done, you're left with a binary tree of planes. You then take your polygons, and one by one, you "push" them through this tree: you check which side of the root plane the polygon is on. If it's behind, you push it through the (e.g.) left subtree. If it's in front, you push it through the right subtree. If it's on both sides (i.e. the plane splits it), you split the polygon into two, and push each one through the corresponding tree. Eventually you reach the leaf nodes, so you leave your polygons there. To draw it back-to-front, you start with the root plane and check which side the camera is on. You know that all the polygons on the opposite side have to be drawn before all the polygons on the same side as the camera, because any ray of light from the camera to the polygons on the other side would have to at least cross the plane to get to there, and it would sooner hit a polygon on the same side of the plane. So you draw the child node for the opposite side, then the child node for the camera side. The same logic them applies recursively until you reach the leaves, at which point you just render the polygons stored there. As for picking the planes in the first place, you have one for every polygon.

I kind of understood that. So you go left to right in the bsp tree.

What I am confused is what exactly a leaf node holds: a line? a polygon? a pixel?

How does the program cut it up into leaf nodes? How does it decide what the starting point is and what the final leaf is?

Without the diary structure you'd need to loop through the entire map every time to you want to show the player where the loot he has seen is located, and test whether he has seen that loot.
With the diary you have what you need and only what you need right there. You can sort it and to b-searches on it there, and you can put other important things like quest objectives in that same structure. It's good encapsulation and good semantics, the hero has-a diary.
And don't worry so much about memory use, especially for something so small as pointers. Memory exists to make your life easier.

I think we are on the same page. I planned on having 1 variable be a list of items, then also having map tiles point to the item. I thought for some reason user was saying I should have items included in a 3rd location.

>be me
>making a program in C
>compile without error
>test run
>wtf.png
>it behave really weird
>spend 7 hours checking whats wrong with the code
>turns out there is 2 .c files containing int data_index; and I forgot to set it to static, and the linker just connect them together

Stop using global variables, idiot.

I too have had problems in C. Mainly when I call a function that is in another C file without be being declared there.

if youre using global variables then youre a retard and should stop using c

>using a language that allows globals

>programming at all

Or maybe it's you who is retarded who knows nothing about his design requirements?
Global variable is fine if it's used for it's intended purpose: global state.

>inb4 hur dur all global state is bad
Or maybe you're just an idiot who's never done any real programming before.

Can someone explain what message passing is? I saw it while searching for Nim, which supports it, I read the wiki page but it looks identical to polymorphism.

Building a function that performs the Newton's method for approximating squares. Can't seem to get the a to continue updating past two iterations.
Where am I being a dumbass?
void newtons_method() {

int i = 0;
double long a = 1.0;
double long b = 3.5;

while (i < 100) {

b = (a - (func(a) / func_prime(a)));
a = b;
cout

approximating roots*

wiki.c2.com/?AlanKaysDefinitionOfObjectOriented

rylev.github.io/words/blog/2013/10/03/erlang-is-the-most-object-oriented-language/

Do you mean it crashes? Post expected outcome and actual outcome

Ackshually b = 3.5 might as well be nan since you never use that value

P(n) is now at : 3.5
P(n) is now at: 3
P(n) is now at : 2.5
P(n) is now at: 3
P(n) is now at : 2.5
P(n) is now at: 3
...
so 'a' starts at 1,
becomes 3.5,
by the 2nd iter, 'a' should equal ~2.60714, but it starts bouncing as you can see.
here are the funcs being called:
double long func(int x) {
return (x * x) - 6;
}

double long func_prime(int x) {
return 2 * x;
}

Is that supposed to happen?

Don't you have to declare that shit extern?

Accckkchully I know it but it was for debugging and I didn't change it back before I posted.

You might want to not use a func that works on ints if you want more precise results. Just sayin'

Fuck I'm a retard, now it's working, thanks, user.

You're welcome user

Hey guys. I have a dillema:
I am a developer and have been with my first company for 5 years now.
I worked on many different projects and had to use different technologies some of which are: C, C#, Javascript, TSQL, Java.
As you can guess I am now OK with all of them but really a master of none. When it comes to programming in general I would say I am very good and a fast learner.
In my company I am a one-man show since software development is not our core bussines. That is why I recently reached out to a few other companies where I would be surrounded with developers and learn more and quicker.

One of the companies is offering me a role of Javascript engineer... That would of course include Angular and similar frameworks.

The only problem is the salary. The new company is offering 20% less pay than the current one. This is kinda reasonable since I effectively only have a year of experience with the technology that they need me for, but on the other hand, overall I am an experienced developer and have brought a number of projects to completion.

On my current salary I can save 10% per month no problem.

So my question is: is it worth it to change my lifestile to spend less in order to try out a potentially better company?

There is a significant probability that my new salary could reach my current salary in about a year or a bit more.

I wanted to ask on /advice but the question is software based so i'm posting here.

it greatly bothers people like you

go back there

Dis nigga being a disingenuous and insensitive fag here because no one is arguing that.

If programming socks make you better at programming, why aren't there more female programmers? Surely they should be super powered from decades of wearing programming socks?

>retard thinks the prayers are for prevention
>not that the prayers are to get the sinning faggot kids into heaven
nigger needs to stop being edgy

Ask if the starting salary is negotiable.

That's basically a strawman of an amalgamation of gun owners and Christians, but so vague there's no opponent that's going to want to point it out. For liberals, debate means monologue.

I wouldn't take any life advices from the internet and especially 4cham.

If you care more about improving then you go to the place where you can improve.
But if you are thinking about some creative position you might be trying to bite more than you can chew.

>female brains is still inferior
>t. Neckbeard virgin misogyny.

Nice strawman.

Why grant the vote to females if they are just going to vote guns and booze away?

Will do probably

Normally I would not go to the internet woth this, but I am really struggling.
Just wanted to see how do you guys value learning over money.

New position won't be something crazy creative, there is a UX team for that.

Learn to generic:
#include
using namespace std;

template
FLOAT newton_method(FLOAT x0, Functor f, Functor_Prime f_prime, int iteration_count = 100){
while (iteration_count) {
x0 = (x0 - (f(x0) / f_prime(x0)));
cout

The blood of the innocent is needed for the conversion of sinners.

Sup Forums has never been your super secret fedora hideout.

>>>/reddit/

I don't see work as a place to learn but you should take opportunities that present themselves.

If risk isn't high only thing stopping you is fear.

why aren't you using D this very moment

Not as fast as C++, not as convenient as [every POOlang which isn't Java]

what's a good book to learn concurrency, preferably language-agnostic?

So I have only done object oriented programming and want to do a basic web project, but my shit Java doc only explains Tomcat and I am pretty sure is not what I want. I consider C# or C++ too, where do I start?/ I took JS classes and holy fuck JacaScript and HTML is a mess...

it's dead

Is it at all possible to disable playback controls somehow when streaming youtube video inside an app?

>putting this in a global variable because I don't know how else I can get the instance of that object
on a scale from 0 to 10, how wrong is that ?
0 is wrong, 10 is wrongest.

global variables are evil, but sometimes they're the least evil option

post your code

Friendly reminder goto is perfectly fine in modern languages.

desu there must be some other way, but the frontend of this ERP is very badly documented. And all these modules and objects and shit... I just feel like whatever I do I'm shooting myself in the foot.

ghostbin.com/paste/toudj

Can someone tell me how/why func1 is going terribly wrong with auto return type detection?

#include
#include
using namespace std;
#include

int main()
{
using F = boost::multiprecision::cpp_dec_float_50;
cout.precision(numeric_limits::max_digits10);
cout

If you don't know any better it's some kind of solution so it's not wrong.

Question should be how bad is that.

not him but would you mind explaining the syntax you used in main for your Functor and Functor_Prime args? I'm not familiar with it but it looks to be extremely useful.

>t.genericlet

he's using lambdas user. please dont template if you're going to only ever have the one parameter, you're just uglifying your code and increasing compilation times.

Are there any tools for designing text-based UIs? Or do I just have to like create a bunch of spaces with a monospace font in a word processor and work from there?

Because you're using boost. Who knows what black template magic is happening in the background.

ncurses

it's okay, I can't into templates yet anyway and I'm not planning on trying until my basic skills are much stronger, I just didn't think we had any lambda style functionality in c++, so this is good news to me

yeah it's a c++11 feature. good on you for waiting till you master the basics too

is this still relevant today, or is there a better, updated book?

>Be God
>Be about to cast Timmy into hell to be tortured for eternity.
>Soccer mom in America prays to me for 8 seconds and convinces me to send him to the good place forever

lmfao.
what a brainlet worldview

Don’t use OOP in 2018.

This.
DOD > OOP

mike acton pls go

Never heard of him but he seems pretty neat. More of a Jon Blow fan.

You can't reuse the Functor type for the 2nd lambda as each lambda is it's own anonymous struct type (with its own operator()). An alternative is to use std::function but that's can lead to more overhead and it's more annoying to call.

#include
#include
using namespace std;

template
FLOAT newton_method(FLOAT x0, function f, function f_prime, int iteration_count = 100){
while (iteration_count) {
x0 = (x0 - (f(x0) / f_prime(x0)));
cout

>What are you working on, Sup Forums?
AI-powered virus that replaces Anime with pictures of frogs.

stupid frogposter go back to

smart frogposter

Wow. That's very edgy. I didn't expect that from him.

Works fine in visual studio. Must be a gcc problem.

gameprogrammingpatterns.com/

I think he means lambdas are C++11

punch that straw

Not that guy but isn't it more appropriate to explain your view rather than mocking the opposition?
It's certainly more in line with the idea that prayer is for the sinners moral standing not to prevent their deaths.

>What I am confused is what exactly a leaf node holds: a line? a polygon? a pixel?
Every node has a plane that divides the parent's space (or subspace) into two. The leaf nodes also contain polygons.

>How does the program cut it up into leaf nodes?
Leaf nodes are just those nodes of the tree that have no children. They are the point at which you stop subdividing.

>How does it decide what the starting point is and what the final leaf is?
Typically, you will have a level made out of many convex solids, so every face of every solid has a plane associated with it. In principle, you can pick any of them as a starting point. Then you have solids on one side of it, and solids on the other side, so for each subspace, you pick another plane from a solid contained therein and repeat the process. Eventually you run out, because you will have subdivided the entire level into convex subspaces that have no solids in them, but which are the spaces between your solids. Naturally, you stop at this point. Then you can push the polygons through the tree, and be confident that all the polygons that end up in the leaves can't possibly obscure eachother, so they can be rendered in any order.

In practice, if you want to write a good BSP builder, you will typically try to pick your planes so that the number of splits (remember that you have to split a polygon if it's on both sides of a plane) is minimized. There are simple heuristics that can be applied here. For example, pick planes from big solids first, because they will have big polygons, and picking them last and pushing them from the tree increases the chances that one of the planes splits them. Small polygons aren't as likely to be split. If you want to use the BSP tree to accelerate game logic, you will probably also want the tree to be balanced. Industry-strength heuristics for doing this stuff are difficult, but once you understand the basics, you can always read more on this stuff.

I have been sick for the last 3 days, hopefully I can go back to writing and learning data structures from tomorrow