/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?
old thread:

Other urls found in this thread:

interactivepython.org/runestone/static/thinkcspy/Functions/thinkcspyExercises.html
twitter.com/NSFWRedditVideo

Why's she so angry?

>she

fuck off faggot

Fucking kill yourself, trapfag.
It is a girl.

struct option {
constexpr option(int value, const char* name);
};

struct field {
constexpr field(int offset, int size, const char* name);
constexpr field(int offset, int size, const char* name, option options[]);//????
};

static const field dataFields[] = {
field(0x000, 4, "Field 1"),
field(0x004, 5, "Field 2"),
field(0x009, 8, "Field 3"),
//fuck ton more of these^
field(0x166, 13, "Field 48", {
option(0,"A"),
option(1,"B"),
option(2,"C")
}),
field(0x173, 3, "Field 49"),
field(0x176, 9, "Field 50"),
//and so on
};

I want to declare/define a constexpr array of arbitrary size with static storage duration in the middle of an expression in C++.
Hardmode: not a character array.

wat do

...

I'm not exactly sure what your problem is, are you having trouble accepting an array of option with it's size known at compile time?
I think this should do it:
template
constexpr field(int offset, int size, const char* name, option options[N]);

>He thinks array parameters are actually arrays
lmao, try std::array maybe

She misses /prog/

Posix socket or SDL_net for cross platform net stuff for application already using SDL?

well I suppose I wasn't too clear with my example, but the actual problem is how do I store said array with a constexpr function?
if I try to add it to a container, it wont be constexpr
if I template the class, it wont fit in an array anymore
if I just try to store a pointer to the array, it will become a dangling pointer before I even enter main() because the array is a temporary by C++ rules

I'm stuck on this and it really bugs me because I feel like it should be possible because it is possible but only with string literals

How about:
#include
#include

struct option {
constexpr option(int value, const char* name) {}
};

template
struct field {
constexpr field(int, int, const char *, std::array options)
: options{options}
{
}

std::array options;
};

auto test = field{5, 5, "", {
option{0, "A"},
option{1, "B"},
}};

see in where I mention the class template

why does dbus even exist

>He doesn't know that you can accept C style arrays using template parameters with the size known at compile time.

Woops, I think it should actually be a reference for it to work:
template
constexpr field(int offset, int size, const char* name, option (&options)[N]);

(the parentheses are important)

>but the actual problem is how do I store said array with a constexpr function?
You mean, after you've passed the array into the fields constructor, you want to then store it somewhere with statically known size and contents?
That depends on how and where you want to store it, but you might not be able to.
You'd need to give more detail.

Thank you for making a mudslime free /dpt/

It's idea is nice, but it's completely trash in implementation.

I know the "where" can't be in the object I'm creating because I would have no way to create an array of differently sized objects, and I know it can't be some dynamic storage because that isn't possible to do constexpr.
It would need to have static storage duration like that of a static variable or a string literal.
I can't just declare a static variable in the middle of an expression, so ideally I could just write it as an object literal and have it go to the same place string literals get shoved into.

The "how" is the part I'm trying to figure out

For more context, this is my attempt to work around the issue:
template struct Arr{
T *data; uint32_t size;
constexpr Arr(T*p,uint32_t s): data(p), size(s){}
};

template struct inttag{};
template
constexpr Arr makeStaticArray(inttag tag, T1 first, Ts... v){
static std::array staticArray = { first, v...};
return Arr((T1*)&staticArray,(uint32_t)staticArray.size());
}
#define OPS(...) (makeStaticArray(inttag(), __VA_ARGS__))

The idea was that each template instantiation would create it's own "staticArray" which I could store a pointer to, with the __LINE__ ensuring that each of them were unique. Which would have worked except static variables aren't allowed in constexpr functions.

Anyone know where I can look to read up on how to learn Modern C++? I'll even take slightly-better-than-shit youtube tutorials.

do you know C++ already and want to know how to write modern C++?

If you dont know any C++ just read Bjarne's book and after that Scott Meyers' Effective Modern C++. And practice for a year after that.

I have a vague idea of contemporary C++, I just feel like I should probably focus on modern C++ since that's the fucking push these days, anyway.

I'm not a complete beginner in programming, so something that moves a bit faster would be fine.

OK do what this user says I don't know which book user means by "Bjarne's book" but A Tour of C++ will cover everything you need to know in breadth rather than depth

>Just read Bjarne's book
Which one?
The C++ Programming Language
Programming: Principles and Practices in C++
A Tour of C++
???

If you already know how to program and already have a little bit of experience with C++ then A Tour of C++ will be fine..

ego-death.
Go sell everything and find a buddhist mission that will take you.

I just came up with this idea:
#include

// Each unique instantiation creates a new static variable. Multiple uses of the same instantiation (eg foo = 7; x = foo) uses the
// same static variable, so this works, which is honestly pretty cool in my opinion.
// Substitute int for whatever type you want.
template
static int foo;

int main() {
foo = 1;
foo = 67;
std::cout

Employed Haskell programmer reporting in

Making a variable static in the global namespace means it can't be seen outside of this compilation unit, right?

Correct.

the (You) you wanted

I had no idea this was possible.
Thank you for enlightening me, user.

Damn I've been seeing a lot more C++ in these threads in the past few days.

im searching for a picture with a collection of different projects i saw here a while ago. anyone has it?

Its just a few people asking lots of questions which is good.

/dpt/ is comfy when its q&a

sticky disagree

Why?

Search for g programming challenges. There are tons of these

Newfag C++ is pretty good.

How did you guys or gals get started in programming? I'm going to start school on repairing computers, and 'm thinking about learning programming as well.

My uncle gave me a book about Pascal instead of sexually abusing me.

Garry's Mod game modes. Wouldn't recommend it.

Is it a bad idea to add a comment above every function (no matter how small or big) explaining what it does and a high-level view of how it does that?

Avid Python.
Try: Rust,Nim,D, and any other modern language and pick the one you hate the least.

//adding function to return two numbers
int add (int x, int y)
{
//returns the product
return x + y;
}

Yes, its obnoxious.

Doc comments are a wonderful thing

It's better than pointless language wars.

>Try: Rust,Nim,D
If he's a beginner he should try learning a language with resources outside of this thread and (in the case of Rust) a bunch of screeching trannies.

I wrote an mIRC bot sometime in the early 2000s which really kickstarted my whole interest in programming.

>gals(guys)
ftfy

I dabbled in it in highschool outside of class, but actually learned in college

Agreed

>Solid advice for a newfag:
>Avoid Python
>Try Rust, Nim, D
This is too much. Hooly fuck, it's just too fucking much, /dpt/. Damn, I am triggered, fuuuuck

Not like that, but like this:
/* ---------------------------------------
* add(x, y)
* ---------------------------------------
* adds `x` and `y`
* ---------------------------------------
* @return {int}
* the sum of `x` and `y`
*/
int add(int x, int y) {
return x + y;
}

Ironically, that's what my college insists your comments be like. To the point you get points off your homework assignments if you don't comment the living shit out of your code

Well I can speak for D as having an excellent book which i personally learned from. The docs are mostly there, but a few broken links because no one person has the active job.
explain.
Python teaches bad habits.
I hate that even more.
Learn to self-document your code. Thats only necessary if youre making a library.
awful

Roll

high school:
>Tried C for robotics, balked when I had to install some Bloodshed bullshit.
>Tried out Ubuntu, Puppy Linux. Ubuntu wasn't working with my network card so it was a lot of playing around with the control panel, same way I got used to Windows as a little kid
>Learned regex for OCR, used libreoffice writer to do all the editing
>Never really got around to programming because it seemed mostly useless when you can Google programs that already do it for you (I still think this)

college:
>Did the exercises in interactivepython.org/runestone/static/thinkcspy/Functions/thinkcspyExercises.html and actually got the hang of it
>made a newton's method PDE solver in MATLAB, learned OOP in MATLAB, got the hang of adding semicolons everywhere
>my first Java class, standard CS curriculum from there

>can i dick your gf

>that's what my college insists your comments be like.
Because they don't know how to do software development. So take everything they say with a truckload of salt.

why the fuck can't CS majors at my school indent
I don't give a flying fuck about comments, where you declare your variables, or your properVerboseVariableNomenclature, just fucking indent so I can follow the flow of logic when I try to help you

Okay I have written my C game engine.
What statically typed and memory managed language should I use with it? The engine can be used just as shared library.

C++ with a garbage collector library.

>take a language whos use-case is because of """"improved""" MMM
>add a GC to it
sasuga

How does that even perform? I can't imagine it'll perform very well, it seems more complicated to determine if an object is unreachable in sepples.

baka desu senpai

template
constexpr uint32_t count(Ts...){
return (uint32_t)sizeof...(Ts);
}

template
std::array static_options; //error: C2280: 'std::array::array(void)': attempting to reference a deleted function
#define OPS(...) Arr((option*)&(static_options = std::array{__VA_ARGS__}),count(__VA_ARGS__))


alternatively,
template
std::array static_options = {0};
#define OPS(...) Arr((option*)&(static_options = std::array{__VA_ARGS__}),count(__VA_ARGS__))
//"error: C2440: 'initializing': cannot convert from 'initializer list' to 'std::array'" x30, with N=whatever

>Had a new TA for one my programming classes
>some guy(girl)
>During an exercise, one of the guys in class raises his hand for help to get his program running
>verbally screams out "WHAT THE FUCK, WHERE'S YOUR COMMENTS? HOW THE FUCK AM I SUPPOSED TO HELP YOU?"
>For the rest of the semester, no one asks the bitch for help even though she'll sometimes walk around the class room going "Does no one seriously need help?

Is it that easy to get a TA position? Dye your hair blue and your good?

I really need to look for a new job

>work for an IT consulting firm
>"user, you will be the product owner for this project"
>you know that I will start my masters in a few weeks and don't have the time
>"whatever, just believe in yourself"

>#define OPS(...) Arr((option*)&(static_options = std::array{__VA_ARGS__}),count(__VA_ARGS__)
good lord sepples

Anyone has a good guide on how to use perf to do c++ profiling?
As of now i fail at obtaining what i could easily obtain by just using profile in netbeans when programming in java, for example.

Have fun

That's mostly just the macro being ugly, which is equally as possible in C
I could do more to clean it up but I'm just trying to get shit to work at the moment

I want to kill the fucking idiot who thaught me to see pointers are a way to allocate memory.

you should understand pointers before you learn malloc

Is that just to define Variadic args?
I cold have sworn that was already a thing.

I still don't understand pointers.

All I fucking get is a pointer is a data type "pointing" to a memory direction, and should return the same data type when dereferencing.

That's it, yeah.

>tfw the web stack is insane
I just want to target RHEL 7 as a static target, but there's no web framework I can get the full security updates until 2024 because it's not packaged.
What is a man to do? Write a CGI clusterfuck in C?

You just explained pointers. Whats there to not understand?

Read the reply chain for more information

You cant work with arrays without working with pointers.

Go + Revel framework
(Go executables are always static)

or

Scala + Play framework
= self-contained WAR archives that run on standard J2EE servers

I've had this same problem before too, I knew what the definition of a pointer was but I didn't understand it 100%. But after learning assembly and debugging some binaries I now understand pointers.

That's kind of a C meme, which is true in C and C++ but not anywhere else. There's nothing about arrays that needs working with pointers more than anything else in memory needs working with pointers. In some languages you can pass arrays by value.

is it worth it to learn swift?
i'm already on a memeBook so i figured why not

Oh, yeah, Java exists. I guess I'll go with Java. Thanks for the insight!

I'll pass on Go (interface{} is a meme) and Scala (Can we stop omitting the type of variables? It's kind of important)

Learning new languages is almost always worth it, even if you don't use them afterwards

Good concepts can be carried over to other languages
Bad concepts can be remembered as a warning sign and to fine-tune your language filter

I worked full-time with PHP for 3 years and it taught me a lot on how to recognize bad programming languages and idioms. So it wasn't really wasted time.

Java is underrated for web development,
and gets a bad rep from old-fashioned libraries like Hibernate and Spring that are terribly enterprise-y.

I worked on a J2EE app built on Jetty & Flyway and it wasn't painful at all.

I never regreted learning Pascal, even when disbeliever would drive me away from it.

k thanks

i think swift has some nice features stolen from functional programming languages so it might be fun

I wrote Java for two years [spoiler]for an IRC network[/spoiler]. I'd probably feel more at home than with Scala even after all these years. I'll look into these, thanks.

I've programed in Java and Scala and Java is pretty comfy whereas Scala feels C++esque in its devotion to throwing in everything but the kitchen sink.

Is IntelliJ still the way to go or did people hop back to Eclipse or NetBeans?

>NetBeans
I don't think anyone has shilled that in years.

IntelliJ seems to be everyone's new favorite lately, though.

39 with synthwave music would be awesome.

Java + Spring Boot

>heartbleed was caused by something like that
No that was a buffer overflow. Not related to using contiguous memory.
And regardless. If you use a half decent allocator you won't find that it allocates each allocation on a completely different page for no reason.

It's always true. Arrays are always pointers under the hood, in all languages, on all architectures. High level languages hide low level details to make programming easier, but they're still there if you pry open the hood and use a genuine low-level language.

Why would anyone competent wanna be a TA? Have you not seen your classmates?

Transgenders and such are a protected species. They're reverse-discriminated.