/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

benchmarksgame.alioth.debian.org/u64q/program.php?test=fasta&lang=go&id=3
benchmarksgame.alioth.debian.org/u64q/program.php?test=pidigits&lang=go&id=3
youtube.com/watch?v=1PhArSujR_A
rosettacode.org/wiki/A*_search_algorithm
youtube.com/watch?v=sxMVYX5Ua5k
github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/fd.rs#L240
twitter.com/SFWRedditVideos

Thank you for posting an anime image.

java is objectively the best language

...

>fasta
> benchmarksgame.alioth.debian.org/u64q/program.php?test=fasta&lang=go&id=3
>calls three functions sequentially instead of running them in their own goroutine

>pidigits
> benchmarksgame.alioth.debian.org/u64q/program.php?test=pidigits&lang=go&id=3
>calls C code

>regex-redux
>calls C code

yeah, no wonder...

I wanted to learn a fast and easy scripting language. I was thinking about lua, but maybe an easy compiled language like golang would be better.

just paid $150 for the A* algorithm unlock on unity

literally python

What's the motivation for learning either? Are you new to programming?

lol go is so bad it has to cheat in benchmarks by using C libraries. SAD

Go away, Rob Pike.

>paid $150
>for babby's first AI algorithm

all python programmers must be killed

Choose a Scheme, for your sanity.

Bait.

It's a terrible trend.
The website owners acknowledge it even. They should benchmark how much of the code is written in the stated language too.
And even that's too weak a measure since you have so many languages that write the most stupid shit that's essentially C code in their higher level languages.

We need a good measure for semantic complexity.
Virtually every language does. The exceptions are C++, asm and Java.

Rewriting C++ game engine in C.
Fuck trying to rnimplement class inheritance made in cluster fuck of sepples.

You don't have to write oo in C++.
But I support your decision.

chapel, swift, fortran
dumb go poster

>cheat
calling C code is what makes it slower

>lists languages
What for? And I don't use go nor am I defending it.

I know c and a bit of c++ and c#, but it takes a while to get a prototype to work in these languages. I usually use matlab for prototyping, but its performance is quite slow, so I wanted something faster.

>C better than C++
>W-why is it so hard to write this code in C?
The length Cniles will go to prove their language isn't outdated is hilarious.

C?
Shell scripts do 80% of what you want for 20% of the development time in accordance with the pareto principle, there's also python for the ambitious pajeet

youtube.com/watch?v=1PhArSujR_A

C++ucks will try to defend their horrible language.

>width
>height
>th
>ht
why is english so fucking retarded?

>depth
>weight
Literally nothing wrong

You made the linguist in me cry. Please consider your physical removal.

I'd much rather write widþ and heȝt personally.

>dþ
>ȝt
why is *THIS_SHITTY_LANGUAGE* so fucking retarded?

C++ developers will work while C developers whine, try to write equivalent code, and fail.

because it was conceived by anglos

>linguist
I also know Russian and Swedish.
>выcoтa
>шиpинa
and
>bred
>höjd
all fucking rhymes

wid TH
hei GH t
The digraphs are th and gh, not th and ht. They're also pronounced differently. Be glad your language doesn't have two words used interchangeably for width and length at least.

Digraphs are evil. One letter, one phoneme.

Bredd and höjd don't rhyme, and bred (wide) and höjd certainly don't.

also, to add: Go won't use AVX2 code (not always, anyway), AFAIU. that's because it's not part of the amd64 spec, but an extension...
I just tested the C++ fannkuch-redux locally in my system (a shitty 4-core AMD cpu that lacks AVX/AVX2), and it takes exactly the same time as the Go program...

In today's episode of "teach me C++":

I have a class with a member list of unique pointers:

class MyClass {
public:
MyObject& getObject(int index);
private:
std::vector _objects;
};


This class is sort of an ObjectManager, so it makes sense for it to have ownership over the objects, so I made it a unique_ptr. However, I'd like for other parts of my code to be able to access the objects too, through the getObject method. But I don't want them to be able to overwrite it, they should basically have read-only access. So I figured it makes sense if getObject returns a reference to MyObject...

So that leaves me with 2 questions:

1: What's the syntax for this? What should the definition of MyClass::getObject look like?
2: Does this break the semantics of unique_ptr in any way?

>They should benchmark how much of the code is written in the stated language too.
Wheee! I see an idiot. Every single class on optimization ever teaches the same thing, and faggots keep not doing it.

***Profile*** the code first. See where the time is spent. Optimize the critical path only. If there isn't a bottleneck, leave that code alone and put your effort elsewhere.

>1: What's the syntax for this? What should the definition of MyClass::getObject look like?
MyObject& MyClass::getObject(int index)
{
return *_objects[index];
}
>2: Does this break the semantics of unique_ptr in any way?
Nope. Unique_ptr represents ownership. If it is guaranteed by the structure of your program that the instance of MyClass will outlive the function that requests an object from it, then it is semantically valid to return a non-owning reference.

Even if you're a complete washout in computer science, you could have just copied this for free off of Rosetta Code with a few modifications.

rosettacode.org/wiki/A*_search_algorithm

Conventional wisdom isn't always right. If you always keep it in the back of your head to write efficient code, you won't get trivial inefficiencies spread out all over the code.

Thanks m8. That clears things up.

Re-stating this question from the old thread.

youtube.com/watch?v=sxMVYX5Ua5k

How can programming tutorials be more edgy than CoD montages?

Also, consider returning a const reference if you don't want it to be possible to alter an object using getObject.

>Weite
>Höhe
>te
>he
why is german so fucking retarded?

>arab
are bombs programmed in C?

>windows
>programming
found your problem

even with a degree the best thing is to have a network of people in the industry who will vouch for you. it seems slimy but i think it's the truth

Is this going to get me v&?

>arabic writing
>french os
checks out

captcha: rue de russe

>why is english so fucking retarded?
Because it's a bastardised mix of Saxon and Anglean-Frisian, with influences from Old West Norse, Western Modern Norse, Frankish, Latin, West Frisian, and plenty of other languages.

>slimy
Not at all. Hiring someone is a big committment and it's difficult to make sure of all the other aspects (social, mainly) of being a good employee outside of technical knowledge.

Why does >> overloaded operator print correct age of object, but name is not correct? prints random stuff. Picrelated.

[CODE]#include
#include
#include
#include

class Human {
public:
Human(const int& param1, const std::string& param2) : Name(param2), Age(param1) {}
Human& operator=(const Human& param);
Human& operator>>(const Human& param);
void PrintParams(const Human& param);
private:
std::string Name;
int Age;
};
Human & Human::operator=(const Human& param) {
Name = param.Name;
Age = param.Age;
return *this;
}

Human & Human::operator>>(const Human& param) {
printf("%s %d : \n", param.Name, param.Age);
}
void Human::PrintParams(const Human& params) {
std::cout

you are now on the blacklist.

when in conversation i think of whether i am talking to this person because i might need something from them later on. i don't like that

>Frisian

>equivalent code

There's the problem. C++ code is always a magnitude worse than C code, it creates bad arcitecture, bad abstractions, and generally bad everything. The language shapes the problem, it shapes the way you think about the problem. The solution will be differnt if it was coded in C rather than C++. As it will be with FORTH, Prolog, Lisp, Haskell, etc.

All valid, but then it begs the question why you are trying to translate a C++ game engine verbatim into C.

I'm not that poster. I also think that poster is stupid.

dumb frogposter

>Human(const int& param1, const std::string& param2)
>Human k{10, {"James"}};
why are you using references and passing values?

I just realized... how is this not considered cheating? debian itself doesn't distribute binaries that use AVX natively, for example...

You fucked up your code tags, mate. It should be all lower case, and you forgot the [ in the closing tag.

Also, %s is for printing C strings (char*, const char*), not std::string. Your printf call just arbitrarily interpreted the bytes of the std::string as a pointer. I'd be surprised that it didn't segfault.

julia?

But std::String is const char* internally, i thought it would print using %s

std::string is ugly sepples object cluttered with bloat and evil thoughts.
const char* is '\0' terminated const char array.
How the fuck are they the same?

std::string is a class that has a char* variable internally, but it isn't a char*. to get the char* you use the c_str() method.

>A properly configured and hot JVM is as fast as -O2 code if not faster
the only thing i've seen that would suggest that is a set of benchmarks that gets posted here sometimes. they're all simple cases (generally single simple/inlineable functions of simple/inlineable operations on stack-allocated primitives), for which there's no real excuse for any modern JIT compiler *not* to produce such results, especially since it knows for certain the instruction set and extensions available on the machine and can incorporate them into generated code without runtime branching or separate builds, a rare natural advantage over native compilers. however, those cases are ideal. in a large/enterprise-scale project, the cost of things like other less local/primitive/JIT-optimizable code, overall higher heap utilization/lower stack utilization, and garbage collection would add up. all things considered it does a pretty damn good job, and i can't make any sweeping statements like that it's enough of a difference to make it generally unsuitable (and of course the difference we're talking about is nowhere remotely *near* the difference between optimized native code and a legitimately slow language like Python). but games often do have extremely stringent performance requirements, so it's not at all unrealistic to say that it could legitimately be a dealbreaker for some projects

c_str() worked, thanks.

I feel like C++ is too fucking over engineered. Why the fuck can you overload ANY operator and why the fuck do you have so many types of constructors, holy shit.

My brain is melting already but i still enjoy this clusterfuck

It is, but you should start by knowing what the fuck you're doing.

>Conventional wisdom isn't always right.
This particular piece is. If you insist on optimizing everything, you'll take forever and never ship. Also, most people who "optimize" everything are very good at missing out on real optimizations such as picking the right data structures and algorithms.

Sure, putting bubble sort in asm makes it fast... for bubble sort... but switching to quicksort and ensuring that you don't have to sort so often is better, especially once you've got lots of data. Want to look something up a lot? Don't linear search if you can use a hash table. These sorts of things can give you multiple order of magnitude accelerations; seen that for real many times.

no, but I can be your julia if you want

Its so hard to remember everything. How do professional C++ programmers keep remembering every important aspect of language?

By keeping only the relevant parts in your mind when you need them and having reference material close by.

As a unity developer, thank you.

We need more people to fall for shit like this.

>But std::string is const char* internally
No. An std::string contains at the very lease a size field, a capacity field, and a pointer to the data. There is no guarantee over the order in which they are stored in the struct.

And now that I think about it, your compiler would have passed your std::string by reference implicitly, so the characters it was reading was actually the bytes in the struct.

1. Don't ask "why" with C++. You'll get tired of it. The answer is "because this is a language that was designed by committee and everybody wants something different."

2. It is a clusterfuck, and it can be enjoyable. But to truly master it, you must come to accept that you have the word's largest toolbox at your disposal, and for many tasks you will only need a hammer and a screwdriver, and maybe an odd tool that doesn't get used often (but hey, you have it, so fuck all the other langs, right?)

they don't. people who say they're fluent in C++ are usually full of shit

Turns out sbcl still performs gc even when gc is disabled (confirmed by (room)). Meanwhile, racket doesn't do anything upon (collect-garbage) when gc is disabled, and gc can only be enabled/disabled globally at start. What do?

is it worse than siraj

Well i'm working as C# programmer right now and even C# is becoming too large to remember everything, usually i have to use google for some things. I imagine working as C++ dev takes much more googling.

It's true what they say, can't spell cuck without c.

Stop using Lisp if you need garbage collection, retard.

>Well i'm working as C# programmer

what are C# jobs like? do you have to write web apps with it or what?

literally don't know what people use this language in industry for

I'm working through the tutorial introduction to pic related. Right now I'm on Exercise 1-20:
Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter?
I know in general what they are wanting, but what do they mean by
"Assume a fixed set of tab stops, say every n columns."
Not sure where columns come from. Any advice would be appreciated.

Rust is "safe"
github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/fd.rs#L240

Oops, forgot pic

>Shell scripts do 80% of what you want for 20% of the development time in accordance with the pareto principle, there's also python for the ambitious pajeet
Shell "scripts" aren't portable at all and use a shitload of different binaries for what could just be a function which makes them really fucking inefficient. Bash and zsh are a pretend programming language, in reality they're just binary abuses. The only good reason for using this is because you're a beginner who had to learn how to use your shell and basic binaries but was never arsed to learn a proper language. Any half decent scripting language like perl, lua, python, ruby, awk, etc. will do whatever the shell does through very standard functions that don't require executing a whole new binary and actually have programming language features that will be useful to whatever task you have (like proper lists).

Recommending to do ANYTHING through shell scripts other than setting up an environment before launching a program or using it to automate some sequential execution of a program is fucking retarded and just shows that you have no clue whatsoever what the purpose of your shell is.

Are you clinically retarded or merely lobotomized?

I'm writing websites using ASP.NET MVC 5, usually it's very boring. Most of stuff works like

Web request comes in -> hits controller -> controller passes some parameters to ORM framework -> using LINQ or direct SQL query we get some data from DB and pass it back

Then render it at front-end. So its working with DB and rendering information using HTML mostly. Pretty boring desu.

I'm a Haskell programmer, user~~

There is no problem here.

people who believe rust is safe because it's marketed as safe and safety is its gimmick lack critical thinking

Figures. Only cucks could possibly fall for the hasklel meme.

jesus christ it's 150 fucking dollars? i was already good and pissed that people would pay for an A* plugin before when i assumed it'd be ten bucks or some shit. dear god

Rust < OCaml < Idris > Haskell > Rust

t. paid nsa shill

Explain why Idris is good. (this is going to be fun)

Which is why Bjarne Stroustrup says he's only mediocre at C++.

Programming in general is like 80% googling, and 20% actually typing shit into the editor. If you're not googling the standard library because you forgot something or because it's fucking massive, you're googling a 3rd party library because there is no way in hell you're going to remember that shit.

Rust is "mostly" safe. There are cases where you must use unsafe blocks, and when you are dealing with syscalls (or C wrapper functions that do nothing but invoke a syscall), you are pretty much playing by the kernel's rules.

t. rustlet