/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1486598631463.png (551x920, 426K)

Other urls found in this thread:

mooc.fi/en/
benchmarksgame-team.pages.debian.net/benchmarksgame/faster/python3-gcc.html).
catb.org/esr/structure-packing/
dev-point.com/vb/threads/649457/
github.com/victorqribeiro/digitRecognition
twitter.com/SFWRedditGifs

We live in a world where C++ is the only viable programming language.

How does that make you feel user?

nothing!

Attached: 1553854069232.jpg (664x720, 98K)

Lisp = Jewish communism
Haskell = British capitalism

Did anybody go to the unimath workshop?

Well, at least I can still program in C.

I just want to get a head start on my stupid java class

Attached: file.png (436x779, 156K)

I'm still in CS but this is going to be my last student summer, I'm trying to find some internship for a month or so. I've been looking at vacancies now and then and there is one company that has had a job position open for C/C++ for over a year now, and job posting can only be up for a month so they've been refreshing it and about 3 months ago they've changed the title to "Junior C/C++ programmer" on the ad, with exactly same description.
What the fuck could be going on in there? I live in a medium city and every graduate here knows C. Should I try to apply?

Attached: 1503155800413.jpg (399x400, 16K)

Redpoll me on bosque

how tough would it be to make a major mode for a pseudocode my class is using? ive never tried making a mode in emacs.

C++ is mostly for closed-source paid botnet wangblows desktop programs or more recently(UWP) 'apps' and console games. both of those utilize N-O-T-H-I-N-G of meta-programming/templates autism let alone optimization flags. It is all thanks to the idiotic/known C-style syntax and the ability to make everything an object plus hard to decompile binaries that C++ is even mentioned.
prove me wrong.

Might as well just write C++

mooc.fi/en/

What is your main programming language's score?
anything >10 and you need not apply.

Attached: 1555863514662.jpg (647x703, 222K)

It sure looks obtuse for something marketed as obvious and clear

dumb frogposter

Is that the one with incredibly naive implementations for some arbitrary languages?
The one where they only use simd for C/C++?

I use chicken scheme, so going by benchmark game standards I've got a score of 1.

You can help this article by submitting better code.

Are you a chicken

pay is probably low but if you need it do it

No, I'm a cute anime girl.

Attached: reset.webm (640x368, 286K)

no, you're an ugly anime girl

What a coincidence,!

Attached: 1536014885508.jpg (850x1237, 219K)

Attached: 1551765418844.jpg (620x758, 145K)

I wouldn't expect it to ever become a first class supported language. Stick to F#.

it's surfing on this worse is better trend

Attached: the_end_is_near.jpg (2603x1756, 462K)

Is this yet another language that is similar to some other language(s) that ms will use to port features to c#?

Imo the bigger problem is the way people think this is significant. There's plenty of examples where languages not designed with performance in mind are tortured into doing work fast.
Then there's also examples where the languages are basically C rewritten in the other language by using a library (most obvious example is pidigits here: benchmarksgame-team.pages.debian.net/benchmarksgame/faster/python3-gcc.html).

The problem becomes that the benchmarks are all optimized to look good for their languages. They're not representative of real production code. At least where people have bothered to make them good enough.

Also many of the tasks do favor lower level languages. There's not much business logic-y stuff going on for instance so the benefits of these high level languages are easily missed.

#include

typedef union
{
long R;
struct
{
char a;
char b;
char c;
char d;
}B;
} ex_1;

typedef struct
{
char a;
char b;
char c;
char d;
} ex_2;

int main()
{
printf("ex_1 size: %d\nex_2 size: %d\n", sizeof(ex_1), sizeof(ex_2));
return 0;
}

returns:
ex_1 size: 8
ex_2 size: 4

any cnile can explained to me why?

Attached: 1552792616641.jpg (978x1024, 85K)

my guess is that sizeof(ex_1) == sizeof(long) on your system

4 packed chars are smaller than a long on your system.

Attached: ranks.png (1200x1332, 304K)

Attached: Captura de tela de 2019-04-21 16-03-09.png (1137x266, 42K)

you cant even provide a linear measurement of the "speed" of a language unless you're comparing something like interpreted vs compiled
benchmarking languages is dumb

oh ok
didnt know long was at least 32 bits
i feel retarded now thanks

this isn't a terrible ranking, personally i'd move php down and swap haskell and lisp

>COBOL logo
>mfw

Attached: nes171.jpg (640x480, 28K)

Not sure I follow.
Thought you would say the opposite. How compiled vs interpreted isn't fair.
I'm fairly certain that they mostly avoid that though.

Chances are if it's still available under the circumstances you descrive they pay shit or are unrealistically selective. But at least it's a job to get experience, definitely interview there if there are no other choices

I agree.
If you only look at benchmarks languages like ocaml seem terrible, and yet projects like MirageOS perform very well.

>personally i'd move php down
PHP devs are fine since they stay in their own little hole. JS became a problem when they started to infect everyone else with their AIDS.

list.push // js
list.push_back // c++
list.append // python

Seriously fuck this shit

push implies queue
push_back implies deque

append does not imply any particular data structure

Unless you're being retarded and misrepresenting the data types, Python is the one that is most consistent to standard naming.

Empty/clear is worse. It tends to be inconsistent between containers even within the same language.

>Empty/clear
Yeah how about adding reset() and drop() to the mix?

>look up C++ reference
>"List containers are implemented as doubly-linked lists"
Yeah don't use these. These are pointless. They're just deques that mislead you into thinking they have functionality they don't have. Use vectors or deques depending on which you need.

most crappy business software does not have performance as a major concern
C++ is the only viable language for many actual important things but 90% of the programming going on is worthless random companies providing no real value to the world

Lisp is the most powerful programming language.

C++ has push_front and push_back and STL containers may implement either one, both, or perhaps neither (depending on the underlying implementation -- it only provides functions for the O(1) operations)
then some other containers have neither push_front nor push_back but insert instead (e.g. std::set)

In C this is just

struct l_node {
void *elem;
struct l_node *next;
struct l_node *prev;
};

struct l_list {
struct l_node *first;
struct l_node *last;
};

void append(struct l_list *list, struct l_node *new_elem) {
new_elem->prev = list->last;
list->last->next = new_elem;
list->last = new_elem;
}

Can someone give me advice on how to learn by oneself?

I can learn in a classroom environment, but I'm lost when I'm on my own.

Attached: 1541448177608m.jpg (1024x945, 99K)

Can I somehow, without using external tools, save the contents of my C++ header file in a string?
Feels to me like it could be possible, there are only small syntax things that are stopping me. I can say:
char *text = #include MyClass.h;

But that doesn't compile because it's not a string. All I really need is put quotes around the text in the header file, with macros or something, but it seems there is no way.

>Can someone give me advice on how to learn by oneself?
Practice and thinking about what you did, how you did it, and how to improve what you did.

Lecture videos

>apend takes a ptr to an already-allocated node instead of just the void* to the contents
disgusting
now everyone has to muck about with your implementation details at the call site

You just have to force yourself not to be brain afk. Learning always should put a kid of tension into your body and brain. In other words force yourself to concentrate. When you do that almost any source will be helpful.

But calling malloc() outside of main() is harmful, don't ya know?

Is Clojure all right?

you would need to use the raw string syntax to ensure you don't have to escape all the quotes in the header file itself
possibly using a macro for the beginning and end of the string to fool the preprocessor into still interpreting the #include

>now everyone has to muck about with your implementation details at the call site
What is documentation?

Can someone post that image with the programming challenges?

Attached: 1550650754495m.jpg (1024x576, 57K)

That was my problem. I tried raw strings but then the include was interpreted as part of the string, it was not expanded.
I never used macros much, because it often isn't considered good style so I really don't know how to use them.

Maybe there is a different way of doing what I want. Basically I want to implement some simple reflection mechanisms, all I really want is to write a Json of a class that only contains primitives or vectors of primitives. I think I could parse that somehow, if I could save the header file to a string. It wouldn't be pretty, but I think for my limited usecase it would work.

This one?

Attached: remember: post number modulo 145 plus 1.png (3840x2160, 1.61M)

I think preprocessor directives have to be the first thing on the line.. Try something like this:
char *text = \
#include "MyClass.h";

void *elem
dreadful

Just tested this, it doesn't seem to work. I think it's because the contents of the .h file would have to be enclosed in quotes.

I have seen some toy examples where the contents of the .h file were strings like "helllo", but I want to assign a syntactically valid header, so the text in that is not in quotes.

Maybe there simply is no way, I am not sure. It would be cool I think, it often is a pain to write Json with C++. Also I want to make this open source if it works.

you could also just use file i/o code to read the file from disk but that would require the source being present every time it runs

f

I'm trying to make a parser for polish notation.
I try giving it "+ a b" and everything goes well.
I try giving it "+ + a b c" and everything goes well.
I try giving it "+ a + b c" and it starts endlessly puking out stuff
What am I doing wrong?

Attached: what.png (1637x517, 37K)

>java vm
no, no it isn't.

Yes, It's me again: Fizzbuzzed Monkey.
So, looks like I unfizzbuzzed myself for real. But, how can I optimize this?
for i := 1 to 50 do
begin
if ((i mod 3 0) or (i mod 5 0)) and ((i mod 3 0) and (i mod 5 0)) then writeln(i,' ');
if (i mod 3 = 0) and not (i mod 5 = 0) then writeln('fizz ');
if (i mod 5 = 0) and not (i mod 3 = 0) then writeln('buzz ');
if (i mod 3 = 0) and (i mod 5 = 0) then writeln('fizzbuzz ');
end;

Attached: fizzfuzz.png (214x555, 16K)

True, I also thought about that. It would work for my personal projects, but I am not sure if it would help other people. But I keep that as a backup plan.

I could also write a sort of meta compiler, but I wanted to keep it very lightweight.

use a monospaced font for programming

Yes thank you.

>I could also write a sort of meta compiler
or just do the processing with shell commands in a makefile

tell me why i shouldn't learn gnu cobol in 2019

think about how to reduce the number of cases and how to simplify what you check in each one

no jobs

learning esoteric shit considered harmful

Modulo is a somewhat expensive operation, so calculate it as few times as possible.
Then do the checks in order of likelihood, from highest to lowest, to decrease the total number of comparisons.

var m3 = (i mod 3 == 0)
var m5 = (i mod 5 == 0)

if (!m5 && !m3) then 1
else if (m3 && !m5) then Fizz
else if (m5 && !m3) then Buzz
else FizzBuzz


But this is pointless, you'll only see a marginal difference and you can already FizzBuzz to millions in a few milliseconds.
If anything you are bound by I/O, not CPU cycles, so the best would probably be to allocate a contiguous area in memory that's a few million characters long, and then instead of printing for every iteration, add the outcome to the memory array. Like buff[current_position] = "Fizz\r\n"; And then once you reach the end of the array, print it all out in one big chunk, clear the array and start anew.
Again, this is completely pointless but there you go.

Oh and one more thing, if you use a little bit of math you can see that there's a repeating pattern. Basically if every 15th is FizzBuzz, every 5th is Buzz and every 3rd is Fizz, how do you combine those into one pattern? And then you can just loop through that pattern instead, and generate results without doing any checking.
Code that never runs is the fastest code by default, and you can usually use math to write code that never runs.

I wrote a rudimentary forum for 8 hours for an all-day hackathon on Friday in ~480 lines of Common Lisp. I just showed everyone what the users saw, and won a functionality award for it.

Today I'm going to work on it to make it a little more robust.

Attached: screenshot-5gegNaSh.png (422x584, 27K)

In Lisp this is just ((()))

Based. Lispfags will win.

Project Euler 91, version 2.0 in F#.

let isRightTriangle2 (P, Q) =
let Px, Py = P
let Qx, Qy = Q

if (Px * Qy) List.map isRightTriangle2
|> List.sum


Oy vey, delete this post!

I was thinking that there aren't any easy simple tools to quickly visualize data so I made a basic python script that just takes numbers from stdin and makes a chart

Attached: 1555879336.png (1134x848, 41K)

Lispfags have always won, user. The world just doesn't know they are losing.

Attached: Damon_Gant_Portrait.png (320x450, 38K)

>list

common lisp would be (push new-elem the-list) except the element appears at the beginning for O(1) time.

hmm, why does f# remind me of python?

Likely has to do with struct alignment... The sizeof operator is an array element blocksize, including any padding. Red this: catb.org/esr/structure-packing/

Leave the assignment operator but put #include on the next line and a ; on the line after that. If you are using C99 or above then the preprocessor merges string literals, you can have many lines of string literals (no commas or semi-colons between).

It is dangerous to go alone, here take this.

One version (2.0) of image found here. dev-point.com/vb/threads/649457/ The current one is at least fersion 4.0 but search engines suck, keep in mind that no list is perfect.

Attached: p_279aqgy2.png (1450x1080, 378K)

Significant whitespace, no brackets, list comprehensions.

I'm working on my own neural network. Here's it recognizing digits after being trained with the MNIST data set.

github.com/victorqribeiro/digitRecognition

You're out of date, here take this:

level 2 would be to minimize the amount of times you calculate mod.

level 3 would be to minimize the amount of checks and if statements.

level 4 would be to use bitwise operations to minimize the number of conditionals even more.

at level 4 you can probably get it down to one if+else and two ifs.

I'm doing problem where you have list of numbers repeated k times with one unique and you find it.
I know how to do k=2 with xor and I know idea of k=3 where it's same but you're adding each bit individually and doing mod 3 not mod 2 with two int variabes.
Problem is I can't figure out how to derive the bitwise logical operation to do mod 3 adding.

Is there a tip for this? Is it the same CRC checksum math? I'd like to be able to do it for general k.

ggplot?

The straight forward solution is to make a hashmap.

for every n:
map[n]++
if map[n] == k return result