[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 318
Thread images: 19

File: 1503874178424.gif (473KB, 500x355px) Image search: [Google]
1503874178424.gif
473KB, 500x355px
What are you working on, /g/?

Old thread: >>62125667
>>
Please post an anime image next time.
>>
operator overloading is good
>>
>>62129509
PowerShell and .Net are the future
>>
>>62129536
Overloading is never good. Operators should be multimethods.
>>
>>62129509
where's the fucking trap anime image OP?
saged
>>
Is anybody here transitioning?
>>
How to make images with different contrast/brightness more "similar" to each other?
>>
>>62129638
From what to what?
>>
>>62129638
I'm trainspotting.
>>
What's the go-to language for programming on Linux?
>>
>>62129647
Male to female
>>
>>62129509
Trying to add .save, .write methods and override __repr__ for a class that inherits from list. I found some cornercases with adding and multiplying, where it returned an instance of list and not an instance of itself. Are these all or are there more cornercases?

class Framelist(list):
"""Framelist class. Extends list by being capable of saving itself."""

def __add__(self, other):
"""Override self + other to return a Framelist, not a list."""
return Framelist(super().__add__(other))

def __radd__(self, other):
"""Override other + self to return a Framelist, not a list."""
return Framelist(other) + self

def __mul__(self, number):
"""Overrides self * number to return a Framelist, not a list."""
return Framelist(super().__mul__(number))

def save(self, path):
"""Saves self into a file at specified path."""
with open(path, "w") as file:
self.write(self, file)

def write(self, stream):
"""Writes itself to specified stream."""
stream.write(str(self))

def __repr__(self):
"""Returns string representation fit for saving."""
return "\n".join([str(len(self))] + [str(frame) for frame in self])
>>
>>62129647
C++ to Rust
>>
>>62129654
Programming what?
>>
>>62129654
C#
>>
>>62129659
>Male to female
Why would anyone want to downgrade?
>>62129664
>C++ to Rust
Why would anyone want to downgrade?
>>
>>62129671
this
>>
Making a new operating system for embedded devices.
>>
>>62129691
Why not contribute to an existing one instead?
>>
>>62129691
does it have a logo yet
>>
>>62129691
Do you have recommendations for learning embedded c?
>>
File: 06664974.png (42KB, 512x323px) Image search: [Google]
06664974.png
42KB, 512x323px
I've seen people click on a word in visual studio, have it highlight every instance of that word then when they edited the word it edited every instance.
How do I do that?
>>
>>62129691
Please post your code of conduct, I need to know if I'm safe to expose myself by contributing.
>>
>>62129706
How is embedded C different from regular C? You just learn C and then learn API for whatever platform you're using.
>>
>>62129714
No niggers and spics allowed.
>>
>>62129714
No niggers or tranneis allowed.
>>
>>62129733
t. spic
>>
>>62129712
CTRL + R
>>
>>62129740
Get out, tranny.
>>
>>62129699
>>>62129691 (You)
>Why not contribute to an existing one instead?
Proprietary and confidential restrictions.
>>
>>62129712
install vim
:set hlsearch
/<your word>
>>
Why is this not allowed?
/*Write a program that asks the user to enter the number of pancakes eaten for
breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Modify the program so that it outputs a list in order of number of pancakes
eaten of all 10 people.*/

#include <iostream>
#include <utility>
#include <string>
#include <array>
using namespace std;

struct entry {
public:
string name;
int pancakesEaten;
entry(string& givenName, int givenPancakes)
: name(givenName), pancakesEaten(givenPancakes) {}
};

entry getEntry() {
string personName;
int pancakesEaten;
cout << "Enter person name: " << flush;
getline(cin, personName);
cout << "Pancakes Eaten";
cin >> pancakesEaten;
return entry{personName, pancakesEaten};
}

int main() {
array<entry, 10> entries; // not allowed
for (int i = 0; i < 10; i++) {
entries[i] = getEntry();
}
}
>>
>>62129679
>C++ to Rust
>Downgrade
>>
>>62129748
Is it really reasonable to write your own proprietary embedded OS nowadays? There're dozens FOSS ones out there ready to be used, some of them aren't GPL.
>>
>>62129760
it should be
>>
def get_events(event):
# pass this var outside of this
var = event
raise EventLoopStop

def event_wait():
event_callback_set(get_events)
event_listen()

while True:
event_wait()


What's the best way to use "var" from get_events() in the global scope?
I have used a list in the global scope to which I append things from inside get_events(). I can also use global var inside of get_events(), but in my beginner programming books it said that using global variables in functions is bad. Like this:

Global variable solution:
def get_events(event):
global var
var = event
raise EventLoopStop

def event_wait():
event_callback_set(get_events)
event_listen()

while True:
event_wait()


List solution:
def get_events(event):
my_list.append(event)
raise EventLoopStop

def event_wait():
event_callback_set(get_events)
event_listen()

while True:
my_list = []
event_wait()


Is there a definitive way to handle this?
>>
>>62129760
>>62129780
wait, maybe because there isn't a default constructor?

>40s to post
>>
>>62129780
But it isn't
>>
>>62129776
>>>62129748 (You)
>Is it really reasonable to write your own proprietary embedded OS nowadays? There're dozens FOSS ones out there ready to be used, some of them aren't GPL.
I get paid more and get to have fun writing it.
Plus I get paid to maintain it.
>>
>>62129760
>>62129788
Yes, it compiles fine when you add one.
>>
>>62129780
>>62129760
Why should it be allowed?

This is what you want
array<entry> entries(10);
>>
>>62129788
>entry(string& givenName, int givenPancakes)
> : name(givenName), pancakesEaten(givenPancakes) {}
>>
How do people typically examine and parse files never parsed before? Say no one's ever seen an MP3 before and it's used for some little program. Would you use a hex editor to discover the lastingSorry 128 bytes are ID3 info? Now that you have that information, how do you usually go manipulating it with no prior documentation.
>>
>>62129800
No

>>62129801
Not a default constructor, i.e.

entry()
>>
>>62129652
>>>/n/
>>
>>62129542
>PowerShell and .Net are the future
>calling anything microsoft the future
yikes, do you program professionally?
>>
>>62129807
You usually check if it's plaintext first, if it is then it's probably not hard to understand.
If not then well, check the internet if there's a doc or something.
If all fails scoop around with hex editor and try to match known values. It's hard and mostly throwing shit at a wall and seeing what sticks.
>>
>>62129798
GCC really should work on the error messages, compare
<source>: In function 'int main()':
26 : <source>:26:20: error: use of deleted function 'std::array<entry, 10>::array()'
array<entry, 10> entries; // not allowed
^~~~~~~
In file included from <source>:4:0:
/opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/array:94:12: note: 'std::array<entry, 10>::array()' is implicitly deleted because the default definition would be ill-formed:
struct array
^~~~~
/opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/array:94:12: error: no matching function for call to 'entry::entry()'
11 : <source>:11:3: note: candidate: entry::entry(std::__cxx11::string&, int)
entry(string& givenName, int givenPancakes)
^~~~~
11 : <source>:11:3: note: candidate expects 2 arguments, 0 provided
7 : <source>:7:8: note: candidate: entry::entry(const entry&)
struct entry {
^~~~~
7 : <source>:7:8: note: candidate expects 1 argument, 0 provided
7 : <source>:7:8: note: candidate: entry::entry(entry&&)
7 : <source>:7:8: note: candidate expects 1 argument, 0 provided
Compiler exited with result code 1

with clang's
26 : <source>:26:20: error: call to implicitly-deleted default constructor of 'array<entry, 10>'
array<entry, 10> entries; // not allowed
^
/opt/compiler-explorer/gcc-7.1.0/lib/gcc/x86_64-linux-gnu/7.1.0/../../../../include/c++/7.1.0/array:110:56: note: default constructor of 'array<entry, 10>' is implicitly deleted because field '_M_elems' has no default constructor
typename _AT_Type::_Type _M_elems;
^
1 error generated.
Compiler exited with result code 1
>>
>>62129808
>Not a default constructor, i.e.
>entry()
Not entirely sure how am I suppoed to make it work.
>>
>>62129838
Well you can't anyway because it uses a T&.
>>
>>62129838
entry() {} in your class shuld work fine.
>>
>>62129838
std::string name = "";
int pancakesEaten = 0;
entry() = default;
>>
>>62129807
Find a proprietary program operating on such files and reverse engineer. Analyze the binary code. Introduce tiny changes in files and observe how the program reacts. It's a tedious process.
>>
>>62129838
>Not entirely sure how am I suppoed to make it work.
All members are non-const and public.....
>>
>>62129855
>>62129859
But I want to make that default constructor inaccessible. In fact,
/*Write a program that asks the user to enter the number of pancakes eaten for
breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Modify the program so that it outputs a list in order of number of pancakes
eaten of all 10 people.*/

#include <iostream>
#include <utility>
#include <string>
#include <array>
using namespace std;

struct entry {
public:
string name;
int pancakesEaten;

entry(string& givenName, int givenPancakes)
: name(givenName), pancakesEaten(givenPancakes) {}

private:
entry() {}
};

entry getEntry() {
string personName;
int pancakesEaten;
cout << "Enter person name: " << flush;
getline(cin, personName);
cout << "Pancakes Eaten";
cin >> pancakesEaten;
return entry{personName, pancakesEaten};
}

int main() {
array<entry, 10> entries; // not allowed
for (int i = 0; i < 10; i++) {
entries[i] = getEntry();
}
}
>>
>>62129859
Actually, just `entry() = default` is fine, the fields will be default-constructed anyway.
>>
>>62129892
I think you have to fill the array at initialisation
>>
>>62129892
Then you can't use an array, because an array has a fixed size and hence requires all members filled at the point of initialisation.

You could do
array<entry*, 10>
or
array<std::optional<entry>, 10>
>>
>>62129905
>>62129911

Damn. I'll just use vector instead
/*Write a program that asks the user to enter the number of pancakes eaten for
breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Modify the program so that it outputs a list in order of number of pancakes
eaten of all 10 people.*/

#include <iostream>
#include <utility>
#include <string>
#include <vector>
using namespace std;

struct entry {
public:
string name;
int pancakesEaten;

entry(string& givenName, int givenPancakes)
: name(givenName), pancakesEaten(givenPancakes) {}

private:
entry() {}
};

entry getEntry() {
string personName;
int pancakesEaten;
cout << "Enter person name: " << flush;
getline(cin, personName);
cout << "Pancakes Eaten";
cin >> pancakesEaten;
return entry{personName, pancakesEaten};
}

int main() {
vector<entry> entries; // allowed
for (int i = 0; i < 10; i++) {
entries[i] = getEntry();
}
}
>>
>>62129892
But the array will try to construct 10 entries when it constructs itself and it'll want to use the default constructor for that.
You can work around that by using std::vector.
>>
>>62129509
What's the correct way to add a couple of functions and override a function for a class? I tried two approaches, both seem to be bad:

1) Just add some functions that operate on the class. But this mixes procedural programming with OOP.
2) Inherit the class. This leaves you with all kinds of cornercases where parent class returns itself and not the child and you have to catch them all.

What's the right way to do it?
>>
>>62129831
>>62129862

Thanks for the pointers. Also sorry for the typos.

t. phoneposter
>>
File: pro.png (2KB, 797x598px) Image search: [Google]
pro.png
2KB, 797x598px
>>62129509
>be me, work construction. Fuck up my knees
>pick up programming as a way to get a non physical job
>litterally making the easiest and shittiest codes
>never had so much fun in my life
>>
>>62129663
>Dynamically-typed languages
>>
>>62129934
Do you want class methods or plain functions that take class objects as argument?
>>
File: 3029382.png (5KB, 304x21px) Image search: [Google]
3029382.png
5KB, 304x21px
>>62129742
>>
Now I got one more question
struct entry {
public:
string name;
int pancakesEaten;

// notice the string&
entry(string& givenName, int givenPancakes)
: name(givenName), pancakesEaten(givenPancakes) {}

private:
entry() {}
};

entry getEntry() {
string personName;
int pancakesEaten;
cout << "Enter person name: " << flush;
getline(cin, personName);
cout << "Pancakes Eaten";
cin >> pancakesEaten;
return entry{personName, pancakesEaten};
}


As the constructor takes a reference to a string, will the constructor get erroneous argument because the string is leaving the getEntry() scope?
>>
>>62129991
I haven't used VS for a while but that worked for me, try pressing R again?
>>
>>62129992
It will copy construct it anyway.
>>
>>62130005
That's it, thanks.
>>
>>62129983
I would prefer class methods because it doesn't mix procedural programming with OOP.
>>
File: 15006286503.jpg (163KB, 1024x768px) Image search: [Google]
15006286503.jpg
163KB, 1024x768px
PROGRAMMING CHALLENGE

Make a £sd calculator. It must be able to add, subtract in £sd, multiply and divide by decimal fractions. Lowest coin is farthing.

So far, we have a solution in APL and J!
What other languages will present /g/ later?
>>
>>62129992
std strings have a fine copy constructor, it should work ok.
Mixing cin with getline will fuck up your I/O, though.
>>
>>62130043
>Mixing cin with getline will fuck up your I/O, though.
Oh boy. Thanks.

I wonder how many more corner cases there are.
>>
>>62130018
If they compliment the class functionality as a whole, add them to the base class, if they are something new, make a new class that inherits.
If you can't easily come up with a name for the derived class then probably adding to base is the better option.
Of course, you can do something like make a new class that has the base class as a member and add the functions there with some wrappers for the base class. That way you avoid a hard dependency.
>>
Anons, which notebook is best with price < $1000?
>>
>>62130089
I use HP compaq, I bought it new for 200 euro over 2 years ago, runs lubuntu without any problems
>>
What's an inline static virtual variadic extern anonymous constant friend function?
>>
>>62130115
>inline
you can declare it in a header
>static extern
can't be. it's either one or another. static is for traslation-unit linkage, extern is for global linkage.
>virtual
dunno
>anonymous
dunno
>constant
dunno
>friend
dunno
>>
>>62130115
>error: virtual functions cannot be friends

I learn something new about C++ every day.
>>
>>62130145
>can't be. it's either one or another. static is for traslation-unit linkage, extern is for global linkage.
What if it's static in sense that it can only access the static variables in the class?
>>
>>62130115
>>62130145
Since some of those are class method exclusive I'm assuming it is a class method.
>inline
This basicaly asks the compiler to put the code directly into the assembly of whatever called the function instead of calling it.
>static
Independent from class instance
>virtual
Can be overriden by a derived class
>variadic
Has variable number of arguments
>extern
Not sure if it even works in class methods
>anonymous
Doesn't have a name, duh (for example a lambda)
>constant
Can't modify whatever it's called on
>friend
Has access to private and protected fields
>>
>>62130115
>>62130145
>>62130197
>>62130234
Why do you use a language one cannot master?
>>
>>62130247
I don't use C++. I answered this question from C perspective.
>>
>>62130238
>>inline
>This basicaly asks the compiler to put the code directly into the assembly of whatever called the function instead of calling it.
It does nothing besides allowing to declare it multiple times in a header. It does literally nothing else. It's a hint.
>>
>>62130247
You can't master English either and you insist on using it.
That's an extreme corner case anyway, reminds me of shit they put me through at uni. Never used any of the weird syntax they pulled out of their asses.
>>
>>62130247
Lies, I am proficient with 100% of the features of this programming language
>>
>>62130280
I don't do English for a living
>>
>>62130278
gcc interprets inline as asking to make a function faster and it can actually achieve that by inlining it in the assembly
>>
>>62130307
>gcc interprets inline as asking to make a function faster and it can actually achieve that by inlining it in the assembly
It's a hint. The compiler inlines *all* the functions where it sees that fit.
>>
>>62130325
It's like a register keyword, which nowadays is *completely* useless. The inline keyword at least lets you to define the function multiple times.

Compiler is free to ignore it.
>>
>>62130297
I don't do C++ for a living either. I'm paid to solve problems, not know all the obscure features of arbitrarily chosen language.
I'm a Java dev actually and I google most of the Java 8/9 features when at work since you can't possibly remember them all.
>>
>>62130339
> register keyword, which nowadays is *completely* useless
`register` has actually been removed in C++17, now it's an unused reserved word.
>>
>>62130382
Still there in C11.
>>
>>62130390
I don't think any of the popular compilers takes register seriously. It's still reserved in C++17 though so it's open for some cool macro use.
>>
why do some websites work with
https://www.website.com/index.html


but not

https://www.website.com/index
>>
>>62130418
It depends on their backend.
>>
>>62130412
I hope they remove this C feature and C22.
void func(int array[static 1]);
>>
File: Screenshot_2017-08-28_15-38-40.png (28KB, 539x216px) Image search: [Google]
Screenshot_2017-08-28_15-38-40.png
28KB, 539x216px
>>62130339
>>62130390
>>62130382
>register is useless

#include <stdio.h>

int main(void)
{
int n = 0;
#ifdef REGISTER
register int i;
#else
int i;
#endif
for (i = 0; i < 2000000000; i++)
if (i % 15 == 0)
n++;
printf("%d\n", n);
return 0;
}


>It's a hint. The compiler inlines *all* the functions where it sees that fit.
It's a storage qualifier. Not related to function inlining.
>>
>>62130412
See >>62130456
>>
>>62130452
I wish they allowed programmers to give more constraints to types, like, say, the effective range of a variable, the possible sizes of an array etc.
>>
>>62130287
Oh yeah? Write a pointer to a method that returns a pointer to a method and assign it a valid value.
>>
>>62130482
Use Agda
>>
>>62130456
>
#ifdef REGISTER
register int i;
#else
int i;
#endif


never thought of doing this check

nice
>>
>>62130487
Does Agda have C-compatible types? Is it even compiled?
>>
>>62130507
you can FFI to Haskell and then in Haskell FFI to C
>>
>>62130482
>I wish they allowed programmers to give more constraints to types, like, say, the effective range of a variable
In sepples you can do this with enum class.

>the possible sizes of an array etc.
void foo(int array[10]);
>>
>>62130485
My time is precious I don't waste it on trivial and futile challenges
>>
>>62130532
yet you're posting here.

kys
>>
>>62129992
THIS HERE is the problem Rust addresses. Too bad /g/ hates it irrationally
>>
>>62130583
don't disturb me I'm an important C++ person who programs real things
>>
>>62130418
The address after the .com/ doesn't usually represent any real path. The server maps it to some handler or file however it sees fit. Some route index and index.html to the same place, some don't route them anywhere.
>>
>>62130606
name 1 thing useful you've programmed in C++.
>>
>>62130530
Enums are a bit of a hack though, I meant it more as a nonintrusive compiler hint. Also IIRC the standard does not require size to be checked unless you put static, in which case it must be at least as big.

>>62130485
void (*(*x)(int, void (*)(int)))(int) = &signal;
>>
>>62129520
It's an anime image, from PC-98 game.
>>
>>62130619
my last job was C++. reverse engineering and static analysis tools for vulnerability detection
>>
>>62130620
>Enums are a bit of a hack though,
Well, keep in mind the difference between enum classes and enums, but yeah.

>I meant it more as a nonintrusive compiler hint.
That would be very nice indeed.

>Also IIRC the standard does not require size to be checked unless you put static,
No, that is when you use a variable to define the size, because it needs to have a static storage qualifier. When using an integer literal, it can have no other value obviously.
>>
>>62130456
It's useless, try compiling with -O2 next time.
>>
>>62130619
Useful is relative. I programmed quite an extensive Brainfuck interpreter and compiler. It's useful to me, because I like to play with Brainfuck quite a bit. It's called "Brainfunk" in github, look it up if you want.
>>
>>62130665
This is trivial for a compiler to optimise. My point is that register is useful in situations that aren't so trivial to optimise, and certainly not something we should just throw out of the window.
>>
>>62130669
Adam?
>>
>>62130704
I don't think there's a code in which `register` would result in a better code than -O3, yet I'm aware of code that works slower with `register`. In any case, it is some leaky abstraction (the standard doesn't require the machine to have registers, to begin with), premature optimization and an anachronism from the 80s, I think the committee was right removing it.
>>
>>62129509
Hey anons, C newbie here so forgive me if I fuck up the terminology.

I need to translate some matlab executables (.mex) to something python can talk to.

I've managed to compile some shared objects that I can succesfully execute from python.

However, for certain shapes of input arrays, the output from the python shared objects is quite different to that returned by the mex version.

My question really is - is it possible the matlab compiler is producing something different to gcc, assuming im linking the same libraries? As far as I am aware the C source files are identical besides the matlab-specific interface includes.
>>
File: 1503826862937.gif (915KB, 245x285px) Image search: [Google]
1503826862937.gif
915KB, 245x285px
Lads, shouldn't this code use move constructor and move every item from vector? Why does second cout in the code still print original vector items after i moved them with std::move?

C++ move semanthics and other stuff are pretty weird but still entertaining. Someone explain plz.

#include <QCoreApplication>
#include <iostream>
#include <cstdio>
#include <vector>


class VectorDisp {
public :
VectorDisp(const std::vector<std::string> & vec) : _vect(vec){}
VectorDisp(const std::vector<std::string> &&vec) : _vect(std::move(vec)) {}
void DisplayVect(const VectorDisp &);
private :
std::vector<std::string> _vect;
};

void VectorDisp::DisplayVect(const VectorDisp & vectorDisp) {
for(auto i : vectorDisp._vect) {
std::cout << i << std::endl;
}
}

int main() {

std::vector<std::string> vector {"Jamie", "Ninja", "Zero", "Kaka", "Ronaldinho", "Coutinho"};
VectorDisp VEC(std::move(vector));
VEC.DisplayVect(VEC);
for(auto i : vector) {
std::cout << i << std::endl;
}


}
>>
>>62130798
>I need to translate some matlab executables (.mex) to something python can talk to.
why
>>
>>62130763
Okay, first of all I need to point out that the storage qualifier "register" does not mean "use a register for this variable" at all, it simply indicates to the compiler that this variable is likely to be accessed a lot, please use some form of fast storage. It's especially useful on NUMA architectures that combine both cache-coherent memory with non-cache coherent memory.

Which brings me to my next point: -O3 can be overly aggressive. There are cases where -O2 and -O3 will lead to optimisation that change the result of a computation, especially if implementation defined behaviour exist in the code (inb4 "hurr durr don't rely on implementation defined behaviour", this happens all the time in embedded programming).

>I think the committee was right removing it.
It's not removed in C, what are you talking about?
>>
>>62130826
They are part of a (large) algorithm I need to translate to python
>>
>>62130816
remove const from the move constructor (because you'll be modifying the vector whose elements you're taking)
>>
>>62130816
>lads
Did you just assume my gender?
> VEC.DisplayVect(VEC);
What are you even trying to do here?
>>
>>62130906

Now it worked, thank you. I overlooked that. Completely removed items from original vector and prints nothing.

Is C++ move any great improvement compared to copying?
>>
>>62130915
>Did you just assume my gender?
what do you mean?

there are no girls here.
>>
>>62130816
Your move constructor is wrong, in two places.

>const
A move constructor needs a mutable rvalue reference, not a const rvalue reference.

>std::move
There's no need to std::move what is already an rvalue reference.

You want the following:
    VectorDisp(std::vector<std::string> &&vec) : _vect(vec) {}
>>
Okay no I got an array of structs. How can I use std::sort to sort the array by using a particular public member variable of those structs?

Do I need to manually write down the sorting algorithm each time?
>>
>>62130943

it doesn't work without std::move in constructor code now after i removed it
>>
>>62130943
>There's no need to std::move what is already an rvalue reference.
I'm pretty sure you're wrong about this one
>>
>>62130873
>There are cases where -O2 and -O3 will lead to optimisation that change the result of a computation
hurr durr don't rely on implementation defined behaviour. Jokes aside tho, how do you even consider it acceptable? You might as well write `*(int*)0` because fuck it.
> It's especially useful on NUMA architectures that combine both cache-coherent memory with non-cache coherent memory.
False, compiler knows nothing about NUMA, it's an OS issue.
>It's not removed in C, what are you talking about?
C++17.
>>
>>62130943
> There's no need to std::move what is already an rvalue reference.
A common misconception, `const std::vector<std::string> &&vec` is bound to an rvalue, but it's an lvalue itself so you have to use std::move to move from it.
>>
Is there some cross platform(pc,mobile operating systems) GUI library that exports C API?
Currently I have SDL handling events and windowing and draw the GUI with nuklear which is backend agnostic.
>>
>>62130949
std::sort accepts a comparator, either use that or implement operator< for your struct
>>
>>62131059
Thank you
>>
>>62131031
You could possibly use clang to compile to LLVM and then from there to wherever you want, emscripten compiles even to JavaScript
>>
>>62130983
>Jokes aside tho, how do you even consider it acceptable?
It's preferable to avoid it, but C is a high-level language after all, and a very minimalist one too. It simply isn't possible to express dependencies such as memory fences without relying on implementation-defined behaviour and using stuff like the volatile qualifier. For example, imagine a scenario with memory-mapped IO, where writing to one register and expecting another register to change. Without any qualifiers (such as declaring your pointers volatile), an optimising compiler will not "know" that memory may have changed and that it needs to invalidate the cache with an explicit flush.

Another example is pointer aliasing, which require compiler extensions to even detect.

>False, compiler knows nothing about NUMA, it's an OS issue.
A compiler can produce NUMA-aware byte code, such as explicit cache flushing, what are you on about? All major compilers support this, hell GCC even has compiler intrinsic for doing this on Intel architectures.

>C++17.
Ah, for C++. Well it makes little sense in a language that supports type inference and has semantics for compound types. But it still makes sense in C.
>>
>>62131031
What more do you expect of a GUI library that nuklear does not provide? I have a small experience of GL and nuklear for portable GUIs and it was alright, as long as you can live without native menus and dialogs.
>>
>>62130325
also, llvm ir (thats what clang and other llvm-based compilers produc) has finer control over inlining, gcc does not always inline things marked as inline, on the other hand in lvm ir there is an option to prefer inlining, always inline and never inline
>>
Can I get a quick rundown on rust enums?
>>
>>62131180
They act like tagged unions
>>
File: Screenshot_15.png (6KB, 346x89px) Image search: [Google]
Screenshot_15.png
6KB, 346x89px
anybody into competitive programming ?
>>
following along the cs50 course, what are some of the most commonly used or "essential" C libraries?

#include <stdio.h> what else? did someone not make like a huge library that just has everything useful?
>>
>>62131152
GCC has the always_inline attribute, and moreover it also has gnu_inline which omits the compilation of the standalone function.
But anyway Common Lisp is superior to both, it has standardized declarations to demand inlining at call sites, instead of a per-function basis.
>>
I already know java and c++, what are some 10/10 tutorials for other languages? I think I need to learn some Web development.
>>
>>62131137
Well some animations would be nice. Supporting html and css might be something, not sure if I even want that but nuklear is kind of limited.
It works but if there was something similar which had more features I would swith to it.
>>
>>62131133
> Without any qualifiers, an optimising compiler will not "know" that memory may have changed and that it needs to invalidate the cache with an explicit flush.
So you declare it volatile, it's not a UB and will work the same with both -O2 and -O3. I still think that if your code doesn't work with O3 you're doing something wrong, even if the code in question is some low-level stuff.
> A compiler can produce NUMA-aware byte code, such as explicit cache flushing, what are you on about?
No? There is no "numa" option for gcc, the code is the same. The only way to "use" NUMA is to use specialized syscalls to get the right type of memory. But assuming gcc knows something about NUMA, `register` can only be used inside a block, so the value is either on the stack or in a register, there is no way `register` can interfere with NUMA.
>>
>>62131310
There isn't.
>>
>>62131413
but it's 2017. SAD.
>>
>>62131341
>So you declare it volatile, it's not a UB and will work the same with both -O2 and -O3
I said implementation-defined, not undefined. Those are very different. MMIO is essentially one giant heap of implementation-defined behaviour anyway.

>I still think that if your code doesn't work with O3 you're doing something wrong, even if the code in question is some low-level stuff.
You would be wrong in thinking that.

>No? There is no "numa" option for gcc, the code is the same.
You don't understand what NUMA is. NUMA can be the example I explained in my post, where you memory-map device memory into your address space, and where writing to one memory address means that other memory can change, and you need to invalidate your pages because your cache is now inconsistent.

>The only way to "use" NUMA is to use specialized syscalls to get the right type of memory.
First of all, it's not "specialized syscalls", as most, if not all, architectures that support paging also have instructions to invalidate pages. So it's a matter of hardware instructions, not system calls.

Secondly, syscalls are a perfect example of implementation-specific behaviour. You can't take your POSIX program and expect it to run on Windows. Even among NIXes, there are inconsistencies.

>But assuming gcc knows something about NUMA, `register` can only be used inside a block so the value is either on the stack or in a register, there is no way `register` can interfere with NUMA.
Frequently invalidating your page cache means that you might evict your stack if you're working with large enough memory, and cache eviction on a variable used in a tight loop will have a performance penalty. Using the register keyword can ensure that a variable isn't stored in RAM, meaning that cache eviction has no effect on it.
>>
File: register.png (23KB, 594x113px) Image search: [Google]
register.png
23KB, 594x113px
>>62131531
>Using the register keyword can ensure that a variable isn't stored in RAM, meaning that cache eviction has no effect on it.
not him but found this in the standard
>>
>>62131585
Is that supposed to contradict what I am saying? Because it's essentially the opposite, it's saying that you can't take the address of a variable declared as auto or register.

Which makes perfect sense, because a variable declared as register may not reside in any addressable memory at all aka it's stored in a register.
>>
>>62131531
>You would be wrong in thinking that.
[Not that guy]
Can you give a single example where an aggressive yet compliant optimizer changes the meaning of your code, where you feel you are NOT doing something wrong?
>>
>>62131643
No, it just means it can reside in RAM, but you can't take an address of it. It's just a restriction, the compiler is not forced to actually put it into register.
>>
>>62131531
It looks like we have different understandings of what NUMA is, I'm basing mine on http://man7.org/linux/man-pages/man7/numa.7.html , it has nothing to do with cache, only with some physical memory being "closer" to the current CPU than another.

>NUMA can be the example I explained in my post, where you memory-map device memory into your address space, and where writing to one memory address means that other memory can change, and you need to invalidate your pages because your cache is now inconsistent.
I think you're confusing NUMA with DMA.

>So it's a matter of hardware instructions, not system calls.
No? The instructions are the same, the difference is in the physical memory you're using, and you need syscalls to specify it. Citing above:
>The Linux kernel implements the following NUMA-related system calls: get_mempolicy(2), mbind(2), migrate_pages(2), move_pages(2), and set_mempolicy(2).

>Frequently invalidating your page cache means that you might evict your stack if you're working with large enough memory, and cache eviction on a variable used in a tight loop will have a performance penalty.
This is has nothing to do with NUMA, and a compiler can do it automatically.

>You would be wrong in thinking that.
Yeah, well, I don't think so. At least in my experience, every time the optimization level broke something, the problem was with the code.
>>
>>62131658
>Can you give a single example where an aggressive yet compliant optimizer changes the meaning of your code,

I can give you a real-life example: https://lkml.org/lkml/2003/2/26/158

>>62131675
>No, it just means it can reside in RAM, but you can't take an address of it. It's just a restriction, the compiler is not forced to actually put it into register.
That's why I explicitly said CAN though. Also my post >>62130873 , which I clearly state that the register qualifier doesn't automatically mean use a register.
>>
>>62131737
>That's why I explicitly said CAN though. Also my post >>62130873 , which I clearly state that the register qualifier doesn't automatically mean use a register.
Then you're right on that.
>>
>>62131712
>It looks like we have different understandings of what NUMA is, I'm basing mine on http://man7.org/linux/man-pages/man7/numa.7.html , it has nothing to do with cache, only with some physical memory being "closer" to the current CPU than another.
Reading and writing to on-board device memory is NUMA, by this definition as well.

>I think you're confusing NUMA with DMA.
No, DMA means that a device writes to RAM (which also means that memory change), but I am talking about MMIO (aka PIO) in my example.

>No? The instructions are the same, the difference is in the physical memory you're using, and you need syscalls to specify it. Citing above:
See below.

>This is has nothing to do with NUMA, and a compiler can do it automatically.
A compiler can not make a distinction between cache-coherent memory and non-cache-coherent memory.

>Yeah, well, I don't think so. At least in my experience, every time the optimization level broke something, the problem was with the code.
See >>62131737
>>
>>62131219
I did two time limited contests, and I disliked it.
Those were competitions where quality means nothing. The time to solve the problem was a criteria for ranking, so it was only a matter of who could shit the solution the fastest regardless how awfully it was written, as long as it would output the expected result.
I didn't do too bad, but I'm not interested in renewing the experience.
>>
>>62131805
> Reading and writing to on-board device memory is NUMA, by this definition as well.
Only in as much as the memory has different access performance for different CPUs.
> I am talking about MMIO (aka PIO) in my example
So you're confusing NUMA with MMIO.
> A compiler can not make a distinction between cache-coherent memory and non-cache-coherent memory.
A compiler has only two options for local variables - stack or register, it doesn't care about cache-coherent memory.
>-fno-strict-aliasing
Linus is clearly being wrong here, his solution is basically to not give a fuck about standard-compliance, something gcc guys do care about. Thanks to this mindset it's practically impossible to compile the kernel with icc or clang, despite both being fully standard-compliant compilers.
>>
>>62131934
>Only in as much as the memory has different access performance for different CPUs.
No, it also affects caching because most far memory isn't cache-consistent, even though RAM may be.

>So you're confusing NUMA with MMIO.
MMIO _is_ NUMA. You don't have to use an API to do NUMA, you can memory-map device memory manually.


>A compiler has only two options for local variables - stack or register, it doesn't care about cache-coherent memory.
First of all, "stack" means memory. Secondly, I was talking about when your memory page containing your stack frame gets evicted, which means the next time you access the variable, you have to go to RAM. This has a considerable performance penalty, which is why you'd prefer the compiler to optimise so this doesn't happen.

Secondly, the fact that the compiler doesn't know about cache consistency is precisely the problem and why its own optimisation is insufficient.

>Linus is clearly being wrong here
I get it, "everybody is wrong except me", right?
>>
>>62129671
kek
>>
>>62132019
> MMIO is NUMA
No? NUMA is about different CPUs having different access times, read the wiki, ffs.
> the fact that the compiler doesn't know about cache consistency is precisely the problem and why its own optimisation is insufficient.
The compiler can't control where the OS puts stack, so cache-coherency is totally irrelevant for it. The only difference `register` makes is to where put the variable, on the stack or in a register, and any sane compiler can make this decision better than a programmer.
> I get it, "everybody is wrong except me", right?
It's more "Linus isn't always right just because he's Linus", strict aliasing is a valid optimization and if it breaks your code then your code is shit.
>>
>>62129654
Write in C https://www.youtube.com/watch?v=1S1fISh-pag
>>
Refactoring
https://pastebin.com/ap7g3ydv
>>
>>62132161
>No? NUMA is about different CPUs having different access times
>read the wiki
And what the hell do you think happens when you have a shared memory architecture between multiple computers in a PCIe cluster, for example.

https://en.wikipedia.org/wiki/Non-uniform_memory_access#NUMA_vs._cluster_computing

Or battery-backed RAM connected on your PCIe bus?

In both these cases, you write to memory with a vastly different access time than system RAM, because it's memory that reside on your IO bus rather than on your memory bus.

And by the way, caching _is_ a major considerations in NUMA architectures:

https://en.wikipedia.org/wiki/Non-uniform_memory_access#Cache_coherent_NUMA_.28ccNUMA.29

>The compiler can't control where the OS puts stack, so cache-coherency is totally irrelevant for it.
For the last fucking time, it is irrelevant to the compiler (because it doesn't know), but it is not irrelevant to you, the programmer.

>The only difference `register` makes is to where put the variable, on the stack or in a register, and any sane compiler can make this decision better than a programmer.
Except, you know, in cases where you don't have cache-consistency.

>strict aliasing is a valid optimization and if it breaks your code then your code is shit.
I don't understand how someone this clueless about memory architectures can be so bombastic about how Linus Torvalds, arguably someone who knows a great deal about low-level programming, writes code. I guess this is a severe case of Dunning-Kreuger.
>>
>>62127330
> some hobby compiler by someone with no PLT experience
What are you talking about? Jonathan Blow has developed a few languages in the past. Off the top of my head, he did a Tcl dialect and made Lerp.

Not saying those went far, but they do establish that he has PL experience. Besides, even if he hasn't, does that preclude him from making a serious language?

> hasn't released the slightest prealpha years after the announcement
This is something that I thought was smart. I LOVE Rust, but it suffers from the "top many cooks" problem. He wanted to develop the language to a certain level by himself _before_ letting the public touch it and give feedback. I think at this point he's testing with close friends who also work in game dev.

Also, this isn't his full time job either. He announced Jai in 2014 while he was still working on the Witness, which took another two years to finish. I think 2017 is the first year that he's been able to work on the language with his full attention.

> no relevant game studio feeling any need to turn away from sepples
Come on, are you serious? Game studios would LOVE a better language to work in considering the shit pile that is C++. It's just an issue of legacy, effectiveness, and hiring.

I'm not saying everyone is going to rush to Jai, but I do think AAA game studios that aren't just sequel factories will be interested.
>>
>>62132199
https://www.youtube.com/watch?v=b-Cr0EWwaTk
>>
>>62132286
this video is a war crime
>>
ITT: Programming songs?

https://www.youtube.com/watch?v=outm3S8trH4
>>
>>62132220
Also, can someone redpill me on refactoring in gamedev? Is it worth it?

t. someone who spend 7 hours rewriting a resource generator script and game engine w/o adding any functionality
>>
>get thing working in ncurses in 10 minutes
>get thing working in SDL in 20 minutes
>4 hours later OpenGL still not working
Why is this such a pain to use
>>
I'm teaching myself c++, and I already read the pic-related book. What should I read next?
>>
>>62132512
Because it's high performance and capabilities graphics?
>>
>>62132458
I leave for like a couple of years and everyone is on this t. bullshit.

Game dev is always about making things fast. And fast means simple. You don't need to refactor unless it's either HARD to iterate on or it's getting slow.

Just finish your game.
>>
File: 1503049785615.png (110KB, 362x370px) Image search: [Google]
1503049785615.png
110KB, 362x370px
>When they're teaching you RUP in your uni class
>>
>>62132423
https://www.youtube.com/watch?v=XIr8ZnpQEXM
>>
>>62132547
C++ TPL, Effective C++(a bit outdated but solid avice), Modern effective C++ (and you can also get More Effective C++ and Effective STL but imo these are much more outdated, specially the STL one)
then wait for the second editions of Concurrency in Action and C++ Templates which both should (I don't think CiA will make it) be released on the first day of the CppCon 2017.
>>
>>62132601
This has literally nothing to do with programming.

https://www.youtube.com/watch?v=1Ie00tGi_io
>>
>>62132423
https://www.youtube.com/watch?v=pJON-nUg4eA
>>
>>62132161
>>MMIO is NUMA
>No?
Not the guy you're responding to, but yeah, it is. MMIO is a way for a CPU to access memory that doesn't necessarily reside on its memory-bus, i.e. memory either sits on the other side of a QPI or PCIe bus.

This bug was/is an issue in VDSM, Red Hat's virtualisation manager daemon, which among other things controls and assigns IO devices to virtual machines. It would assign NUMA nodes (read: PCIe devices that appears to have a lot of on-board memory, but rather forwards memory accesses to other nodes in the NUMA cluster) arbitrarily, rather than to VMs on hosts where the node actually resided.

https://bugzilla.redhat.com/show_bug.cgi?id=1356161
>>
>>62132620
>implying programmers are idiots in math
It does
>>
>>62132572
You mean, for example, this is a complete, total waste of time and effort?

https://pastebin.com/vHAwcz7X
>>
>>62132565
oh so that's why nearly every search result does everything totally different to the last.
>>
>>62132278
Do/did you work in the industry?
>>
>had to do multiplication table with nested loops
>didn't have any idea what I'm doing
>just messed around with the code until I got it

I don't know how to feel. Is this normal to get right results like this?
>>
>>62132601
thank you for posting this
>>
>>62132626
>>62132620
>>62132601
plebs
https://www.youtube.com/watch?v=ZOYTfpHl0JA
>>
>>62132612
Sweet, thanks
>>
>>62132732
You should feel like killing yourself.
>>
What's the equivalent of C#'s Code Contracts in other programming languages like C or Python?
>>
>>62132732
Just make sure you iterate columnwise ;^)
>>
>>62132788
asserts?
>>
File: ru.png (202KB, 750x634px) Image search: [Google]
ru.png
202KB, 750x634px
>>62132784

>>62132794
    int n, m;

printf("%4c*",' ');

for (n = 0; n < 10; n++){
printf("%5d", n);
}

for (n = 0; n < 10; n++){
printf("\n\n%5d", n);
for (m = 0; m < 10; m++){
printf("%5d", n * m);
}
}
printf("\n");

return 0;
¨
I think it turned out pretty well
>>
>>62132765
This.
>>
>>62132692
Are those comprehensions? Is that Python? Why do you hate yourself?
>>
>>62132912
It's a level generator in Python. It generates game resources from images and some configurable values.

The game engine and the game itself is in C11.
>>
>>62132710
I did, but I make significantly more money and get treated a lot better since I left. Turns out, it's really fucking hard to make games and the only companies that are willing to compensate someone who can do that work are web companies. My friends who stayed are just now making what I started off at when I left.

I make games as a hobby now and I'm significantly happier doing so.
>>
>>62132936
That's a good example of "refactoring when it's hard to iterate on." your old scheme seemed like a lot of manual work if you had to change one thing across every level.
>>
Anyone know of any good books on Operating Systems that also includes projects/exercises you can do?
>>
Why does /dpt/ have no wiki?
>>
>>62132278
>I LOVE Rust, but it suffers from the "top many cooks" problem.
What makes you say that?
>>
Can somebody recommend YouTube series which would cover basics about programming? I have done super basic shit with Python but I can't recall anything. I'm currently too lazy and busy to start full projects.
>>
>>62133053
IMO a lot of the RFCs put forth really just serve to complicate the language and move us closer to becoming another C++. A good example is the recent modules RFC.

I'll be the first to admit, it was a bit strange figuring out how to work with modules at first. However I don't think the solution is adding more concepts in the pile to "simplify" things. All that'll do is confuse someone trying to learn Rust for the first time because now they have to realize there is an "old" and "new" way to do modules.

I'd be totally fine with this stuff if there were breaking changes. But at this rate, I can easily see the language being really bloated and obtuse.
>>
how can i parse a string of form "1 2" followed by 0 or more spaces into variables in python?
>>
I looking from programs to packages for my distro, what you guys have that is new or not well known, but you find very useful?
>>
>>62133136
I thought they were talking about scraping modules completely and redisigning everything from scratch. It's kinda disappointing desu.
>>
>>62132812
I don't think that's really the same? Code Contracts let you specify preconditions that run at the start of a method/property, postconditions that run at the end of the method/property, and invariants that are checked at the end of every public method. Postconditions run even after exceptions, let you do checks on the return value, etc. These checks can run dynamically at runtime, but there's also a static checker that can analyse them at compile time.
>>
>>62133163
str.trim().split(" ")
>>
I'm trying to reverse engineer the netcode of the game Dominions 4. I've never tried reverse engineering the packet structure of a network protocol before, at the moment I'm just trying to look for patterns while reproducing behavior with slight differences. I know for a fact that the protocol is not encrypted (based on the behavior of the programmer and what I've found so far) however I'm getting large variance in the payloads beyond the header when something as small a single state flag flips so I have no idea whats going on.

Does anyone have any tips and tricks for reverse engineering protocols? Maybe some nice reading materials or tools that they find helps. I have the packet headers which is just a simple type and length, but beyond that I'm stumped and I have no idea how to proceed.
>>
>>62133136
> I'd be totally fine with this stuff if there were breaking changes. But at this rate, I can easily see the language being really bloated and obtuse.
>>62133174
> I thought they were talking about scraping modules completely
They plan to deprecate and remove features via "checkpoints": https://github.com/aturon/rfcs/blob/epochs/text/0000-checkpoints.md, it looks like it's gonna be like C++11/14/17/20.
>>
>>62133265
I don't really know why but it seems like a bad idea to me. I have the feeling it'll make the compiler very complicated.
>>
In C, which of the following string declaration forms guarantees that the string may be safely modified at run-time?

char *string1 = "Foo";

char string2[] = "Bar";

char string3[32] = "Baz";
>>
>>62133371
2 and 3.
>>
>>62133371
2 and 3
>>
>>62133202
any way to do it with regex?
>>
>>62133395
lookup re module
>>
>>62133371
All of the above.

>>62133395
\s+\d \d
>>
>>62133382
>>62133385
Isn't "[]" (without anything inside) just syntactic sugar for declaring a pointer? I'm pretty sure that's how it works in function arguments at least.
>>
>>62133371
>implying you can safely modify anything in C
>>
>>62133416
>All of the above.
I don't think so. String literals are allowed to be read only, and the first one shouldn't allocate any new storage, so it will just point to where the string literal itself is allocated, which may be on a read-only page.
>>
>>62133331
Rustc already has a nice architecture where each "feature" can be enabled/disabled individually via #[feature] in nightly, so checkpoints could be just presets of such #[feature] directives.
>>
>>62133427
In function parameters, yes.

>>62133416
The first one is placed in the data segment which is read-only.
>>
>>62133456
This. Editing first will segfault.
>>
>>62133427
That's how it works in function parameters (and why you shouldn't use it in your declaration).
But no, an array is its own type. An array decays to a pointer, it is not a pointer in and of itself.
>>
>>62133427
[] - yes
[static 65] - no
>>
>>62133494
that's still a pointer.
>>
>>62133510
no, the second one is UB if the parameter is not an array of at least 65 elements

practically yes though
>>
>>62133473
I know but as time goes it'll get harder and harder to backport fixes and stuff like that.
>>
>>62133456
>>62133478
>>62133474
You're right in practice. All modern compilers will place string literals in read-only data. Technically though there's no such requirement in the standard, but changing a string literal is undefined behaviour. But since the question specified safely, I don't think 1 counts.

TL;DR: Like all things in C, it depends.
>>
Why do trashkell girlmales think it auspicious and reasonable to publish "moan ads" in which they use kode komments to embed videos of themselves moaning in their trashkell source files, so that prospective l33t masc programmer BFs will be l33t enough to uncover them and get hard?

Surely there must be a more efficient way to accomplish the same thing?

It is almost as bad and stupid as their "lamb duhs" in which they use Kode Komments[TM](C)(R) to draw pictures of mentally retarded sheep so that there will be something for their counting algorithms to count before bed.
>>
File: 87NzOkn.gif (2MB, 450x254px) Image search: [Google]
87NzOkn.gif
2MB, 450x254px
Anybody here work in R? If so, what are you working on?
>>
>>62133530
It points to an array of at least 65 elements. It is not an array of 65 elements.

The litmus test is sizeof. That's how you can tell if your identifier is an array or a pointer. I wish C weren't so shit that this became a source of confusion.
>>
>>62133548
Graphs.
>>
>>62133548
had to use it for a class. complete shitshow of a language. laughable documentation
>>
>>62133570
Yes, I do know that. I mean this:
[/code]
#include <stddef.h>

static void foo(int *array);
static void bar(int array[static 1]);

int main(void) {
foo(NULL); // alright
bar(NULL); // UB
}
[/code]
>>
>>62133621
#include <stddef.h>

static void foo(int *array) {}
static void bar(int array[static 1]) {}

int main(void) {
foo(NULL); // alright
bar(NULL); // UB
}
>>
>>62133621
Yep, I know about that.
It's not an array though.
>>
>>62133637
Yes, it's not. You're right.
>>
https://vimeo.com/77451201

For people who need to understand maths for programming
>>
File: 1402876470872.jpg (123KB, 720x540px) Image search: [Google]
1402876470872.jpg
123KB, 720x540px
>>62133593
Built in libraries are pretty solid though and the depth of the rounding functions etc. make it nice for doing some probability/AI projects. I wrote a few projects in MCMC methods and messed around with some Bayesian hierarchy models so far.

I've been looking around for cpp libraries for distribution sampling and building but nothing quite matches what R has. Is there a better alternative you'd suggest?
>>
>>62133675
upboat
>>
>>62133530
>>62133621
>>62133636
>UB
But it shouldn't be "UB" though, for the feature to be useful it should be well-defined as causing a compile-time error. Because accessing an invalid array index is ALREADY undefined behavior, so if the "static X" notation is UB as well it wouldn't actually help prevent errors.
>>
>>62133695
consider it a form of annotation
also your compiler will probably warn if you call it with null like that.
>>
I am kind of new to the programming thing, but do I understand this correctly:
Programming is mostly about creating new functions, while scripting is basically just piecing together premade functions?
So basically scripting can be done by anyone with minimal training, while programming requires more training?
>>
>>62129712
If you're a C# fag then install Resharper too.
>>
>>62129712
F2
>>
>>62129509
how do I edit a windows host file without admin????
>>
>>62130515
The Haskell code it generates is awful sadly.
>>
>>62133678
Not him but use Haskell + HaskellR/inline-r

nice language + access to all of R
>>
What is the best Haskell language? I am trying to learn Haskell but don't know what language to learn
>>
>>62134269
Haskell is a pretty good Haskell language, but you could also try Haskell
>>
>>62134269
i personally program haskell in assembly
>>
>>62134269
Scala
>>
How does back propagation work?
I understand it goes backward through the neural network but how does it decide which neurons to go back *to* and what weight multipliers to pass? And also what does it do to each neuron it traverses to change it?
>>
>>62134377
*to each EDGE it traverses i mean
>>
>>62134377
it decides what neurons in the previous layer bear what share of error by what their activation was, and what the weights were. the greater their activation and the weights, the more impactful they were in the decision that was made, so that neuron bears greater responsibility. get it?

as for what it does to the neurons, it uses the error term to compute a stochastic gradient descent, which it then traverses down to minimize. don't ask me what gradient descent is, look it up yourself
>>
>>62134418
sick thanks breh
>>
Lispians, convince me to use a Lisp.
>>
File: OmaPLKq.png (219KB, 400x400px) Image search: [Google]
OmaPLKq.png
219KB, 400x400px
Does anyone have the picture with the Wojaks and the different type systems they use? I need it for reasons
>>
Fact: if you do not take pleasure in programming in C++ you are a brainlet.
>>
>>62134747
I take pleasure programming in C++, but it's twisted and somewhat unsatisfying.
>>
>>62134714
>>>/r9k/ or knowyourmeme you fucking redditor
>>
>>62134747
Ha ha ha ha ha.
>>
>>62134747
C++ is the least fun language.
>>
>>62134747
I actually do enjoy modern C++, too bad I can't use it often.
>>
>>62133678
just use stan
>>
>>62134818
Imagine if modern C++ was just its own language, rather than being a hack built upon years and years of legacy shit.
>>
>>62134840
It would be glorious. No more convoluted error messages that can't even tell you the line at which they occured, due to template and macro hackery in the underlying implementations.
>>
>>62134840
Well, I use Rust for my personal projects, it's pretty much C++ done right IMO.
>>
When are global variables not considered harmful in C/C++? I don't want to create a structure to store just two variables... should I just go with global variables in this case? It's a small program (Minesweeper) with ~350 lines.
>>
>>62134747
C++ exists just to make yourself feel superior, until you meet a pure C programmer.
>>
>>62134889
It's considered harmful when it's hard to figure whether changes will have a big impact on other part of the software or not, eg in most big projects. They still have their use (global service locators, etc). In your case there shouldn't be any problem using them.
>>
>>62134889
>When are global variables not considered harmful in C/C++?
When it's the least bad of the options.

>>62134884
There's a lot of great stuff, but it's quite different. It's not a better C++ in its style or philosophy.
>>
>>62134908
back to front
>>
>>62134889
In general, I would lean towards a singleton before polluting the global namespace. It depends on what I'm making though. If I'm making a library I'd avoid polluting it at almost all cost.
>>
>>62134908
C is a disservice to intelligent programmers. It has almost 0 features that a modern and intelligent programmer uses to be productive. Since C is such a timesink, it's popularity is falling more than any other languages in the market.
C is dying and it should die ASAP. C programmers are actually retards in general. C is a small language to grasp, exactly the kind of shit that makes things retard friendly.
C has no advanced features like C++ does.

But as a newfag you are kinda in the right direction. C is for newbies. Think of it this way:
During ancient times, counting to 10 was a big deal and a person who could count to 10 was considered to be "wise".

Fast forward a few century counting to 10 is so trivial we teach this to toddlers. Now toddlers appreciate the vast "knowledge" of counting to 10 while matured brains are busy with modern technologies.

C is from stone age and the people who still preach it is like overgrown toddlers that can't learn advanced things. C is for lesser programmers.
C doesn't have delegates
C doesn't have resizable arrays
C doesn't have strings
C doesn't have string concatenation
C doesn't have namespaces
C doesn't have exception handling
C doesn't have closures in the standard
C doesn't have unit tests
C doesn't have Function overloading
C doesn't have memory safety of any kind
C doesn't prevent memory exploits and has no bounds and runtime checks
C doesn't support dynamic method loading/creating
C doesn't even have generics and templates
C doesn't have meta programming
C doesn't have mixins
C doesn't have higher order functions
C doesn't have contract programming
C doesn't have inner classes
C doesn't have function literals
C doesn't have array slicing
C has a very limited support for implicit parallelism
C doesn't even have string switches

C is a cancer that plagues the modern software industry.
>>
File: Untitled.png (7KB, 79x399px) Image search: [Google]
Untitled.png
7KB, 79x399px
Rate my garbage
var page = require('webpage').create();
var system = require('system');

console.log("start");
console.log(system.args[1]);

if(system.args.length===2){
console.log("open");
function getMaxPost(status){
if(status==="success"){
console.log(
page.evaluate(
function(){
return Math.max.apply(
null,document.body.innerHTML.match(/"no":(\d+)/g).map(
function(a){
return parseInt(a.substring(5));
}
)
);
}
)
);
}
else
console.log(status);
page.open(system.args[1], getMaxPost);
}
page.open(system.args[1], getMaxPost);
}
else
phantom.exit();

It doesn't work well on fast boards though.
>>
>>62134952
Nice pasta
>>
>>62134942
>I would lean towards a singleton before polluting the global namespace.
Use the static keyword to scope the variable to only within the same compilation unit.

I agree it's not really avoiding namespace pollution, but at least you contain it to a single compilation unit.
>>
>>62134952
>implying C++ isn't cancer
>>
>>62134889
You can restrict the global variable to the relevant files by inlining its declaratiin in your include file.
>>
>>62134966
You either die fighting the shitposters or live long enough to become one of them.
>>
>>62134952
C has delegates and overloading though.
>>
>>62134959
var page = require('webpage').create();
var system = require('system');
console.log("start");
console.log(system.args[1]);
if (system.args.length === 2) {
console.log("open");
function getMaxPost(status) {
if (status === "success") {
console.log(page.evaluate(function() {
return Math.max.apply(null,
document.body.innerHTML.match(
/"no":(\d+)/g
).map(function(a) {
return parseInt(a.substring(5));
}));
}));
} else {
console.log(status);
}
page.open(system.args[1], getMaxPost);
}
page.open(system.args[1], getMaxPost);
} else {
phantom.exit();
}
>>
File: 1489491095718.png (740KB, 1834x1200px) Image search: [Google]
1489491095718.png
740KB, 1834x1200px
Reminder.
>>
>>62134959
REWRIT THIS
>>
>>62134884
>Well, I use Rust for my personal projects
Seriously, what is your opinion on Rust compared to related languages?
>>
>>62135021
I don't like this
>}));
kind of shit, so I'm trying to space it out more.
>>
>>62135047
I JUST WROTE IT IN LIKE 15 MINUTES
>>
>>62135017
>delegates
Through function pointers, but that's still not a "native" thing.
>overloading
This is wrong though. _Generic != overloading.
>>
File: 1445722183259.jpg (68KB, 700x700px) Image search: [Google]
1445722183259.jpg
68KB, 700x700px
>>62135043
N-no, i-it's not fair! They told me C programmers are the smartest.
>>
>>62135043
>to intelegente too spell correctly
>>
>>62134952
I agree, I'm pretty stupid, so I still use C like it's 1970s.
>>
>>62135064
>_Generic != overloading.
that's right, _Generic is better because it doesn't fuck up linkage
>>
someone make a new thread, I have a question.
>>
>>62135043
This is the dumbest meme. It's like saying the chip designers at intel are brainlets because all they use are NANDs.
>>
File: 1502409681999.jpg (24KB, 480x360px) Image search: [Google]
1502409681999.jpg
24KB, 480x360px
>>62135097
>>
>>62135043
Needs a Pure Binary programmer with
>muh 1s
>muh 0s
>>
>>62135064
>Through function pointers
Through function prototypes actually.
> _Generic != overloading.
Bruh, what are you smoking. Just declaring a function multiple times is overloading, generics have nothing to do with that. What C doesn't have is OPERATOR overloading, for obvious reasons.
>>
>>62135109
>>
>>62135098
>>62135092
>>62135091
>>62135080
triggered Ctoddlers spotted
>>
>>62134952
>C doesn't have
That's just because you are dumb to realize that in C. If you weren't, you wouldn't stick to languages with "batteries included".
>>
>>62135120
>function prototypes
These don't have any actual presence in object files. Delegates are supposed to be type safe function pointers.
>>
>>62135149
function pointers aren't typesafe?
>>
>>62135149
Function pointers are type checked.
>>
>>62135164
In C they aren't.

In sepples they are.
>>
New thread:

>>62135186
>>62135186
>>62135186
>>
>>62135185
Does that only apply if you don't declare the parameter list or what?
int(*)(int)
looks pretty typesafe to me.
>>
>>62134884
What do you think of it compared to C or Python?
>>
>>62135206
Implicit casting will only produce a compiler warning.
>>
>>62132590
I have to make a presentation about RUP.
What's wrong with it?
Thread posts: 318
Thread images: 19


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.