/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: CGTheater762.jpg (480x2103, 234K)

Other urls found in this thread:

leetcode.com/
hackerrank.com/
en.wikipedia.org/wiki/Grace_Hopper
en.wikipedia.org/wiki/Barbara_Liskov
projecteuler.net/
twitter.com/SFWRedditGifs

Didn't hit bump limit dumbass

>tfw finally starting to grok monads

why so many poos in Java?

Indians love shit languages

why so many white males in C++?

leetcode.com/
hackerrank.com/

Any other pages where I can learn new languages or solve problems?

Attached: dpt - Daily Programming Thread.png (457x185, 53K)

stackoverflow

White males invented every computer language, you can't make fun of white males for using any that they choose, including Java

Because it takes skill.

Isn't that a site to ask questions?

>solve problems

konnichiwa

Attached: c11e312e383b9bcd7faedae1743f4f58.jpg (220x328, 16K)

Are there any easily acquirable and good quality books for learning modern non-fixed pipeline graphics programming?
Right now I'm working through "Learning Modern 3D Graphics Programming" by Jason L. McKesson, which the khronos group recommended, but I really dislike the way he brings shit up only to say it'll be explained later.

pic very much related, he does this a lot, and it irritates the fuck out of me

Attached: 1532674532652.png (978x158, 38K)

They're comfy with shit and bashing together enterprise turdbeans A and B until they stick lets them express their inner jugaad spirit.

Ruby is for girls, user

>Make PHP page
>Decide I like it and want to take it further and add web interfaces to my personal apps
This is really cool guys.

Attached: 1520155950970.jpg (1080x1080, 142K)

girl (male)
ftfy

Attached: 220px-Coraline_Ada_Ehmke.jpg (220x391, 18K)

No, you're thinking of Rust. Ruby is for girls.

notihing. pls give problem or interview question

FizzBuzz? or something else?

i did fizzbuzz. something a bit more complicated

Attached: 1525735622064.png (1080x1106, 682K)

well i suppose ill give that one a go. seems interesting. thx

Any recommendations for books, manuals, tutorials etc for linux kernel programming?

try doing bubble sort

I'm solely a C# developer, but I feel I should learn at least the basics of more classic languages like C and C++, even if just to understand how things work at a lower level.

I'm not planning on going full dive on it, but what's a good place to learn the basics?

have you used "traverse uncurry" today, /dpt/??

took me longer than expected
#!/usr/bin/env python3
RIGHT = (1, 0)
DOWN = (0, 1)
LEFT = (-1, 0)
UP = (0, -1)

directions = [RIGHT, DOWN, LEFT, UP]
def next_direction(d):
idx = directions.index(d)
if idx + 1 == len(directions):
next_idx = 0
else:
next_idx = idx + 1
return directions[next_idx]

def get_next_position(x, y, cur_direction, cur_matrix):
direction = cur_direction
new_x, new_y = map(sum, zip(*[cur_direction, (x, y)])) # add direction to coordinates
# Wrap the index modulo matrix size
new_x = new_x % len(cur_matrix[0])
new_y = new_y % len(cur_matrix)

# touching a previously populated value?
if cur_matrix[new_y][new_x] != 0:
direction = next_direction(direction)
new_x, new_y = map(sum, zip(*[direction, (x, y)]))
return new_x, new_y, direction

def main(n,m):
data = [i for i in range(1, n*m+1)] # values to put in the matrix
ret = [[0] * m for i in range(0, n)] # 0-filled return matrix
direction = RIGHT
x, y = 0, 0
for i in data:
ret[y][x] = i
x, y, direction = get_next_position(x, y, direction, ret)
return ret

for row in main(3,5):
print(row)

[1, 2, 3, 4, 5]
[12, 13, 14, 15, 6]
[11, 10, 9, 8, 7]

different input? larger.

for (5,8) it returns
[01, 02, 03, 04, 05, 06, 07, 08]
[22, 23, 24, 25, 26, 27, 28, 09]
[21, 36, 37, 38, 39, 40, 29, 10]
[20, 35, 34, 33, 32, 31, 30, 11]
[19, 18, 17, 16, 15, 14, 13, 12]


which is correct

This kind of solution is similar to the best solution for an adventofcode question where Santa had to traverse a grid of squares based on textual directions. Really cool when I discovered that starting python

JavaScript rocks!

congratulation, user

Attached: 1526062348080.jpg (640x640, 93K)

>White males invented every computer language

en.wikipedia.org/wiki/Grace_Hopper
>cobol
>pioneer in high level language implementation

en.wikipedia.org/wiki/Barbara_Liskov
>CLU
>introduced the concept of abstract data types
>turing award

Attached: circuitgirls2.jpg (1500x938, 88K)

#include
#include

int *make_spiral(int rows, int cols)
{
int *array = malloc(rows * cols * sizeof(int));
if (array == NULL) return NULL;

int dir = 0, num = 1, i = 0, j = 0;
int left = 0, right = cols - 1, top = 1, bottom = rows - 1;
while (num

Attached: Screenshot from 2018-10-07 14-05-47.png (734x499, 44K)

Is there a global database of every single boorus out there (or at least the biggest ones) that can easily be downloaded or should I make one.

>the best solution
>O(n*m) space complexity

Attached: sure anon.png (390x379, 249K)

REMINDER that you can emulate concepts in current C++ relatively easily.

If an expression inside a decltype is invalid after template substitution, then the decltype is invalid and it is considered a substitution error, so SFINAE kicks in.
You can use this to overload functions on whether arbitrary expressions involving given type parameters are valid.

Here's an example that can check whether a given type can be added together by checking whether the expression a + b is valid and convertible to the same type, just like you'd do in concepts.
#include
#include

using std::declval;

namespace _is_addable {
// The int is a dummy parameter.
// When given multiple overloads, C++ will choose an exact match over a variadic candidate.
// This allows us to avoid ambiguity errors when our SFINAE check succeeds.
template
auto eval(int) -> std::bool_constant<
std::is_convertible_v
>;

template
auto eval(...) -> std::false_type;
}

template
constexpr bool is_addable = decltype(_is_addable::eval(int{})){};


template <
typename T,
typename = std::enable_if_t
>
static void foo(T&&) {
std::cout

Attached: 1508212880017.jpg (800x1131, 146K)

Who even needs concepts though

Concepts are useful for overloading on the semantics of a type.

What doesn't my vim look like in the picture?

Attached: GitHub - ajh17:Spacegray.vim: A Vim color scheme loosely based on the Spacegray Xcode theme. 2018-10 (3004x1752, 840K)

Try project euler
projecteuler.net/

what are some cool features of c++17 I should try using

Interesting. Thank you.

Unless the concepts you're overloading on partition the set of types, that sounds like it'd get confusing.
Just use if constexpr if you need to do that kind of thing, it's much clearer because it prevents the kind of spooky action at a distance that overloading leads to.

>that sounds like it'd get confusing.
For brainlets maybe.

>Just use if constexpr if you need to do that kind of thing
Tell me how to check whether certain expressions are valid using just a constexpr function. Go on.

>wake up
>it's 2018
>this is C++
wew

You're not wearing programming socks

Maybe I wasn't clear enough.
The actual Concepts proposal sounds hazardous if it allows you to overload a template on multiple different concepts.
The other solution you demonstrated where you write a single template and then branch within it using if constexpr to determine if a concept is satisfied seems superior because the resolution is more explicit.
SNIFAE is an ugly solution for creating the concept though, there's no doubt that requires expressions are preferable.

What kind of brainlet needs to check whether his types can be added?
Don't you know your own code?

I said similar to the best solution, unless the best solution changed. It didn't keep a grid of data

>what are libraries
>what are big codebases

What kind of brainlet doesn't understand his libraries and codebase?

what kind of brainlet doesn't understand the word "big"

That's why brainlets should stick to small codebases.

>SNIFAE is an ugly solution for creating the concept though, there's no doubt that requires expressions are preferable.
I completely agree.
>The actual Concepts proposal sounds hazardous if it allows you to overload a template on multiple different concepts.
Subjective.
If you're talking about the template syntax where Foo is a concept, this syntax is mostly intended for constraining, but it can used to overload too and there's nothing wrong or scary about that. Overloading isn't scary.

>write a single template and then branch within it using if constexpr to determine if a concept is satisfied seems superior because the resolution is more explicit.
Yes, sometimes this solution is more elegant. And guess what, you can do that with concepts too. Here's the exact same function you were talking about except using concepts instead of decltype SFINAE:
template
concept Addable = requires (T t) {
{t + t} -> T;
};

template
static void bar(T&&) {
if constexpr (Addable) {
// Addable
}
else {
// Not addable
}
}

You can use concepts however you like.

Of course, concepts is better than my shitty decltype hack, but given that concepts aren't coming out until 2020 and the GCC implementation of concepts is still quite buggy and unusable, this is a temporary solution you can use whenever you need to check whether a type satisfies some constraints, say for example, whether a type has a member function taking certain parameters and returning a certain type. You can do that with decltype SFINAE.

It's an example proof of concept, dumbfuck.
If you can't see how overloading on the semantics of a type can be useful, you haven't done enough C++ programming.

Why do you think "understanding your codebase" has got anything at all to do with concepts?
You clearly don't even know what you're talking about.

>If you can't see how overloading on the semantics of a type can be useful, you haven't done enough C++ programming.
I've done more than I care to wish for.
It;s completely useless.

I'm glad I stopped writing sepples and don't have to pretend this shit is sane.

>I've done more than I care to wish for.
Not enough obviously. Or you only did pajeet shit.
>It;s completely useless.
Wrong.

>strong types and absolute typesafety are not sane

>Not enough obviously.
More than enough.
>Or you only did pajeet shit.
I used neither gcc, clang, msvc or icc if that tells you anything.

>mommy help! I need to protect myself from myself! I don't know how to go potty!

>Wrong.
Elaborate already
I don't see any value as well

congratulation too, user
here's another anime girl + sicp pic

Attached: 1526496496747.jpg (1280x720, 456K)

Optimal algorithm selection based on what the type supports.

>littering your code with tens of different syntaxical elements, plus a few that don't make any sense except for the compiler to shut the fuck up just so you can have a simple feature that is already usable in many other sane languages at the cost of increasing tenfold already painfully slow compile times
I have nothing against strong types, but that gymnastic you have to do in sepples is ridiculous and if you don't agree you're delusional.

Nice nonargument, I spend majority of my time in dynamic langs.
If you can't see why those things are valuable then you should stop being unemployed.

No optimal solution is "generic" - it's highly tuned to a specific problem.
So why the fuck would you need some kind of decision and dispatch if you already know the what optimal function to call since you've designed for it from the start?

>but that gymnastic you have to do in sepples is ridiculous and if you don't agree you're delusional.
I agree it's gymnastics m8, but as I said it's an EMULATION of concepts, for in case you need it (which I DO have a need for it).
Actual concepts makes this MUCH more elegant to do.

>other sane languages
Do you suggest rewriting the whole codebase or what

The best lang for intellectually unsophisticated people?

I've spend the last six hours trying to figure out how to write a single command that lets me reword specific git commit like reword c30d604 "my new message".

Please just fucking kill me.

>Actual concepts makes this MUCH more elegant to do.
C++20 concepts are still uglier than concepts from any other language. I don't see what niche sepples fit that isn't filled by any other language, so I don't feel like keeping up with standard revisions.

It's too late. Might as well learn a new language.
The sepples committee should have stopped pretending people care about backward compatibility with C and dropped that part back in C++11.
All that is left now is the "5 constructors + 4 operator= overloads" meme.

You're fucking retarded.
You use it in generic functions. You can analyze the type parameter and use the information to select an optimal algorithm.
Example: random access iterators vs non random access iterators.

Sometimes you NEED to overload on type semantics, like say you want to define operator| only for types that satisfy some properties like for example being a generator or an iterator adaptor or a collector.
Say you want to implement the following:
Integers() | Take(30) | Collect();
You can use concepts to select the correct operator| based on what kind of types you have on the left and right side.
Perhaps a generator is any type that satisfies g.next() -> std::optional, an iterator adaptor is any type that takes a generator and returns another generator. and perhaps a collector is any type that can take a generator and return a container. Concepts are a perfect fit for detecting these semantics.

C - requires intellect, doesn't require sophisticated conventions

C# is pretty, simple and gets the job done

>I don't see what niche sepples fit that isn't filled by any other language
Going really fast with minimal runtime while supporting abstraction.
Only other language that does this is Rust, and C++ is more powerful than it.

ew

>ew
Stopped reading right there.

>there
Stopped reading there

I don't see what niche sepples fit that isn't filled by any other language (c) /dpt/, 2018

*interjects*

Attached: romanianguy.jpg (960x540, 94K)

m8 the code doesn't get "littered" with this stuff
it's all in a library or header so the code that uses it is very concise and clean
"C++ was designed for library writers" and all

the absolute state of /dpt/ 18 years after the turn of the century

>GC
Not a systems programming language. Not fast. Not minimal runtime.
Try again.

This is what true beauty looks like.

i did something like that for a challenge, except it's n*n, not n*m. o(1) space.

Attached: s.png (1678x1030, 190K)

what do you mean o(1)?
i saw nested loop.

Update:
You can get rid of the declvals and dummy variables and make it a little more elegant and closer to concepts like this:
namespace _is_addable {
template
auto eval(T x) -> std::bool_constant<
std::is_convertible_v
>;

template
auto eval(...) -> std::false_type;
}

template
constexpr bool is_addable = decltype(_is_addable::eval(declval())){};

I made an almost Win95 L&F button in PyGame, only took a week.

Attached: cat (2).jpg (500x375, 70K)

the loop only prints the number for each x.y position in the grid but there is no buffer/array to store the grid. the memory consumption is not bound to the grid size.

Attached: tetris.webm (640x480, 552K)

>Win95 L&F button
what's that?

Where my OCaml niggers at?

>systems programming language
There is no such thing though, even the Gotards and the Rustoddlers stopped using that denomination

Ocaml is gay and not real FP

replying to stuck into time-sharing concurrency.

Attached: 1439061543070.jpg (1920x1080, 162K)

>even the Gotards and the Rustoddlers stopped using that denomination
That's because they're retarded.

Nice rebuttal.