/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

stackoverflow.blog/2017/10/04/3-ways-can-ally-women-tech/
immersivemath.com/ila/index.html
pastebin.com/a3FmBv7T
prevayler.org
youtube.com/watch?v=mOOuuU0VUYQ
youtube.com/watch?v=tcZtGl0VWtI
youtu.be/6o47N-aYd08
youtube.com/watch?v=gWkiQ-9FEn4
youtube.com/watch?v=myhnAZFR1po
youtube.com/watch?v=DTOqwbuQq_U
pastebin.com/BcXYCzyL
twitter.com/SFWRedditGifs

First for modern opengl!

>What are you working on, Sup Forums?
A userscript for HookTube. I really like it but it lacks lots of functionality that helped make YouTube so nice to use - if you ignore the fact that YouTube is slow as fuck. Been at it for nearly a week, JavaScript is still a confusing shitheap.

Got instancing implemented yet?

You mean drawing the same element array object again and again with a different model matrix every time?

Yes. I suppose I should have said 'instanced rendering' but oh well.

Why aren't Judy arrays used more often?

I suspect it has something to do with this.
>Judy arrays are extremely complicated. The smallest implementations are thousands of lines of code.[4]

How do you search through a sorted list the fastest? There are many duplicate entries, and the amount of duplicate entries vary (50-100). I don't think binary search is optimal here. Total amount of entries is known. There are almost no gaps.

Here's my idea
>seek to totalentries/size*desiredentry
>get value
>calculate (currentvalue/currentpos)*desiredentry
>seek there
>repeat until found
Is this optimal? I'm worried about searching the last part too slowly (achilles and the turtle style). Should I do something like ((((currentvalue/currentpos)*desiredentry)-currentpos)*2)+currentpos so I "overshoot" the estimate? But this might cause it to jump around a lot, what's the optimal solution here?

Thousands of lines of code is no big deal if you compile it in (not statically link or god forbid dynamically)

Ah, the name of the algorithm I'm looking for is interpolation search.

struct struct1{
vector x;
vector y;
vector z;
};
struct1 structure;

or
struct struct2{
int x;
string y;
stuff z;
};
vector structure;


The former acts as a key/value system but is ugly imo. The latter looks better but I would need to add a forloop to search for a key every time its used.

std::map

Maybe. Still, most people will look at such a thing and say "but I can just do it this other way, my program still works great". Until there's a real need for it I think it's too complex to gain popularity outside its niche.

Use the one that you find easier to read and understand. You can always come back and change it in the future if the need arises, until then just stick to what makes your development easier.

> Judy array

www.nothings.org/computer/judy/

>'strcat': This function or variable may be unsafe. Consider using strcat_s instead.

stackoverflow.blog/2017/10/04/3-ways-can-ally-women-tech/
>Kristina Lustig is a UX Researcher at Stack Overflow.
>UX Researcher

>-ways-can-ally-women-tech/
>women-tech
>women
>tech

>reasearches how to use bootstrap for stackoverflow

In this case thats not a viable solution. In struct1, x, y, or z can act as a key and if I dont know the keys I can search by index.
struct1 is what I always do. struct2 is what I always want to change it to when I come back.

I'm sorry, this is /dpt/. You seem to be trying to post to the UX designers thread in /lgbt/.

>woman
I'm not fooled

Explain this to me
var poop = (int?) peep ?? 1;

no, use elixir

Christoph Hellwig writes:

> memcpy for strings is plain ugly. memcpy will not null-terminate
> your strings and led to source-bloat.

This is why you use

*((char *) mempcpy (dst, src, n)) = '\0';

Which is more efficient than any of the str*() functions when
concatenating multi strings since the NUL termination only has to be
done at the end.

>-fstack-protector
>-D_FORTIFY_SOURCE=2
How come I didn't know about this before?

what lang? looks maybe like C#, in which case int? indicates a nullable int

if peep is null and not int, make poop equal 1, otherwise make poop equal peep

cast peep to nullable int, if its null, then assign 1, else assign peep's value

AKARIN~
Hai!
Yuru Yuri, Hajimaru yo!

he's wrong. And how do you compute n?

I want to learn a single language and stick to it for some time to actually get good at it. Between C++ and Python which should I learn in hopes of actually getting a job without a relevant degree?

I already know the following
>C++ is massive
Yes, I could spend a decade learning it and there'd still be more shit I don't understand
>Python is a scripting language probably not suited for large, OOP projects, also not compiling = slow
This is probably true, but a better bet than Java IMO.
>Why not Java?
Java is a clusterfuck filled with quirks that I don't think I'd like to deal with. Maybe a javafag can convince me otherwise.

What do Sup Forums?

>Coddle me because im a woman

literally what shes saying

Language doesn't matter, having a portfolio of projects matters.

Java/C#/Python choose one of those if your only goal is to get hired.

>Java is a clusterfuck filled with quirks that I don't think I'd like to deal with. Maybe a javafag can convince me otherwise.
seriously? Java's very regular and sensible. Java is bad because it's too dumbed down, not because it's too complex.

I don't suppose you or anyone can point me in the right direction with this? My programming is good but my maths is kinda meh.

immersivemath.com/ila/index.html

Guys help, I'm getting interested in the ml/data ""scienece"" meme. How do I stop this?

Stop reading reddit and HN.

Any software engineers here?
Can someone help explain what the difference between abstraction and encapsulation is?

Hi guys,

I'm trying to do polynomial fit on my scatter graph in python but It's not working. Anybody care to look at my code and tell me wtf im doing wrong?

Thanks in advance.

pastebin.com/a3FmBv7T

Employed Haskell programmer here

>Between C++ and Python which should I learn in hopes of actually getting a job without a relevant degree?
Haskell

Abstraction: computers deal exclusively with numbers. If you want to deal with, say, text, it's terribly inconvenient to deal in terms of arrays of numbers, so you use a higher level abstraction, strings. Abstractions hide implementation details so you can focus on solving the problem instead of worrying about irrelevant details.

Encapsulation: hiding data and variables to make it accessible only to a limited portion of your program, so you don't get tempted to create too many dependencies that make your program harder to understand and debug.

The problem with Java is that people over-use a bunch of obtuse frameworks even in cases where the base language solves the problem just fine. Plain Old Jave Objects, POJOs, they call it, that they have a buzzword for just programming in plain Java shows how out of touch that community is. It's a bit how normal sex has now become a fetish, "cream pie".

But the language itself is fine if a bit verbose, it has way better semantics than either Python or C++.

My suggestion is to first get really good with OOP concepts (read Kaye, Fowler, et al) in a pure OOP language like Smalltalk, and then learn to apply it in Java. Too many Java codebases aren't object oriented at all, some people seem to think a few scattered class keywords in their spaghetti code makes it OOP, but it clearly doesn't.

In C++, say you have a class, which has a getter function which returns a const reference to a private member of that class. Perhaps that private member is a fuckhuge object and you don't want to copy it whenever someone tries to read it, but you still want it to be read-only. Or maybe that member is an int and you're just a faggot (or writing a memory-critical application).

Is it possible for someone using your class to fuck about with pointers and addresses to get a non-const reference to that member and thus be able to write to it? Effectively bypassing your efforts at encapsulation?

>Is it possible for someone using your class to fuck about with pointers and addresses to get a non-const reference to that member and thus be able to write to it? Effectively bypassing your efforts at encapsulation?
There's always a way. They could get the base address of the class or a neighboring variable and use pointer arithmetic.
It's fine as long as it's made clear to the user that the variable is meant to be read-only.

>Employed Haskell programmer here
I'll take two large ones to go.

How about
const& int foo() {
return read_only_int;
}

/*...*/

const int bar = foo();
int baz = *(&bar);
baz++; //you just edited the readonly variable

Would this work? Is it really that easy? Because if so, it sounds like if you ever create a pointer to something, you'd lose const without meaning to (int my_completely_innocent_ptr = &bar;
/*...*/
*(my_completely_innocent_ptr)++; //woops, forgot I shouldn't edit it)
Sounds error-prone.

fuck opengl, though

No, bar and baz aren't references. They're initialized with a reference but are separate values themselves.

If you change their declaration to const int &bar and int &baz then you 'll get this error:

>error: invalid initialization of reference of type 'int&' from expression of type 'const int'|

And in your pointer example:

>error: invalid conversion from 'const int*' to 'int*' [-fpermissive]|

If you give someone a reference, what they end up doing with it is beyond your control.

Instead of one getter for the whole object, make separate getters for the primitive bits of information in the enclosed object.

UX means user experience, so she's not even actually in tech

A function takes 3 arguments, however I want to call the function with the type of one of the arguments changed. Using C.

Is this possible at all? Trying to avoid modifying original code and writing interface(?) functions instead.

In C++ you can cast away any of those restrictions and do whatever the fuck you feel like.

Access specification is just a suggestion for your own benefit. Personally I just call everything struct and use a naming conventions to indicate whether something is "public" or "private".

I can't take her serious at all because
"Lustig" in Germans means "Funny"

This is not possible. C does not have function overloading (multiple functions with the same name but different parameter types).

However, C11 has the _Generic macro. You can name multiple unique functions, then have a macro select which of those should be called depending on the type of your arguments. Just be careful since C has a few pitfalls with the types of certain literals and macros.

Thanks

user, this code compile but is it a good way to initialize a pointer?
struct foo
{
int a;
int b;
foo(int a, int b) : a(a), b(b){}
};
class bar
private:
foo * pfoo;
public:
bar(int a, int b): pfoo(new foo(a,b)) {}
~bar() {delete pfoo}
};


My intuition said that it's better to change the bar(int a, int b) :pfoo(new foo(a,b)){}
into bar(int a, int b) {pfoo = new foo(a,b);}

which one in being considered as "good code"

...

The first one is better, I would change the pfoo(new foo(a,b)) part to pfoo{new foo(a,b)} though.

Don't use constructors, they're shit.

But if you do use constructors, try to use initializer lists as much as possible.

What do you mean with pfoo {new foo(a,b)} ??

Is the constructor became like this?
bar(int a, int b): pfoo{new foo(a,b)} {}

Is it possible to having a block with {} in the initializer list?

Yes.

It's a matter of consistency. Some modern C++ guidelines recommend you use curly braces to initialize all objects.
Foo foo{1, 2, 3};
Personally, I stick to using () for constructor calls and = {} for POD initialization.

Yes, that is what I meant. Initializing an object using {} is something they added in c++11 to "fix" some problems with syntax ambiguity when using () to initialize an object.

Care enough to clarify what is the advantage of using {} in initialize list?
All answer in SO only tell how to use it, and the advantage than using '='

Why do people like you constantly insist on reverting to 80's graphics instead of using modern platforms that do this menial labor for you?

You won't hit the Most Vexing Parse by accident. I'm not sure of the other advantages.

>If it's not broken, then don't fix it

Who are you quoting? Are you implying I said something of this nature?

What's the difference between , etc. and the variants?

is the C++ ported C library
is the native C library
I'm pretty sure, in the all of the function being included in std namespace

I'd say it depends on the regular access patterns for your data. If you're iterating only through x for example, the first one will have better cache locality. If you need to iterate through and access elements of x, y, z at the same time, the second one will do better.

How does the perl version of this look like:
curl something | grep -Po '(?

prevayler.org

This is genius, why don't people use this?

>UX Researcher at Stack Overflow
Stack Overflow is a horrible user experience.

Well, no wonder why..

SO:
>You need to have 50 reputation to make a comment

FFS SO, I know that OP's code is flawed, and I can fix it.
But the code is a bit unclear, there is more than 1 possible intention.
I just wan't to ask OP about his intention so I could answer it accurately and get some rep

Because it's called Redis

Post your programming music
youtube.com/watch?v=mOOuuU0VUYQ

youtube.com/watch?v=tcZtGl0VWtI

youtu.be/6o47N-aYd08

Redis is neat, but it has nowhere to put the business logic. You still need a separate domain model and a persistence layer, in which case you might as well use a RDBMS and get more features and flexibility for the same amount of effort.

youtube.com/watch?v=gWkiQ-9FEn4

I'm in the process of making a program that will ask the user to enter a string and then ask the user to replace a single character of that string with a character of choice. I've come to the problem to where I need the user to be able to change instances of that same character but I don't really know how to get everything connected.

I have a for loop that replaces the character they want to replace with the character they want to use and I have a for loop that counts the instance of each character they want to change.

At this point, how I would get everything to work together and have the user replace the exact instance of the character they want to replace?

youtube.com/watch?v=myhnAZFR1po

in C++, How to make a file containing unsigned char?
My idea is some kind like this, but I don't know will it really make the file contain a single "FF" byte or will it produce something weird under certain circumstances.

std::fstream foo("FOO", std::fstream::out | std::fstream::binary);
std::string bar;
unsigned char x = 255;
bar.push_back(x);
foo

youtube.com/watch?v=DTOqwbuQq_U

Have the user enter the index of the character to replace, perhaps?

Are you making a line editor? Perhaps take a look at other line editors to see how they do it.

>cast away
I assume you meant "remove by casting"?

I definitely have to have the user enter the index that they'd like to replace. If the user types in "GG" and meant "Go", then they would have to replace the first index of 'G' since java is base 0. My problem is that I can't think of a loop to make that communicate with my other loops. I've kinda gone brain dead.

Yes.

That's exactly what you said. You considered the modern options good enough. I don't know what user has in mind but there's certainly room for another system.

C/C++ users try their best to avoid using 3rd party libraries because they don't have a standard package/project/build management system.


All those "I don't need library abstractions because I'm too smart" are 100% bullshit

A module system or hack a namespace system in c would be great.

>implying 3rd party library always have a very good documentation

Sometimes, I found a really confusing documentation, and in the end I remake whole code myself.

Kek

Guys, why am I getting indent error here?

pastebin.com/BcXYCzyL

Padding might make this non-ideal/difficult.
If you want you can do #define private public. Then include the header and then #undef that.
Another way is to find a well defined state for the class and search your way into it.
That's useful for when it's a binary library. As you won't know what the binary has as it's padding.

My preference would be that you either conclude that the library should have those fields be public and make it so. Or that you replicate the fields of the class in code except with them being public and cast it to that type (given you have the source and will compile it).

Why not augment and contribute to the modern options?

Because you're using Python

Get a language without significant whitespace