/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

gitlab.com/rogue_test/rogue-test/commit/0164055a2daa403e4d8365c898524a8436ca1ccf
twitter.com/SFWRedditGifs

So yeah, I've made a prng.

thank you for using an anime image

nice, you should now have rogue numbers (maybe numbers with the minus sign) to run away from

Why does the size N give me garbage when I try to output it when I gave it a parameter of 9?
template
Fixed_Array ::Fixed_Array (T fill)
{
this->cur_size_ = N;
this->data_ = new T[cur_size_];
for (int i = 0; i < this->cur_size_; i++)
{
this->data_[i] = fill;
}
}

I'm working on initiating connections and different connection types for my decentralized TV system.

What's the best, most reliable, way of getting global IP addresses. I'm using checkip.dyndns.com, but that isn't reliable (and not too elegant)

Looks pretty dank m8, source code?

post source

What's the point of const if the data type I'm going to declare is mutable by default?

Hey guys, I'm writing a method for a chess board that checks if a piece is obstructing a move or attack move between two points. Am I just over-complicating it here?
public boolean isBlocked(Position pos1, Position pos2) {

//Determine if pos1 or pos2 is closer to 0,0
boolean pos1close = false;
if(pos1.getX() < pos2.getX())
pos1close = true;
else if(pos1.getY() < pos2.getY())
pos1close = true;

//Set point 1 and point 2
int x1 = (pos1close ? pos1.getX() : pos2.getX());
int y1 = (pos1close ? pos1.getY() : pos2.getY());

int x2 = (pos1close ? pos2.getX() : pos1.getX());
int y2 = (pos1close ? pos2.getY() : pos1.getY());

/**
* Number of cells is one less the difference between the two points
* on any axis (this will only ever need to check two perfectly diagonal
* points or along one axis)
*/
int checks = Math.max(x2 - x1 - 1, y2 - y1 - 1);

//Determine if we need to traverse x, y, or both cells in our check
boolean checkX = x1 != x2;
boolean checkY = y1 != y2;

//check each cell between the two points, return true if any are occupied
for(int i = 0; i < checks; ++i) {
//Positions are r/c (y/x). Only traverse x/y if they differ between points
if(pos[y1 + (checkY ? i : 0)][x1 + (checkX ? i : 0)].isOccupied())
return true;
} //end for

return false;

} //end isBlocked()

Thanks. And inb4

Wageslave here, what programming language should I learn that I can be self employed?

Reminder that non-memory managed languages are for niche uses. Most of the time, garbage collection is and should be the norm.

Do your job you fucking nigger mods. I know you dont have jobs but other do

You can pass variables in template brackets?

What do you mean? Everything is mutable by default if you specifiy const.

Memory management really isn't as hard as people make it out to be. Don't be a cuck, write performant code.

You can pass compile-time constants - this is how std::array works. Speaking of which, the user you replied to should just use std::array and std::fill to do what he needs to do.

Fuck dood just go with Java, that's the most marketable one at least

or maybe make some websites with html/javascript or maybe PHP if you're suicidal

thanks mr shark

Yes but it's sloppy

Just pass in N as a constructor argument

What does /dpt/ think of java?

It was done in like a couple of hours to learn CLOS/ncurses and is totally crap, but here you go.
gitlab.com/rogue_test/rogue-test/commit/0164055a2daa403e4d8365c898524a8436ca1ccf

meant if you don't specifiy const, of course.

/dpt/ hates and likes every language, do some research on it yourself because this thread is just another circlejerk on the internet

"Don't be a cuck" is fine for toy uses, but if you want to write large, networked applications it falls apart. Java is god.

It's terrible.

1. Widespread.
2. Easy to learn.
3. Tends to be used in larger shops when compared to say C#, so you get more interesting problem domains.
4. GREAT ecosystem. Libraries for practically everything.
5. Fast (compared to anything but C).

That being said, the language itself is basically shit. I'd say learn it though.

thats a funny way to say you struggle to write large apps with decent memory management user

make it a class (it is in Java anyways)
write a destructor
done

that's a funny way to say you've never seen the inside of a large app.

yep, I look inside it's code, not the app itself..

It along with C++ are two of the most lucrative languages to know. They're not particularly hard but you might find most Sup Forums users, lacking the necessary intelligence, do nothing but shit on them.

And yet that's the only time you're gonna see people shitting on these languages, because they're completely fine.

learn it

>completely fine
I think you should learn them because they're so big, but the languages themselves are not fine

>implying large networked applications fall apart if they are written in C
only if the developers are retarded

fine enough to make careers off of

What's wrong with them, and how does it affect using the language for its desired purpose?

>but if you want to write large, networked applications it falls apart
Any examples or do you enjoy making things up

thanks mr shark

>Any examples of C++ programs with horribly-mangled, runaway memory management?
Perhaps you should phrase your question differently because I can think of plenty. Windows ME comes to mind.

Which I guess we don't know was made mostly with C++ but what else would it be made of?

because the language and learning resources surrounding it encourage shitty practices. also state

Anyone?

redpill me on C

I don't get all the hullabaloo. What makes it so great?

What's the point of doing

typedef struct Foo {
(...)
} Foo;

instead of this?

typedef struct {
(...)
} Foo;

The latter seems to work but most code I saw used the former. Why?

Latter cannot be forward-declared, apparently.

What shitty practices?
>also state
Be more specific.

You probably can't, because there's nothing practically wrong with them. Jesus Christ, where do you guys even get this idea?

In my 4 years of university learning programming and my 2 years on the job, I've never heard anyone of authority or knowledge criticize Java or C++ in the same way that you guys do. What's the secret?

manual vs auto transmission cars, how many race cars do you know to possess an auto one?

In old C, the former allowed you to use "Foo" instead of "struct Foo", but I think that got changed at some point. Basically, there once was a time where if you didn't do that typedef, you'd have to repeat the keyword struct everytime you want to use it. Not sure though.

With these unemployed NEETs, they like to feel in control due to their inability to feel that way in their life.

Aside from writing assembly, C offers the most direct control over your system when compared to all other programming languages.

This makes it extremely good for writing drivers, firmware, and software that directly or at least closely interfaces with hardware. Unfortunately, it lacks some other elements which make it less than optimal for other tasks, where other languages like Java, C++, and Python shine

>he doesnt have a firmware / network app job in C paying 6 figures a year
poor dude

Compatibility reasons. So both "struct Foo foo;" and "Foo foo;" work.

gotcha

If you're not doing OS or other stuff where you really want that optimization is it even worth over using C++
What I mean is, where would you say the threshold of cost/benefit is with regards to what you're developing and if it's worth using OOP or not

so we race when we program?

In my experience OOP and templating and all those features made programming harder rather than easier for me, but if you're making some ping app or some doodle app then of course you aren't going to use C. You use to write serious performance-driven applications (i.e libwebsocket servers that can serve 100k people at once on a quad core ARM processor like libwebsockets)

I have a software engineering job for embedded systems, and i'll be making 6 figures in the next couple years

i am trying to write a regular expression that matches any non-defined escape sequence.
the escape sequences allowed are:
ESCAPE_SEQUENCES = \f \n \r \t \\ \"


my solution:
\'(\\\\|\\\'|\\\"|\\n|\\t|[^\\\'\n]|\\)*\\*[^\'\n]*

:: puts("Sorry. but that escape sequence is not allowed!")


can someone give me feedback?

Isn't it better to allow less ambiguity and only refer to something with one name?

whereas you'd earn 5 or less if you were a java / webdev code monkey
you race when the program runs. racing cars take time to build, just like C apps. but race cars get you 6-7 figures and all the bitches while economy cars get you a fat wife and a shitty studio apartment in manhattan

Race cars don't use traditional manuals either, they use sequentials which simplify the gear shifting and don't allow direct gear control. Only "enthusiasts" and foul-weather truckers use pure manual.

Welcome to the number one complaint programmers have with C++. And a couple features of C, but mostly C++. Backwards compatibility is a bitch.

have you contributed a single line of C code to programs that people use every day?

OOP programming is worth it in every situation but a few. If the guy above can't understand it that's his fault. OOP makes seriously developing on software in a team (read: career environment") infinitely easier, not to mention the re-usability, readability, and convenience it offers.

>so we race when we program?
precisely

I actually contributed to plenty of GTK apps and to libwebsockets, but dont get discouraged, one day you might be a programmer as competent as me if you work hard.

I personally know many java developers that make 6 figures. I'm about to be using almost exclusively C++.

You get paid on ability, not on language. C++ and Java and Python all make more money than C on average.

>OOP makes seriously developing on software in a team (read: career environment") infinitely easier, not to mention the re-usability, readability, and convenience it offers.
so basically you're saying you like OOP because you find reading code in the language of your choice difficult and struggle to manage your objects yourself, lol

>GTK apps and to libwebsockets
LMFAO
Don't get discouraged, one day you might be a programmer that makes money, like me.

>he doesnt know about FOSS funding and what libwebsockets devs get paid to do
Dont get discouraged, one day you might be a programmer that makes real money, like me

22 files changed, 1260 insertions(+), 95 deletions(-)

today was a good day

No, you're putting words in his mouth. Very few non-toy projects are one-man shows. Enforcing encapsulation makes such projects viable even with large teams of less then perfect programmers.

tl;dr: OOP is a software engineering thing more than a compsci thing

you've clearly never worked on a team developing software

fairly solid code. You could probably get rid of a few conditionals if you instead just used a conditional in the increment clause of the for loop: (pos1close ? ++i : --i)

with 95 insertions and 1260 deletions it would have been a great day

I've never worked in a team of incompetent people yeah, enjoy being happy about your 5 figures a year while Qualcomm pays us 250k to write chat apps lel
not really, top most important projects are written in C while those of lower priority are being written in meme languages such as Java, and even those are moving to the lower level right now.

The former violates DRY so I don't ever use it unless I'm contributing to an existing project which does.

Top most important projects are a tiny minority of projects with very few programmers working on them.

not idiomatic grandpa

Not everyone settles for the bottom tho

>he former violates DRY

it doesn't really, "struct Foo" and "Foo" are distinct and independent

you can do "typedef struct Foo_t Foo" if it pleases your autism

idealism is fun when you arent on the hook for anything

And I write programs in pythons of simple arithmetic operations (+, -, /, *) for 1.2m a year

talk again when you're in the 7 figures

I write infinite compilers of compilers for infinite money

literally the best language along with C++

inb4 permavirgin haskell retards shit on java and/or C++

Why is do ... while relatively rarely used compared to for and while loops?

How do you know it is?

Through having seen a lot of code in my life.

Because it's redundant.

I've used a few times for printing menus

>anecdote
Dropped.

wtf this thread has no picture.

it was a gif of helper pepe hitting a scantily-clothed anime girl's red ass with a fly swatter

java is the cutest language

hownew.ru

can you rewrite this without using goto?

use recursion?

>Python has better libraries
>C is faster
>Javascript is more portable

The only reason why you would voluntarily use java is if you want to witness the soul-sucking experience of COBOL made for the 21st century.

how would you write a regular expression to match this number?

In java, this number 1_0_0_0_0 is the same as 10000. (the underscores are used for readability)

i'm trying to write a regex that matches this number

i tried
[1-9]_[0-9]


but its not matching

please, keep in mind that

52_ is invalid
5_______2 is valid (in this case it would represent 52)

i'm not taking into account octal numbers so, i'm not starting my regex from 0

impossible to use only regex for this

how come?

regex is only good for parsing html.

hold on do you want it to just match the string?
then

[1-9]+_*([0-9]_*)*

may work fine

but regex will be unable to return only the digits.
you could always remove those after getting the match, though.

Didn't someone answer this question yesterday?

try [1-9]_*[0-9] or [1-9]*_[0-9]

Pretty sure it's the first one that would work. If the "+" symbol does what I think it does, replace the star with that. It should be 1 or more underscores. Or it won't work and I'm retarded.

>[1-9]*_[0-9]
this doesn't match 100_00_000, for example

>[1-9]_*[0-9]
doesn't work either, 100_00_000_0_2_2,, for example

this might work. thanks

>this might work. thanks
change it to this

[1-9]+_*([0-9]_*)*[0-9]


to disallow a trailing _, but i dont think that is necessary

Oops, misread your requirements.

no problem, mate

thanks again.

why did you add [0-9] at the end?

is there a string that would not be matched by the first expression you wrote, but matched by the second?