/dpt/ - Daily Programming Thread

old thread: I made this Cred Forums. It is crop of an fractal created by the newton basins method using this polynomial:
-x^8 + x^2 + x - 1

Can you replicate it?

Other urls found in this thread:


Another pic

what a shitty thread starter

Would you rather have another fucking anime pic with no starter text whatsoever?
I mean I do like cute 2d grils, but it does get old after a while.

But it's missing the "What are you working on Cred Forums?"

>it does get old after a while

This /dpt/ is fake af...

Please get these vaginas out of my /dpt/

Why doesn't this work?

struct vector_tuple { int x, y; };
struct vector {
union {
int values[2];
struct : vector_tuple {};

int main(int, char**) {
vector obj;
obj.x = 1;
obj.y = 2;


There's your first mistake, laddie. I suggest using C.

You posted this shit WAY too early, and didn't follow the proper OP format.
Please delete this invalid thread.

>struct : vector_tuple {};

World would be better place if c++ didn't try to be c compatible and it was named to something else.

struct : vector_tuple {};
obj.x = 1;
obj.y = 2;

Is this even supposed to work?

Thanks Grandpa.

Reminder C++ is depreciated bloat.

Anonymous structs can inherit, and it compiles fine, the error comes from obj.x and obj.y, so how do i access the x and y fields?

Because unions don't work that way. Use PODs, and PODs only. Anything else is doomed. No way around this. Stop trying to be overly "clever".

I'm not trying to be "clever", i'm trying to save space. This vector class is going to be created and destroyed a million times per second so every byte counts.

>C++ is for pajeet and SJW faggots
Nope. Pajeets use Java/Python/JS/PHP and SJWs use Python/Ruby/JS/Rust. Both find C++ too complicated and low-level for their puny brains.

when will you guys stop being autistic about c++
it's been 33 years

No wonder you faggots can't figure out C++, you haven't even mastered English.
Protip: depreciate is the antonym of appreciate.

Any reason why you don't just preallocate a million-element array and just use it?

Or, compute the size of the largest struct you'll have, allocate size for it, then use raw typecasts to access it.

Here lad: ideone.com/6v4fnK

>Compiling C into javascript
Absolutely disgusting.

I don't get it. Why does this work, and his doesn't?

I'm creating a n-dimensional vector and matrix class similar to std::array but with support for common linear algebra functions.
It will be used for writing game engines, spatial data structures, etc, and the goal is for the source code to be as clear and as simple to use as possible.
No arrays, no prealocation, no c-style optimization, just an efficient vector and matrix class.

template class vector;
template class matrix;

For 2D, 3D and 4D vectors, i want to add x, y, z, w fields without increasing allocation size of the vector object.

It's C++ though.

what the fuck are you talking about

I know it works this way, but i want to inherit the anonymous struct with another one that is specialized based on the template parameters.

Will one of you retarded C shills explain to me how C is such a good language if the languages you call "memes" are slow, DESPITE their implementations being written in C? Python is written in C but you all cry that it's slow. Same with Java.

I honestly don't know if that's even possible. Unions are fickle, trying to put inherited structs/classes inside them is most likely not going to work. Even if it compiles and works, will it actually produce smaller and faster code?

Take a look at how GLM (for example) does these kinds of things. Maybe they have something you could use.

Languages cannot be slow nor fast, only their implementations can. Also C isn't good. It's old, obsolete, error prone, full of pitfalls, dreaded with UB at every step, half of the standard library is unsafe to use, and there's not much useful stuff in standard library anyway. It's only good for a few niche topics but not because the language itself is good but due to lack of viable alternative languages (there are some but they lack tooling et al).

c++ is c?(++)

God what are you doing.

Just make a some vec2, vec3, vec4, mat3x3 and mat4x4 structs.

Stop over engeneering everything.

Your source code wont get any clearer than this.

>m-m-m-muh safety :((((
>wahh why won't the computer hold my pandies ;____;

that's not what i was refering to
what the fuck did you mean >compiling into javascript
did you just pull that out of your ass

Wanted to reply to

C'mon user, let him Dunning-Kruger his way through reinventing the wheel.

I'd rather be called a babby by some random C sperg in /dpt/ than have my airplane flight crash due to a shitty language. C's shortcomings are the sole reason why there are buffer overruns and other bugs in software like zlib, Chrome, don't forget about shellshock either. Even the most experienced C programmers get this shit wrong and we all suffer - only because they chose a shit obsolete language.

Don't worry, you get the best of both worlds any time you open a web browser and get to enjoy some shitty slow-as-molasses Javascript shoved down your throat.

No. They are two completely different languages.

ur a different language

>shitting on C inherently means that I wholeheartedly support JS

k retard great argument

we use rust here

It's possible with inheritance, but this exposes an unnecessary class to the use,
template struct vector_fields { union { T values[N]; struct {}; }; };
template struct vector_fields { union { T values[1]; struct { T x; }; }; };
template struct vector_fields { union { T values[2]; struct { T x, y; }; }; };
template struct vector_fields { union { T values[3]; struct { T x, y, z; }; }; };
template struct vector_fields { union { T values[4]; struct { T x, y, z, w; }; }; };
template struct vector : public vector_fields {
// vector methods

Also i hate how this exposes vector.values as well. Accessing fields should be with .x, .y, .z, .w or operator[], nothing else.

What if somebody wants a 16-dimensional vector?
Also later on if i create an algorithm that works on n-dimensional vectors, do i copy-paste it for vec2, vec3 and vec4?
This is why templates are for user.

>Languages cannot be slow nor fast
Languages have a direct effect on the speed of the implementation itself.
For example, C99 added restrict pointers (an optimisation feature), so it allows for a faster implementation that C89 did.
>It's old
The last standard was 5 years ago, and there is another in the works.
What is it obsoleted by? hint: C++ does not make C obsolete in any way.
>dreaded with UB at every step
Undefined behaviour is fine. It's pretty easy to avoid unless you're a fucking retard. It also allows for the compiler to make much more aggressive optimisations.
The one that is actually bad is implementation defined behaviour.
>half of the standard library is unsafe to use
They're only 'unsafe' if you're a fucking idiot.
If you don't satisfy the precondition of the function, the function has no obligation to do anything.
For example, if you pass a non null terminated string to a C string function, it's YOUR fault, not the function's.
>and there's not much useful stuff in standard library anyway
The standard library is minimal on purpose.

The semantics on using anonymous structs, which is an unofficial extension in C++ and offered in most major compilers, with C++ semantics isn't quite clear to me. It seems like something that should work but since there is no standardization on behavior, you are basically rolling the dice on using it with inheritance. You can try throwing it in Clang or god forbid, MSVC, to see which will give you the right behavior.

>What if somebody wants a 16-dimensional vector?
Optimize for the common case, not for the 16-dimensional weirdo that's going to be highly specialized and rarely used anyway.

Have heavily optimized 1D/2D/3D/4D vectors and 3x3 and 4x4 matrices. Maybe have generic templates for higher dimensions, but don't waste time with them unless they are actually required.

>What is it obsoleted by?
rust :^)

You shouldn't be using any operating system other than DOS and MenuetOS at all if your argument is that. Every single operating system built since the 90s has C code in it in some form. Heck, even with web browsers, I know of none of them that doesn't have at least one C library dependency.

Those are not mutually exclusive user.

>What if
>What if
>What if
We still call this overengineering. Are you gonna cater to ever "what if"?
Needing a 4+ dimensional vector is extremely fucking rare, especially for games. You're inconveniencing the 99.99999% to cater to the 0.00001.
If he really needs it he can write it when he needs it.

>Do I copy paste
Actually you should be using a library for math. But yes, it's only 4 structs and you would've finished already while you're trying to figure out templates.

Also template overuse makes code less readable and harder to debug.

>The last standard was 5 years ago, and there is another in the works.

The base itself is very old - you cannot fix what's inherently broken but just slapping something onto it.

> What is it obsoleted by? hint: C++ does not make C obsolete in any way.

Obsolete in the sense that it doesn't meet present day demands from programming languages.

> It's pretty easy to avoid unless you're a fucking retard.

I guess the Linux kernel developers are now retards, go tell them.

> For example, if you pass a non null terminated string to a C string function, it's YOUR fault, not the function's.

Yes, it's my fault if I do that, the point begin that the language easily encourages such mistakes.

> The standard library is minimal on purpose.

Fair enough but then it's not really a general purpose programming language as many make it out to be here.

> You shouldn't be using any operating system other than DOS and MenuetOS at all if your argument is that. Every single operating system built since the 90s has C code in it in some form. Heck, even with web browsers, I know of none of them that doesn't have at least one C library dependency.

As I said, C still dominates some niches and will do for a while (and I've no problem with that) until we have a viable alternative but it's only dominant in these areas due to the lack of one and due to a lot of legacy stuff.

Does Facebook, barring weird circumstances, get back to their applicants in the order they applied?

There's a much cleaner way to do this
enum { X, Y, Z, W };


Large companies fetch a list of potential applicants, go through some level of interviews to ensure that they could be useful, and then keep them on a bigger list for when they actually need someone.

It is rare that a job posting directly corresponds to a position needing to be filled.

Facebook is probably closer to that ideal than others like Google.

>tfw you fell for the programming meme

There's nothing you can do now.

Lack of alternatives is valid but legacy stuff is wrong. People are perfectly still writing C applications. Wayland was started in 2013 and is written in C despite being able to use something like C++. Rust and C++ might have a chance to get into future OSes or system utilities if there is enough momentum and C lags behind massively by sticking to C11 forever but that isn't going to be the case the case so IMO, system utilities will continue to be a mix of C, C++ and to a lesser extent maybe in the future, Rust unless one of the two gets a killer language feature which is unlikely.

However still, there is no way in hell they can perform to the same effect in the embedded niches that C is relegated mostly to which powers almost all aspects of our lives. Whatever that will replace C now in those niches needs ISO standardization and stuff that many languages don't support even as extensions like fixed point arithmetic, named address spaces, and formally defined direct register/bus access (via iohw.h). C++ is way too heavy without heavy subsetting of the language which is non-standard and has none of the standard embedded extensions C has. Rust doesn't even support any of these features that would allow it to appear anywhere other than x86, ARM and AVR platforms at the moment.

When everything is running on 32 bit hardware, then maybe something more heavy can replace C completely and in its entirety. But until then, embedded and systems programming will continue to use C.

Can anyone help me with some JS help?

Just post the question. You don't need to seek our permission to post something. Admittedly though, we have /wdg/.

What good are structs in c#?

function updateClock() {
var m = new Date();
var dateString =
(days[ m.getDay() ]) + " " +
("0" + (m.getMonth()+1)).slice(-2) +"/"+
("0" + m.getDate()).slice(-2) + "/" +
m.getFullYear() +" "+
("0" + m.getHours()).slice(-2) + ":" +
("0" + m.getMinutes()).slice(-2) + ":" +
("0" + m.getSeconds()).slice(-2);

document.getElementById('time').innerHTML = dateString;

setTimeout(updateClock, 1000);

I want this in DD/MM/YYYY instead of MM/DD/YYYY as it is currently. I have limited knowledge in JS. ;-;

Write a library in C, compile it in asm.js, and call into it.

Move around the concatenate order...


sad to say it's not bait i've just got no clue what i'm doing

so am i allowed to ask the question or not?

no language holy wars. Don't waste time arguing about minute differences in dialect.

how is this not completely obvious? don't be afraid to experiment, if you mess it up you can try something else

Using C++ for daily scripting of simple tasks causes premature ejaculation

Just swap

("0" + (m.getMonth()+1)).slice(-2) +"/"+


("0" + m.getDate()).slice(-2) + "/" +

>Needing a 4+ dimensional vector is extremely fucking rare, especially for games
You do realize literally every 3D game uses 4D vectors right?

and move

m.getFullYear() +"/"+

i did try but I was trying to change the numbers in the slice part. i really had no idea what to do :p


So I finally figured out why Clojure kept giving me random NullPointerExceptions in my minesweep program.

Apparently, comparing two variables with (

Please fuck off, you have absolutely no fucking idea what you are talking about.

so this is the power of meme languages

Your "clever" little abomination doesn't at all help in that respect.

Fucking this.
It fucking pisses me off that references:
A: can't be null
B: can't change their value
It's so fucking stupid.

>inb4 hur dur use pointers XDDDDDDDDDD

>Meaning bigger than 4

Just use pointers.

18+ means 18 and up, I'd assume it also means the same for vector dimensions.

>Needing a 4+ dimensional vector is extremely fucking rare, especially for games.

>x, y, z
What's the fourth component?

>what is perspective divide


No idea.

What is it?


the fourth component

And what does it fucking do?


your mom

Can your language do this?

What do you mean "what does it do"?

Any turing complete language can support an o(n) sorting alorithm

Why does the W component exist and what is it used for? as far as I know it's just thrown in for apparently no reason at all.

Dont think of a vector purely geometrically. Its just a representation of a direction in n-dimensional space. Each variable is just a dimension. Like economics: savings, cash, bonds, shares, interest rate, dividends. Thats a 6 dimensional vector, dont lock yourself into only "physical" geometry, its programming so we can represent it however we want.