/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

calhoun.io/using-code-generation-to-survive-without-generics-in-go/
en.wikibooks.org/wiki/Haskell
codepad.org/2NUqtLGN
github.com/yegor256/eo
twitter.com/AnonBabble

cute sharp

>Rust is a black woman
Inclusive/10

Clojure and Java looks pretty dicent, would fug

>She has no penis
transphobic/10

>clojure
>lisp

This makes Haskell, Matlab and Fortran look like the coolest ones.

Did you just assume they has no penis?

soo,
swift or go?

>they has
Did you just assume grammar-san's gender?

>Go is a child pageet
Looks about right.

This is just sad: calhoun.io/using-code-generation-to-survive-without-generics-in-go/

>implying this isn't what monomorphized/template generic languages do anyway

>There are people who claim the absence of generics in Go is a feature
Mindblowing.
It's like saying we shouldn't use compilers since all they do is generate machine code, and we can write it manually anyway.

>lua is kumatora but with a blue buzz cut
can anyone explain

i think the point was that there ought to be language-level support for it so you don't have to jump through hoops

>dat tumblr, probably SUfag, artstyle
Being Sup Forums is pain.

>JavaScript
Accurate. Since ES6/2016, it's at least two languages in one. You can use classes and block scoping and statically-bound this, but the old misdesigned features are still there, and you can still use prototypical inheritance, function scoping and late-bound this. Also, the original JavaScript was at least three languages in one. It looked like Java, but it was also Eich's pet functional language, and it was also its own unique thing with its own weird shit like the scoping rules. There was always at least two ways to make an object. You could put the methods on the prototype or assign the methods to the object inside the constructor's closure. Now there's at least three ways because of ES6 classes.

>Go
Mostly accurate, but it also needs Rob Pike and Ken Thompson breathing down your shoulder and inflicting their pedantry and elitism on you and forcing you to do things the Right way and to use the Right indentation style and the Right documentation style and the go get approved source code repositories and that channels are the Perfect and Only way to do concurrency and to never leave unused definitions in the code, not even while testing, and that you're too stupid to use generics and to never question the garbage collector.

>Python
I get it, but "the forced indentation of code" has always been a superficial aspect of Python. Like Go, the real problem is pedants. Be prepared to argue for days about which of the billion ways of doing the same thing is the most """Pythonic.""" Also, you'd better be prepared to read PEP 8.

Also Python is really two languages that no one can agree on. Did you pick Python 2 or Python 3? Guess what? Both are objectively the wrong choice.

Half of Sup Forums draws in exactly this style too.

This is more or less equivalent to what C++ does, but it's nowhere near the actual bounded parametric polymorphism Haskell, Rust and even C# have.

>tfw a good chunk of Sup Forums unironically likes pixie cuts

A good chunk of Sup Forums probably has pixie cuts.

Fuck.

>Did you pick Python 2 or Python 3? Guess what? Both are objectively the wrong choice.
What's the right choice then?

He's just meming, Python 3 is the right choice.

Not Python

is there a better way of doing this?

a = args[0]
b = args[1]
c = args[2]
d = args[3]
e = args[4]
f = args[5]
g = args[6]
h = args[7]
i = args[8]
j = args[9]
k = args[10]
l = args[11]
m = args[12]

>lua is a stereotype feminist

Should be a hyperactive little kid

Shit is FAST

I was just meming. Python 3 is the right choice. Python 2 is thankfully dying.

Does anyone have the "Problem solving guide" image that's basically break down the problem, google it or else it doesn't exists?

Store the args in another array?

Lua is actually great. Not for pseudo coders.

C++ can achieve this with concepts, or alternately by jumping through some hoops (though in that case it's admittedly not language-level). but at least the hoops aren't as bad as they used to be. i like C# generics/constraints a lot but unfortunately they do kind of fall apart at the line between primitive and user-defined types (and potentially types defined by third parties), since you can't implement an interface for a type you didn't author. also kind of a pain that you can't interface/constrain for operators. also template specialization is occasionally very handy despite being conceptually rather impure. for those reasons, there's still a solid number of scenarios where i'd take C++ templates over C# generics, despite the fact that (without concepts) they throw language-level type safety guarantees out the window

a, b, c, d, e, f, g, h, i, j, k, l, m = args[:13]

Java as a clean shaven businessman, because its the most professional language out there.

I'm gonna be the guy with the unpopular opinion here, but JavaScript has the right idea.

Traditionally -- in a compiled language -- an object's named fields are compile-time constructs whose meaning depends on the type as which the object is being interpreted. If you have a type in C that can be written as
struct {
int i;
long l;
}

Then the i and the l there aren't the unique strings they appear to be, they're actually plain old numbers that index the address of the object to which they belong.

A scripting language doesn't have to be compiled, so there's no good reason to preserve the illusion of compile-time constructs. Everything in JavaScript is dynamic, because it's a scripting language, so if the named fields of an object have to be dynamic, why not just make them as dynamic as they CAN be? Why NOT just allow putting new things into objects and taking old things out at will, as if they were some common data structure?

is it worth learning BASIC just as a little time waster?

>globals in python are actually module-local
who designed this shitshow

If you want to waste your time and learn something old better take a check out some lisp dialect

Lua is annoying. 5.1, 5.2, 5.3 and LuaJIT are subtly different and incompatible. Metatables are powerful, but creating them is tiring and verbose and it's weird to use them for OOP. Apart from that, it's like an anaemic JavaScript, except it uses 1-based indexing and closed intervals, which are for stupid people.

>>globals in python are actually module-local
I don't understand why this is a problem. Whole-program-scoped globals shouldn't exist. Design your programs better.

Java should be that guy getting replaced by h1b

Already know Javascript/java/php and a little of C

What should i learn next? GO or Rust?

Wanted to try GO because the multiple return value functions sounds interesting, but i dont know.

Then it shouldn't be called a global variable.

Got rekt'd pretty hard in a functionnal programming examination this morning. Anybody knows a good book/online tutorial about Scheme ?
Something with solved exercises to help me practice would be great.

Java as a clean shaven businessman with dead eyes and no expression, because it's the language people settle for when they lose all joy and innocence in life and become stone cold adults.

Some ansible code to deploy a puppet node

/dpt/-chan, daisuki~

Ask your much beloved programming literate anything (IAMA)

Thank you for using an anime image.

Ruby reminds me of Shana, aside from the Rails bot.

Rust, ofc. Go is a brain-dead language Google sponsored so it could save money by employing retards who's too dumb to learn any other language.
> Wanted to try GO because the multiple return value functions sounds interesting
It's funny how Go-fags pretend their limited ad-hoc tuples is a feature, every modern language has it in a way more generic and useful form.

>Already know Javascript/java/php and a little of C

learn something really different from these like haskell, lisp, prolog/mercury, or apl.

is akaribbs down?

akaribbs was a monstrosity. please, never talk about it again.

akaribbs was my 2nd favourite imageboard

>i don't know this language but i'm going to satirize it anyway

...

What's wrong with it?
I'm gonna launch it again soon after I write an administration interface and a ban system because not being able to delete spam sucks.

good luck akarin chan!

Ok where did I fuck up? This worked in visual studio yesterday but not codeblocks? are my settings off?

>ocaml
>fast
>terse code
But why must the syntax suck so much?
Also why doesn't it have macros?

>impure

What is wrong with Lua?

go eat that HASKELL CURRY Pajeet.

>triggered

>are my settings off?
yes. make sure your PATH has all the places codeblocks needs to go. check all your settings again. there are lots of youtube on CB linux setup.

Literally why I can't be bothered with codeblocks. You could write that in vim/emacs and compile from the command line in seconds, but codeblocks is totally unconfigured for anything when it is fresh out of the box.

asd

why am i getting connection error when i add code tags in post, wtf is this shit

This makes me want to learn and master haskell

en.wikibooks.org/wiki/Haskell

So I see most OS is written mostly in C

why is the choice in C and not C++?

Is it slower? Maintenance carrying momentum?

I don't really like C++ but I'm fond of C
Is that a common sentiment that influences the decision as well?

DailyPro,is ed Sup Forums approve not not cute enough?

is this valid?
codepad.org/2NUqtLGN

Wont post code here, connection error

For starters, development of most (popular) OSes started before C++ was stabilized in 1998.
> Is it slower?
C++ is generally faster, thanks to templates.
> Maintenance carrying momentum?
Yeah.
> Is that a common sentiment that influences the decision as well?
Yes, most of the C-fanboys don't know C++ besides a couple articles on how C++ is bad they've read back in the 1990s. Modern C++ is nice and is a way better choice for everything.

historical reasons, c++ compilers became viable for bare metal programming not so long ago.

How do i find values with even index?
template T max(const T* data, int size) {
T result = data[0];
for(int i = 1 ; i < size ; i++)
if(result < data[i])
result = data[i];
return result;
}

I will get proficiency in C before I look at C++ again. I'd like to have the ability to not write the fat to have to cut in the first place.

another follow up question.

C++ seems to be C + stuff
why can't you just write clean efficient C that then when needed takes what is better from what is added on? The bloat of the language isn't that just choice in the end?

Great C ----> Great C++ after picking the bits you need from the supermarket of ++ ?

a lot of the code in a given OS probably predates the time when C++ became a viable option (and *really* predates a lot of the improvements to C++ which have made it much better/more viable than before). and a lot of that code has probably remained largely unchanged in perhaps decades, and has stood the test of time, in which case it wouldn't be very wise to sacrifice all that stability by going back and rewriting it in C++ simply for the sake of it.

>Is it slower?
C++ is certainly not slower (and can be faster in many idiomatic cases), unless you make use of virtualization, which an OS would almost certainly not do, especially when static polymorphism exists as a zero-overhead alternative.

>Maintenance carrying momentum?
this would be a factor. there are far fewer competent C++ programmers than C programmers, not because of differences in popularity/prevalence, but simply because it is much harder to be a competent C++ programmer. and incompetent C++ programmers could most certainly muck up or at least complicate a project like an OS

there remain many *very* dated conceptions about C++, like that it is not suitable for embedded development, which has been false from the start, and only become *more* false (in a way) over time as C++ has modernized (new features expose zero-cost or even "negative-cost" abstractions which have *technically* always been possible to achieve (with heavy use of templates/macros), but formerly not in such an easy/idiomatic way).

in all, there are legitimate reasons why it's the case with current OSs, but if one were to develop a new OS from the ground up, it would be foolish to use C over C++.

Am I dead?

I don't know, are you D? If yes, then yeah, you're dead.

Is ed dailypro approved?

It looks like you've already made up your mind about C++'s "bloat", but the fact it, idiomatic modern C++ is easier to write and to maintain than the equivalent C code. Adding "++" to existing C codebase, and mixing C++ and C in general, is a recipe for disaster, and a sure way to make your code unmaintainable.

>The bloat of the language isn't that just choice in the end?
that's exactly it. C++ is a multi-paradigm language. you're not supposed to use every feature in any given program

what you'll find though is that, for a lot of programs, you'll be using more and more ++ features over time. in particular, professional C code makes use of a lot of macros that are better implemented as templates in ++

I'm sorry I'm ignorant

I have not made up my mind about anything its just I don't think im ready for c++ so my information about it is not the best. I feel like becoming adapt at C would lead to an adapt at c++
I'm not good enough at C to go to C++ to dable with yet

Coming up with a semi-joke scripting language that's so prototype-based that inheritance and instantiation are the same thing.

/* empty object not inheriting from anything */
EmptySingleton;

/* non-empty object not inheriting from anything */
Singleton {
singleton_field;
}

/* abstract = non-static members can only be accessed by objects that
inherit it as a prototype */
abstract Point {
Num x, y;
/* static = visible to inheriting objects, but not copied into
them */
static Point operator()(Num x, Num y) {
/* new = begin inline declaration of anonymous object */
return new Point { this.x = x; this.y = y; };
}
static Num distance(Point p, Point q) {
return Math.sqrt(Math.sqr(p.x - q.x) + Math.sqr(p.y - q.y));
}
}

abstract Shape {
/* abstract for functions = no default implementation */
abstract Num area();
abstract Bool contains(Point);
}

/* multiple inheritance */
abstract Point Shape Rectangle {
Num w, h;
static Rectangle operator()(Num x, Num y, Num w, Num h) {
return new Rectangle {
/* declaring "this" to inherit a prototype = current object
inherits it dynamically */
Point(x, y) this;
this.w = w; this.h = h;
};
}
static Num area() {
return w*h;
}
static Bool contains(Point p) {
return p.x >= x && p.y >= y &&
p.x < x + w && p.y < y + w;
}
}

abstract Point Shape Circle {
Num r;
static Circle operator()(Num x, Num y, Num r) {
return new Circle {
(super Point)(x, y) this;
this.r = r;
};
}
static Num area() {
return Math.pi*r*r;
}
static Bool contains(Point p) {
return Point.distance(p, this)

>OOP
It's shit already

>It's shit already
First of all, that's the point.
Secondly fuck you java is great

>Is ed dailypro approved?

SUBJECT: Edward Wong Hau Pepelu Tivrusky IV
STATUS: Approved

in general i think that most of the "C++ is bloat" people could calm down if they just
>don't use inheritance

and i think that's more of a commentary on inheritance than it is on C++. it's a bad, over-engineered abstraction for the majority of problems.

people tend to think of C++ as "C with classes" but the killer features are actually templates and RAII, because if you look at idiomatic C the things that are disgusting are macros and cleanup during error handling. you don't see a runtime polymorphic union in every C program, yet for some reason people are eager to introduce inheritance. i wish that C++ had a proper interface type distinct from a base class

If java is garbage collected, why doesn't it collect itself?

Because it's a good language, and good languages are not garbage.

i think C++ is a good third language. C++ is a language that combines concepts from many languages and you're supposed to pick and choose the ones you need for a given problem. if you don't know several languages then it's hard to know what your options in C++ are

It's gonna get replaced by this anyway: github.com/yegor256/eo

Working on my Sup Forums ncurses client.

Point being?

What makes something a LISP?

neat

I'm interested in trying to build my own homebrew/breadboard computer. As an intermediate step towards that goal, I'm trying to make my own logic circuit simulator. I've got something that kind of works now, but it's got loads of bugs and only a few things are implemented at the moment.

change for(int i = 1 ; i < size ; i++) to something like for(int i = 1 ; i < size ; i+2) (i dont know how you'd do that in your language)

i tried that but i didnt get why it was not working
then i tried i%2==0
that also didnt worked
then i saw this int i=1
:'(