/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: Smalltalk.jpg (397x499, 43K)

Other urls found in this thread:

cacm.acm.org/blogs/blog-cacm/229942-blame-free-quality-control/fulltext
github.com/dominictarr/event-stream/issues/116
docs.python.org/3/library/argparse.html
nim-lang.org/
twitter.com/NSFWRedditVideo

for me, it's zig

Attached: mov zig.png (4824x1527, 118K)

cacm.acm.org/blogs/blog-cacm/229942-blame-free-quality-control/fulltext

what functional programming language is the best for writing drivers?

JavaScript rocks!

Attached: js-rocks.png (1000x494, 369K)

>do lamdba because it's quick and simple
>doesn't work
>doesn't work
>doesn't work
>write it normally

God I wish I wasn't a brainlet

>Since i feel its alot different than a high level programming language that has a compiler that does all the work for you.
Yeah, here you have the assembler do all the work for you

>Well, you should follow the standards for each language
Make me.

Javascript.

Sir, javascript can't compile to native code.

>writing drivers
Assembly

Lisp is the most powerful programming language.

Idiot.
You write drivers in C or C++.

what shitlang

Hi Rajesh, how do you like working at Radeon?

...

Java
I hope I get the hang of it soon, sorting without lambdas in this dumpster fire of a language is a huge pain in the ass

Of the "functional" languages out there, Rust is most suited to writing drivers, and it is used for such a purpose in Redox OS.

Why do neither C++ nor Python have argument parsing in their standard libs? Fine, I get that C++ has nothing useful in its std, except a giant mess of template based algorithms. But Python also apparently has like two different ways to parse it and both are terrible and everyone uses an external library.

Back in like the 90s before you had stackoverflow for people to tell you "just use boost", did everyone implement their own option parsing or something?

If you use javascript in any shape or form, you're not a real programmer: github.com/dominictarr/event-stream/issues/116

Pretty much all drivers are written in C.
Every driver in Linux is written in C.
And there's nothing stopping you from using C++ to do it.
You might be retarded.

Java since version 8 has lambdas. They're just syntax sugar for the old way with anonymous classes but they work well enough.

do people actually use design patterns?

im a webdev frontend but want to learn fullstack what kind of "patterns" should i learn like CRUD, Authentication, user roles, what else is there? i was thinking maybe pagination as a pattern to learn but can't think of what else is a common thing you would code

Explicit patterns are for people who don't do it unconsciously and intuitively.
I.e. they shouldn't be programming.

Why do we need to bloat the size of the standard library for every little task someone might want to do?

When writing drivers you want to be able to share lots of constant and variable definitions across a lot of different source files. The natural language for doing that is C, one of the few languages that can simply #include another file. C++ too, I guess, if you're a heretic.

Argparse is in the stdlib for Python: docs.python.org/3/library/argparse.html
For simple stuff, you can just parse sys.argv yourself.

C/C++ have argc, argv - it's just strings, parse it yourself.

yes

Okay fine, I was just funposting

>C++ can't include lots of headers
The absolute state of Cniles.

Java lambdas are rather retarded last I checked, do you have experience using lambdas in any other language? If not consider practicing in something non-shit, like fuck javascript is unironically good for practicing first-order functions if you don't wanna learn something like haskell

If yes and your trouble is just java then my condolenses and good luck

Everything is a design pattern. Classes are a design patter. Passing int argc, char** argv is a design pattern (implemented at the OS level). The GoF patterns are nice in that they put names to things you would've done anyway; the problems arise when you use a retarded ecosystem in the first place, like a corporate java application that was first entirely designed in UML then signed off by executive, and which had half the GoF book shoved into it for no reason.

Like said (even if it wasn't the main point of his post) you're likely to use some well-known patterns even if you don't know the name of them

QR code encoder, just for fun

Thanks, no, I haven't used lambdas in anything else before

Sir, what is this then sir

Attached: unknown.png (837x1035, 83K)

>just for fun
I wish I could be like that

>code for an assignment
>get hype and work hard
>code for my job
>get hype and work hard
>try to code for myself
>bored and can't muster any motivation

Option parsing is something literally everyone wants to do, unless they're writing a GUI application (and even then many do still include cli options), and if you're including a GUI toolkit the size of some string parsing functions is a non-issue

It's always just strings, in every language, but there are plenty of edge cases which makes it impractical to implement yourself and yet it's essentially a solved problem that has been used for decades so I really don't see why we need a dozen competing libraries to do it

we v8 nao

It can't, because compile times increase through the roof. The reason for this is, most C++ libraries are single-header header-only, because C++ devs are retards who're scared of source files and want a header-only. C doesn't have this problem.

idk, v8?

Like the juice. jk, the engine.

Count yourself lucky
>code for an assignment
>bored and can't muster any motivation
>code for my job
>bored and can't muster any motivation
>come up with something I can code for myself
>get hype
>start coding and immediately bored and can't muster any motivation

C has getopt and getopt_long, so I guess that's usable from C++ as well

If all you're putting in your headers is constants like you say, there's going to be no difference.
>libs
Sane libraries have macros you can define for a classic build style.
Even if you exclude well behaved C++ libs you're in no worse a position than you are with C.

Most importantly, drivers are never so large and heavy on C++-isms like templates that compile times are prohibitively slow.

public int comparesTo(Stuff o) {
if(this.x > o.getX()) return 1;
if(this.x < o.getX()) return -1;
else return 0;
}
I might be a brainlet but this sounds really wasteful. Is this really that optimal?

I want to learn general design pattern concepts that aren't tied to specific languages (but still OOP), any resources you recommend?

Literally GoF

Python 3, I have list such as [1, 2, 3, 3, 3, 4, 5, 5, 3, 6]
I want to get the count of elements with certain number of repetitions like:
num of elements that don't get repeated: 4 //1, 2, 4, 6
num of elements that get repeated once: 1 //5
num of elements that get repeated twice: 0
num of elements that get repeated three times: 1 //3
Is there any easy way to do this?

You want
public int compareTo(Stuff that)
{
return this.x - that.x;
}

>Is there any easy way to do this?
Yes

The quick brown fox jumps over the lazy dog

I forgot to say, x is double or float

Use a dict.

Wrong.

sorry sweetie.

Need more handholding, total Python newfriend here

Make a dict.
Do a for loop over the list.
If the current element isn't a key the dict, add it with a value of 0.
Add one to the value referred to by the current key in the dict.
Done.

None. Drivers are interfacing software to hardware which is extrinsic to the nature of functional programming.

Wouldn't that get me
1:1
2:1
3:4
4:1
5:2
6:1

>!(o instanceof MyObject)

>Java devs' faces when

Attached: 1539442393785.jpg (850x800, 65K)

You can then iterate over the dict and find how many times each number of repetitions appears.

How did Java get this so wrong when C++ got it pretty much right?

Oh okay, as a non-Python guy I thought there was some more pythonic way of doing it

Thanks user

maybe this?
import collections

def solution(lst, occurrences):
d = dict(collections.Counter(lst))
for k,v in d.items():
if v == occurrences:
print (k)

if __name__ == '__main__':
solution([1, 2, 3, 3, 3, 4, 5, 5, 3, 6],2)

what you want is to get counts of elements (e.g. with collections.Counter) and then inverse the dictionary so that number of occurrences is a key and value is set/list of symbols from the list
from collections import Counter

arr = [1, 2, 3, 3, 3, 4, 5, 5, 3, 6]
c = Counter(arr)

print(c)
# Counter({3: 4, 5: 2, 1: 1, 2: 1, 4: 1, 6: 1})

inv = {v:[i for i in c.keys() if c[i] == v ] for k,v in c.items()}
print(inv)
# {1: [1, 2, 4, 6], 4: [3], 2: [5]}

Trying these now
by the way, I don't need the actual elements, just the number of their repetitions. So I'd be okay with a resulting list of just [4, 1, 0, 1]

p1 == p2
p1* == p2*

Nah this shit is too complicated

oh ok, then just count the values of first count
from collections import Counter

arr = [1, 2, 3, 3, 3, 4, 5, 5, 3, 6]

reps = Counter(Counter(arr).values())
print(reps)
# Counter({1: 4, 4: 1, 2: 1})

Yep this seems to be it
Need to learn about collections
Thank you so much user

Watched a web-talk from Google about virtual-scroller. Basically they've now finally got around to making a list you can use to dynamically set DOM objects off screen as invisible. Like a RecyclerList on Android or any of the dynamically loaded lists we have had for years.
I'm very surprised. It seems this is just occlusion culling in a 2D plane. They know when the DOM is changed and could even color the changes so why don't they just do that in their renderer?
I did get the hunch that this was a talk for brainlets though. Someone in the comments through that retaining a fixed point on the page while resizing would be impossible but anyone with a brain would find there's many simple solutions that don't even require library user awareness.

So maybe this isn't the whole story and it's more of a compatibility issue. Where users with awful browsers don't have these features and you need to emulate it. But he didn't even touch on that or that this could be done in the browser renderer.

Some people get off on invisible references.
How do you do this with references in C++? Can you just take the address of a reference? I would imagine they're more restrictive than that.

My employees fill out the same paperwork each week by pen and I have to copy it to a spreadsheet each week to send in to corporate.

Is there an easy to use parsing library to automate this? I know a little Lua, Python, and Java. I just want to scan the sheets and run a program that parses the data into a spreadsheet.

I don't see what this has to do with references. This is about type assertions.

But yeah, you can take the address of a reference and it gives you the underlying object.
int x;
int &ref = x;
assert(&x == &ref);

...

I misunderstood instanceOf then.

Right.
== is how reference equality is performed in Java, while the .equals method is used for value equality. There is no operator overloading. This is a point of pain for C# devs.

>What are you working on, Jow Forums?
Currently just laughing my ass off at .NET cucks whose shitass Java clone of a language doesn't increment loop variables if you use continue in a loop.

What is objectively the best programming language?

>This is a point of pain for C# devs.
Why?

Because typing .equals everywhere is an ugly pain in the ass.

OCaml

purescript

There are tools widely available for grabbing text from images and then you can just copy and paste. I think this would be the quickest solution.

But if you want to make something on your own.

Python has pytesseract.
Java has a tess4j API.
Not entirely sure about Lua, but I'm sure there's something.

Doesn't facebook use that?

We use == for equality in C#. It works perfectly.

Yes. They do static checking with it (I don't know more).

Yes, I mean this is something C# devs complain about when they use Java.

Why do you keep posting this shit? I'm not even a fucking C# or Java user and I know you're full of bullshit.
It's not even funny.

$ cat Test.cs
using System;

public class Test {
public static void Main(string[] args) {
for (int i = 0; i < 10; i++) {
Console.WriteLine(i);
continue;
}
}
}
$ mcs Test.cs
$ mono Test.exe
0
1
2
3
4
5
6
7
8
9

Ha OK, I was misunderstanding. Thank for the clarification.

besides GUIs in which kind of software it is an advantage to use oop?

>no native thread support
>no unsigned types
>boxed types
>shitty FFI
>no macros, have to use external tool
>;;
Ocaml is shit
consider SML, SML# or actually good programming language

Exactly.

Attached: sc.jpg (499x624, 97K)

You're funny.

Not an argument.

I know.

Not an argument

In oop gui you tend to duplicate state a lot. It's not ideal. Usually the process of translating from your OOP representation to drawing objects can be quite significant. If you wish to not regenerate your entire drawing structure on change it becomes complicated. The advantage you speak of is that people are used to oop gui and that for applications with very little dynamic behavior (think your typical GUI window, not a 3D model editor or otherwise complex software) the problems that are there aren't visible usually. I would say it's one of the least offensive places because of how world modeling is actually starting to be sensible when you're dealing with a world that's entirely constructed/defined by you. Anything less abstract like a world (our world) representation starts to make less sense. Where the world modeling fits well it's great for intuitively understanding the code.

I can't think of any other place that fits OOP especially. I tried to explain how I'd try to evaluate it generally but it got complicated.

Don't limit yourself to just one paradigm, FP niggers will want to make you believe that FP is the end all be all paradigm, but only a retard doesn't use the right tool for the right job.

daily nim shill because fuck it I like it even if I don't get to use it as much as I wish I could
nim-lang.org/

Trying to figure out where i'm losing precision in my tax calculator.

Attached: 1329064982492.jpg (640x480, 88K)

maybe it's your mom's snapchats

round everything to 0.1 cents, or 0.001 dollars

Getting random freezes on my MariaDB server while performing seemingly innocuous SELECTS or UPDATES. I've disabled the query cache, and mytop doesn't show any slow queries (it freezes as well). The entire daemon locks up.

Trying to determine whether it's my code or the daemon config.

Attached: illogical.jpg (440x343, 18K)