/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

ghc.haskell.org/trac/ghc/wiki/Building/GettingTheSources
youtube.com/watch?v=Cn1hFo7bs7A&list=PLDTj_bVPwcYwMIm2xW6uYLBsAvNMqKVjZ
godbolt.org/g/5SLw4H
twitter.com/NSFWRedditImage

dumb clojure lisp interpreter instead of doing my homework

employed Haskell programmer here

Cute
Sauce?

Employed computer engineer here

slowly looking for something new to write, ideally with a bit of required research, might scour some new cs papers and see if any interesting developments have come up to review

need to finish some outstanding blog articles that I always have on the backburner, too

Here you go! ghc.haskell.org/trac/ghc/wiki/Building/GettingTheSources

why is this called "daily programming thread", when it sounds more like "the vagina monologues"?

Threadly reminder for the retarded niggers who don't understand how sets and subtyping work:
>C inherits from B, B inherits from A
>C is a subset of B, B is a subset of A
>(A) U (B) U (C) = A

As a massive homosexual, what is the language for me?

>massive homosexual
Haskell.

c++ is the greatest language of all time

>Is this exploitable?
Not unless you're on the same network or a node in between the client/server to sniff the password. You would also need to be able to get the client to go to login.php/ instead of login.php.

Don't know why it happens but likely a JS url splitter that makes bad assumptions.

Why does

Rust

It needs to if it accesses protected or private members, which it usually does.

Wtf is wrong with const in C++
Why is this even legal?
class foo{
public:
foo const * const bar(int const * const baz, int const & bag) const;
};

There should be a new syndrome called Seppels Const Syndrome.

Nevermind, I just read the warning and assumed that's what you were talking about. You're not even using HTTPS.

Anyway it's unlikely, unless you cause a XSS with the broken result.

DATA
DRIVEN
PROGRAMMING

which hashtable to use with C?

>I don't understand something thus the thing is wrong

>class isn't const
could be worse

>const * const bar
I don't get it

>state

>function prototype
>params and return type declared const
why tho

Learning .NET like a patrician programmer:
youtube.com/watch?v=Cn1hFo7bs7A&list=PLDTj_bVPwcYwMIm2xW6uYLBsAvNMqKVjZ

What is an ``FROB''?

Const pointer vs pointer to const

But why isn't it just a normal member function? Why does it need to be a friend function?

Const pointer (right) to const data (left)

const pointer
of what? bar?

If with this I can hide the lines of a user
.chat_line[data-nick="username"] {
display: none;
}

How can I achieve the opposite? only the lines of a certain user are shown
:not() doesn't work... I'm the retard who doesn't know

(I know that this CSS corresponds to /sqt/, please forgive me)

Have you looked at what the "friend" keyword does for functions that aren't defined inside the class? Basically your protected/private fields aren't accessible outside the class, hence the need for friend.

...

I just hate when const-tards expose const in a header.

extern int foo(const int a);
extern int foo(int const *a);

I don't care what the function does internally, that const does not affect the caller.

Yeah I know but why isn't this possible:
class foo
{
ostream& operator

That does make a difference to how the function is used and the invariants you can count on though.

bar is a method of class foo.
bar return a pointer that is a constant, to an int that is also constant.
bar accept a const pointer that point to a const int by value, and a const int by reference.
the whole bar is a const method, so it should not be permitted to modify any member of (*this)

Then the stream would have to be on the right.

How would the correct overload be chosen by the compiler const is not in the header?

...

In neither of those cases it does, it's passed by value. If the function modifies that value in (const int a vs int a) or changes where a points to (int *a vs int const *a) has absolutely no affect on the caller.

extern int foo(const int *a);

Is actually useful information.

Ah right I see now.
Thanks.

>bar return a pointer that is a constant, to an int that is also constant.
Well that's pointless. Functions generally return constant object, hence the pointer to it is going to be constant too

You're getting confused.
extern int foo(const int *a); is equivalent to extern int foo(int const *a);

extern int foo(int *const a); is leaking unnecessary details.

Be honest with me anons, I'm going into programming and want to program for computer games, am I wasting my time?

Reason I ask this is because of A.I that are advancing so fast, will they not need the majority of us anymore?

>Functions generally return constant object

Give me a counter-example

Oh, I see. Why are there 2 forms?

Do you even know what const does?

>return a constant pointer to a constant foo
>takes a constant pointer to a constant int and a constant int reference
>doesn't mutate the class
Simple as fuck, you're retarded user

I'm writing a vector calculator and using an abstract class Vector for inheritance via Vector2D and 3D.
Is there any way to have a dot product function in Vector, but have its argument defined only in Vector2D and 3D? Obviously you can't do a dot product between a 2D and 3D vector, and the function needs an argument of the same dimension.
Is there any way to declare it a pure virtual function in Vector then define it with a respective 2D or 3D vector in the other classes?

Constant is a type modifier
Can you give me a function that doesn't return a non-const object?

>a function that doesn't return a non-const object

AI doesn't matter, gamedev is already irrelevant. Real programmers will always be needed but gamedev pays like dirt and is not enjoyable for anyone but the (10+ years experienced) project leads.

>Constant is a type modifier
Wow super accurate description there my man. Did you get a Turing award out of it?
You're confusing returning by value and non-mutability.

C/C++

void fun(float in[], int size) {
//do something with in, iterating over the elements
}

float arr[] = {0,1,3,4,5,6,7};
fun(arr, sizeof(arr));


Is there any way avoiding the boiler plate code of having to send the size of the array as an explicit argument?

Not with C. With C++ use std::array.

In C++ you can use the STL stuff, in C you wrap it in a struct with a len field.

Why don't you just use sizeof() in the function?

Also use std::array

I meant return a non-const object. You should've been able to infer this.

Yeah, RVO makes sure the value is moved. Can you PLEASE give me an example where a function returns a variable? Or are you going to keep avoiding my question because you don't have an answer.

And yes, `const` is a type modifier.

You can do a bounds check inside the method itself.
e..g
void fun(float in[])
{
int i = 0;
int max = sizeof(in);
while(i < max) {
//do stuff
}
}(
Or, you know, whatever makes the most sense in the context of your function.

No. But if you have code that has a 2 Vectors and doesn't know what sort of vector they actually are, how can you safely multiply them together without casting?

The closest thing I can see is generics tbqh.

>sizeof() in the function
Doesn't work in this format, it will return the size of a pointer.

Create a slice class.

>sizeof(in)
This will get the size of a float* and is by itself a very good reason not to write "array" parameters.

vector, my main man

std::array, my man

Literally EVERY object that isn't marked const in the return type is mutable
C++ does mutable by default variables. Are you being dense on purpose?

vector everywhere, friend
vector and unordered_map together solve any problem efficiently

int fn(){ return 5;}

Do you think its returning a non-const object?

>unordered_map
>efficient
lol

There's nothing in standard C++ either since the standard committee still hasn't managed to adopt a simple slice/span/array_view type.
You could use the span type from the GSL.

>using heap allocations and worsen performance just because you can
"no"

lol xD

Not make_unique. If it returned a constant value it couldn't be used since the copy constructor of unique_ptr takes a non-const argument.

Noose

int fn(){ return 5;}
void test_const(int &&x) { x++; }
int demo()
{
test_const(fn());
}

Well... yes it is. godbolt.org/g/5SLw4H

learn about variance/covariance:
values of type C are a subset of values of type A
BUT
the members of type A are a subset of the members of type C
basically, whenever you have a function from that, it flips it around
i.e.
X A) A)

pretty shit example friendo
the compiler optimized everything into do-nothing followed by exit

You can copy a const object to a non-const object, user.

So, you are saying, the value returned by fn() will be 6 after you fed that into test_const() once?

All this does is to replace it with other boilerplate code, doesn't it?

As other said, sizeof inside the function won't work becuase the in argument decays to a pointer.

What's a slice class?

All I really want is a convenient way of initializing the values of a dynamic matrix class object.

Not all objects. unique_ptrs don't allow that

Not that there would be any way to read it.

>All this does is to replace it with other boilerplate code, doesn't it?
no buddy
you no longer need to pass in the size because std::array and std::vector can give you the size and length themselves

>It's another seppletards arguing about dumb shit /dpt/
Well this was fun

No, that's because you are wrong. The value returned by fn is copied, and test_const increments the obtained value.
int fn(){ return 5;}
void test_const(int &&x) { x++; }
int demo()
{
test_const(fn());
}

std::cout

That's the assembly output.
I think you're pretending.

You wanted to get rid of the length parameter, a std::array will carry that information (and likely at compile-time with your example) and perform what you want. You can initialize a std::array in the same way as a standard array too, (minus maybe a type specification to not auto deduce to an initializer list).

What other boilerplate do you even mean?

if the in array size is computable at compile time, then
#define IN_SIZE 7
void fun(float in[])
{}

and use IN_SIZE as the size

>That's the assembly output.
really bro? what value did this statement add to the discussion?

template
class slice
{
private:
T *data;
size_t size;

public:
template
slice(T (&arrptr)[N]): data(*arrptr), size(N) {}

// write accessors and other bullshit
}
It's pretty insulting that C++ doesn't already include this sort of thing, but at least you only have to write it once.

Your statement was fucking retarded in the first place since we're talking about the C++ type system. Of course when built with -O3 it's going to propagate every constant.

I misunderstood. What you're saying is correct in this post, but is not correct. What's being returned is a non-const copy of a const object.

Something like this?
void fun(std::array in) {
//do something with in, iterating over the elements
}
float arr[] = {0,1,3,4,5,6,7};
fun(arr);
[\code]

Would that work?

>tfw want to start function names in uppercase but the standard library and opengl a shitload of other libraries like lowercase
how do you treat autism?

this is why Nim has the true path.

std::array does not solve the problem you're describing. Don't listen to these morons.

foo {
...
}

or
foo
{
...
}
?

>values of type C are a subset of values of type A
>members of type A are a subset of the members of type C
Learn about getting professional help for your mental retardation. The only way to make sense of your post is to assume you're talking about members of an INSTANCE of a class (i.e. data fields and methods). In that case, any talk about sets and subsets is invalid. If B is derived from A, it doesn't follow that the set of fields/methods of an instance of B is a superset of the set of fields/methods of A. They can both have exactly the same set of fields and methods and still have a subtype relation.