/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

en.m.wikipedia.org/wiki/Data_exchange
tour.dlang.org/
wiki.dlang.org/Books
dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes
dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/
youtube.com/watch?v=0z1QFiowntM
twitter.com/SFWRedditGifs

Re-writing JS in WASM

Teach your pet snakes to write software

>pet snakes
Snakes are illegal where I live.

Hence the quotes. I guess I should have said `language features` instead though.

That said, compilers are pretty smart about some things, but you do have to be pretty careful. The point about adapting the design around the language features based on an expectation of what the compiler can/will do is very good.

ωth for Fortran.

What do you think of JBlow's relative pointers, /dpt/?

In layman's terms; what makes a certain language faster than others?

>not using FORTRAN77

If language A can perform a run-time task faster than language B.
If LA can compile faster than LB.

Those are the main two.

LEVELS OF ABSTRACTION AND MEMORY MANAGEMENT

That's a very complicated question, without an easy answer.
I'll give the hand wavy answer specific to C. All of the operations that C supports is very close to how the hardware actually works. It also allows compilers a lot of room for optimisations. They can exploit the shit out of undefined behaviour and the fact they're allowed to pretend it never happens.

That's not the only way to write a fast language, though.

I think they're great. I think a general audience will miss the point of the language but I'm perfectly fine with that.
>fast
As in performance?
Either it takes away control from you and restricts you in a way that lets a compiler make good code that fits your intent.
Or it gives you control and lets you write the fast thing.

There's a bunch of languages that are designed without aims of being particularly fast, just fast enough for their purposes. Which can make languages very slow.

And as a note (because some pedantic fuck will mention it) a language is just the systematic interpretation of some input (source code) into a meaning. Most of what makes the slow languages slow lies in the environment they're intended for. Interpreted languages for instance tend to be run time interpreted and often don't optimize their code well because of that decision.
Its important to consider the environment you run in. If you can translate C++ to JS and run it its not gonna be fast because it was written in C++ originally. Pretty obvious.

In what course/subject in college am I supposed to learn this stuff? I haven't heard anything of it so far.

CE probably since CS is mostly theory wank.

CE isn't going to teach you shit about programming language design.

I'm on CE but I haven't touched the subject yet.
The fucking career is 50% EE courses and I fucking hate it.
I suppose I might learn about this stuff once I reach compilers. I just passed Data Structures, currently on Algorithms.

Not specifically no, but tertiary.
Its more an independent study subject anyway.

CE? I think you guys mean CmpE. Unless CE has a lot more software involved than I thought.

Absolutely nothing and I'm bored to death

CE isn't even well-defined.

writing a static site generator.
def writeBody():
with open('newpost.txt', 'r') as input, open('post.html', 'a+') as output:
for line in input:
if line==2:
output.write(''+ input.readline())
if line in ['\n', '\r\n']:
output.write('')
if len(line.strip()) != 0:
output.write(''+ input.readline())
else:
output.write('')


get the error "ValueError: Mixing iteration and read methods would lose data" because of

if len(line.strip()) != 0:
output.write(''+ input.readline())


and i have no fucking idea why. pls help im too autistic to use jekyll.

holy shit
what are you doing

nigger

fuck nevermind the logic of this is even retarded im going to go slam my head into a car door thanks Sup Forums

There's optimization courses that teach you some about CPU architecture (usually still at a level that isn't particularly applicable) but there's some bits that could be useful. I don't think most universities educate you seriously on modern optimization/ways to write software that goes fast. It's not really their role to teach you that. They're more often focused on bigger picture stuff.

But I think the question you're asking is indicating that you don't have a clue at all. Which is pretty problematic imo. They should give you a hum. They should cover algorithmic optimization. Which is basically theoretically figuring out how to do little work to reach a result. Searching and sorting are prime examples. For general code there's probably not going to be that much to guide you in university. I've learned this stuff (which we haven't really talked about yet) from working with skilled people and reading articles by skilled people and later from Intel via conference or courses. So I imagine nowadays you'd go online and search for what skilled people are doing and talking about. These people talk about their jobs a lot on their spare time usually.

I'm working through two books at the same time, kinda like, 2 chapters in one and then 2 chapters in the other.
C Primer Plus 6th edition
and
C Programing a Modern Approach 2nd edition

How well do these two books cover the language for a newbie?

No CPL?

Is JSON or XML the only format for communication between modules?

The algorithms and datastructures bit covers algorithmic optimization. That's not that essential to the 'what makes a language fast?' question.
Also you need to be more specific. Are you interested in writing things that are fast. You wanna be the optimization guy. Or are you talking about understanding various languages and what decisions made them slow?
This Is all about the former. You could infer some stuff from that in language design but I don't think it's the most productive approach.

>modules
Define "modules" in this case.

My (third-year) algorithms course actually covered CPU cache and paging optimisation, but it didn't go balls-deep into it.

Modules are like vector spaces but with rings instead of fields.

Ah I was just being curious. My Algorithms professor assigned us a project, we're supposed to implement lots of sorting algorithms and report their runtimes using more than thousands of data. During that time he mentioned something about "If you do this in C it will be blazing fast". So I was just being curious why was it.

Define modules.
Very generally:
There's tons of formats that can be used. XML is a markup language. It's intended to communicate what information it contains better than most file formats. Same with json.
en.m.wikipedia.org/wiki/Data_exchange
They're not the only two who have this goal though. But there's a lot of formats that are used that aren't specifically made for general use like this. csv (comma separated values) is a common one.

Stop trying to trick me with your mathematics; I actually know what you're talking about.

Ah. Yeah well if you implement something correctly in low level languages it tends to go fast. Assembly would also go fast (but a newbie might make his assembly slower than his C version).

He probably said C because it's a safer bet than most languages.

I'd consider that rare. I've had optimization courses that, imo, didn't go that deep into it.
In the wild the best go on trial and error and intuition. Which may seem weird but it's just that people are so time constrained and usually don't have full control of the environment.

cpl?

I want to learn Elixir but I don't have any project ideas that would make use of channels.
Suggestions? Can be as stupid as you want.

Black box components of software

Why would you need such an over-the-top form of serialisation for that?
Just use a struct and a standard function call, or some shit.

What if they can't communicate like that.

Are we talking about a single piece of software (i.e. a single process)?
Or is that Java® Enterprise-tier™ software?

>Or is that Java® Enterprise-tier™ software?
Yeah.. something like that but not Java

How to spot a shitty language 101:

>You can declare variables this way:
int x (12);

>You have "function overloading"
int fn (int x) { kill(self); }
void fn (int x) { delete(system32); }

>Your shit language doesn't have standard build system and the package management has no standard
Cmake, Gmake, Excusemake

>Your compiler takes 20 hours to compile because your shitlang doesn't have any model for software construction that doesn't make want to kill yourself with dependency analysis

>(((header files)))

>Your language has 3 standard libraries
std::trash, boost::trash (soon to be added in C++($CURRENT_YEAR + 25)™

>It's a rolling release language


>And you had half a century to fix all these

FUCK CTRASHTRASH

>return type inferred function overloading
I didn't know this was a think. Sounds awful.

No, I don't even think C++ is that retarded.
He probably just forgot to change the argument type.

>No, I don't even think C++ is that retarded.
Rereading my statement, I realised I worded this poorly:
>No, I don't even think C++ is retarded enough to do that.

been a while since I programmed and I'm looking to sharpen up and start doing something besides mindless html/css again. I've had this thick ass C book for about 12 years now.

Doesn't seem to have a newer edition. What should I do after I finish this one?

Threadly reminder that dlang-chan has RAII; she's quite fast; and she's super duper cute! Say something nice about her, /dpt/!
>Tour
tour.dlang.org/
>Books
wiki.dlang.org/Books
>GC
dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes

Rate my $cat

1 import std.stdio;
2 import std.file;
3
4 void main(string[] args)
5 {
6 if (args.length < 2)
7 {
8 string input;
9 while ((input = readln) !is null)
10 {
11 readln().write();
12 }
13 }
14 else
15 {
16 foreach (path; args[1..$])
17 {
18 auto current_file = File(path, "r");
19 while (!(current_file.eof()))
20 {
21 current_file.readln().write();
22 }
23 current_file.close();
24 }
25 }
26 }
27

>$cat
Yeah, it really is shit.

Why

>no region-based memory management
>only choice is gc
>can't even remove the gc from the stdlib yet despite all this time
it's doa

>You can declare variables this way
I'll agree that this is kind of a shitty syntax

>You have "function overloading"
Also known as compile time polymorphism. It's a good thing.

>Your shit language doesn't have standard build system and the package management has no standard
Properties that mostly apply to younger languages, rather than older languages, to be honest.

>Your compiler takes 20 hours to compile because your shitlang doesn't have any model for software construction that doesn't make want to kill yourself with dependency analysis
It takes about 2 hours to compile g++ on my phone, last I tried.

>(((header files)))
C++'s price to pay for compatibility with C libraries.

>Your language has 3 standard libraries
C++ has one standard library that consists of the STL and libc. Boost is not a part of C++.

>It's a rolling release language
What's the problem with this exactly?

>And you had half a century to fix all these
Technically, C++ is 32 years old, not 50. Because of its widespread use in industry, it has to maintain backwards compatibility with previous versions. Features cannot be removed, only added, and this is completely non-negotiable. If you can't compile a C++ program written 20 years ago with a modern compiler, you can forget about it. With regards to the features you wish it did have, most C++ programmers aren't really clamoring for them. If you use Linux, you can just use your distro's standard package manager. With regards to build systems, everyone has different tastes, so there will never be a standard build system. One of the complaints about Rust was that it basically forced Cargo onto everyone.

Why would you remove GC in stdlib?

>Boost is not a part of C++.
Nice try. Boost is literally the beta version of the next C++ stdlib

>C++ has one standard library that consists of two standard libraries

>Cargo
Best shit I've ever used

While Boost features have been added to the C++ standard over the past decade or so, Boost itself is not a part of the C++ standard library.

>Boost itself is not a part of the C++ standard library.
It essentially is. Boost = the next C++ release, literally every one knows it

Cargo is 90% abandonware and 10% trivial bindings to C libraries.

>abandonware
>last commit one hour ago

Needs some error handling, but it looks good. I see you're utilizing UFCS like a true man.
Also check this out for CLI programs: dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/

>didn't read the links provided
>doesn't know that there are already GC-free alternatives for existing constructs

Because people have an unjust fear of GCs. In reality, you can use another library/runtime for embedded programming with dlang-chan and use RAII for performance critical code.
In the average program, a GC is fine. Check out vibe.d for a non-trivial implementation of a non-GC dlang-chan program.

This

Dub is good to but Cargo is absolutely the best package manager

>UFCS
One of the few reasons left to live for

>In the average program, a GC is fine
This is why software today is shitty

language specific package managers are retarded

>Because people have an unjust fear of GCs
For a language trying to compete in the realm of systems programming languages, that's just a fucking death sentence.

People that are afraid of GC are the people that didn't study about GC

having a package manager > having no package manager and hunting down dependencies and listing them and defining them in a shitty config files and compiling them and finding out that dependency has a different dependency cycle and hunting them (recurse)

t. can't manage memory

What makes you say that?

Just because people don't square a 5 digit number by hand doesn't mean they can't do it. It's probably because they've got bigger thinks to focus on

This is incorrect. If there are speed issues it's because the programmer is a retard.

I agree with you if we were talking about younger dlang-chan. But today, she's got good RAII support and alternative libraries and runtimes.

Because you seek to discourage programming without GC

Because you yourself cannot do it, so those who do make you feel inadequate

>Because you yourself cannot do it
What makes you say that?

>programming without GC
Is that supposed to be a "skill"?

>If there are speed issues it's because the programmer is a retard.
In that case write me some code in a GC language that's as fast as optimized C/C++ code. You can't do it.

>I agree with you if we were talking about younger dlang-chan
First impressions are incredibly important, and D fucked theirs up HARD.
No matter what deadlang does, their time to shine has already long gone. It will never be popular.

It's as much a skill as tying one's own shoelaces is. It used to be something you could take for granted in adults, but now that expectation is too great for many people today.

Because I know you can't do it.

>Because I know you can't do it
What tricks you into "knowing" that?

this is closer than last time

youtube.com/watch?v=0z1QFiowntM

>It's as much a skill as tying one's own shoelaces is.
Why would you tie shoelaces if your shoe doesn't require you to?

No tricks, it's merely the honest truth.

Why would you become toilet trained if you can wear a diaper instead?

Now that I've posted that, I anticipate an increase in adult diaper sales to software developers.

>He wears velco shoes
What are you, 4 years old?

I could tie my own shoes at 4.

>Why would you become toilet trained
Probably because people grow up, just like programming languages?

It is a single library with two components.

>it's merely the honest truth.
What makes you believe that?

>Not building your own house yourself
What are you, 2 years old?

[insert a child cartoon here]

>Because you seek to discourage programming without GC
Nobody's discouraging anybody from manually managing memory. But why would you want to anyway unless you had to? RAII and GCs are good enough for most use cases.

You're arguing something totally different now.
I'm talking about general use cases here. For non-critical code, a GC does well enough. If you need to squeeze out performance, you'd disable it.

And that's why I'm spreading the glory of her now. Many people don't know or have forgotten about her; thus, it's a good time reintroduce them to dlang-chan.

I'm not aware of any implementation which works like that.
libstd++ and glibc are NOT the same library.

>libstd++
libstdc++*

Because you're so feeble that you haven't even attempted to deny it yet.

Oh indeed, programming languages have grown up. That's why we have Rust and C++ today, and we're not still using C and FORTRAN for everything.

Kids like to "manage own memory" because they think having no GC will turn their O(n^2) code into O(n) magically

Not sure I understand the purpose.

>you haven't even attempted to deny it yet
Why would I be required to deny a false claim?

>C++
Is that supposed to be an "upgrade"?

>C++
Isn't that a brainlet language with smart pointers GC?