/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

amazon.com/dp/0672326965
amazon.com/Primer-Plus-6th-Developers-Library/dp/0321928423
amazon.com/Primer-Plus-6th-Developers-Library/dp/0321776402/
perldoc.perl.org/perlre.html
mitpress.mit.edu/sicp/full-text/book/book.html
github.com/sarabander/sicp-pdf
principia-m.com/ts/0050/index-jp.html
twitter.com/NSFWRedditVideo

printf("rust is for faggots\n");

Second for D

printf is for faggots

Little reason to use cout when it has 2000x the overhead if you don't need to use any of its features.

sepples stream syntax sucks, but at least it doesn't need redundant type specifications

Java is pure.

>cripples you with no real multiple inheritance
>still has the diamond problem
bravo

C is pure.

>Little reason to use cout
Little reason to use printf when you can use puts.

Reading K&R.

That f in printf is actually useful though

Why is it that nobody in these threads is ever actually working on anything, but instead is just arguing over what programming language is best?

Because Sup Forums is all about yelling at people for having different opinions.
Why do you think?

because I'm embarrassed

Not if all you want to print is line
>rust is for faggots

Why don't you post what you're dong?

Ce drăcie grăit-ai despre mine, mojicule? Țiu să-ți aduc întru știință căci fusei întîiul din Școala de Rezboiu de la Viana și fusei în multe misii neștiute la Înalta Poartă și pre mulți am prăpădit. Sînt școlit în rezboi de vicleșug și niminea nu mînuiește mai acătări ca mine archebusul în toată armia cea sfîntă. Mi-ești dară numai o șaibă. Te voi mătrăși cu atîta pricepere ce n-a văzut întreg Stambulul, ascultă voroavele mele. Îți închipui că vei rămîne slobod dupe ereziile ce mi le grăiești pre ceastă jalbă? Rogu-te a chibzui iară. Numai ce vorbim de am trimes soli către iscoadele mele din țările rumâne iară copita murgului tău e taman vegheată așa că proptește-te întru viforul ce-are să vină, mamelucule. Viforul ce-are să spîrcuiască nimicnicia ce tu găsești de cuviință a numi vieață. Ești pristăvit, mojicule. Poci ca să fiu orișiunde, fieștecînd și poci a te stropși în șapte sute de chipuri, iară asta doar în brînci. Iată că nu doar ce sînt înalt școlit în trîntă, dară poci umbla la armurăria dorobanților și am să mă slujesc de dînsa întru totul pentru a-ți nimici șezutul de pe fața gliei, zamparagiule. O, numai de-ai fi vezuit ce amărăciune vei fi ispitit asupra-ți cu ceastă şăgalnică cuvîntare, pasămite ai fi muțit. Dară nu-ți fu în putință, n-ai cadaticsit, iară acum vei da tribut, nărodule. Iată voi slobozi urgie asupra-ți și de îndată te vei năbuși într-însa. Ești pristăvit, mojicuțule.

naruhodo

Then just use puts, I'm just saying printf is still useful unlike IO streams

Fair enough.

SICP chapter 2 binary mobile question.

Currently waiting on other people to finish/fix backend shit so I can finish my work. Other than that jack shit. Maybe test out some mobile database options, or go through some interview prep questions to stay on top of stuff

Usually I come to these threads to get ideas, but all anyone talks about is language wars

>61716386

I'm afraid I don't understand

>it took me a week to realise i was calling a class instead of an object
am i retarded?

>Using printf instead of fputs or even puts to print a constant string to stdout
ISHYGDDT

arguably

I geniunely can't tell, is the book in OP's pic about C or is it about C++?
Looking through its Amazon page[1], there are some reviews like pic related that confuse me.

[1] amazon.com/dp/0672326965

i'm trying to understand what this command does
grep -oP '"url_id": "\K([^"]*?)"'


according to grep manual:
-o = Print only the matched (non-empty) parts of a matching line,
with each such part on a separate output line
-P = Interpret PATTERN as a Perl regular expression

>What are you working on, Sup Forums?

Exploring the deepest, darkest corners of racket.

c primer plus is about C
c++ primer is about c++

Prata has written C Primer Plus and C++ Primer Plus.

amazon.com/Primer-Plus-6th-Developers-Library/dp/0321928423

amazon.com/Primer-Plus-6th-Developers-Library/dp/0321776402/

2 different books.

>c++ is a horrible language

Are the Prata books any good for learning C? I'm asking as a beginner to programming, I need to learn C for uni (EE degree before anyone starts recommending other meme languages)

It searches for strings matching the given regular expression.
For more information about Perl REs, see perldoc.perl.org/perlre.html

K&R is pretty good to learn C.

no it isn't

I doubt this was the question.

C Programming a modern approach is what I always recommend. K&R may be a little difficult if you have no experience in another language. Programming in C is another option, can easily find that one online as a pdf.

Writing an x12 parser in PowerShell because fuck everything

I've heard bad things about his C++ book. Don't know about the C one

At least for me, it was.

I prefer k n king's book.

hmm ok got it.

i'm downloading a whole web page html and then there's a bunch of JSON data
and in it there is the line
{
...,
"url_id": "example.com.-1.dnf.lopeio.net/t12.555.jpg"
}

so basically searches the whole HTML for the url_id attribute and finds the expression associated with it

>C Programming a modern approach is what I always recommend
Thanks user, I'll hit up libgen. Are there any common pitfalls that I need to be aware of when beginners are learning C?

it's shit

That's what is great about the book, it has common pitfalls annotated throughout it.

Exactly.

It's probably the actual best C book

I disagree. You can pass an IO stream to a function that takes a generic stream. You can't really do that with printf. This lets you write some more declarative code in many cases.

no u

>102mb for the PDF copy of the book

This better not be a fucking scanned copy.

>all these stories about interviewees failing to write fizzbuzz
is the standard really that low? will simply knowing how to write fizzbuzz immediately land me a $300k starting job?

They don't make retail PDF of the book, so it's almost certainly scanned lul.

I think I'll start with the Prata book since there's a real pdf copy and downloading from libgen is slow af for me at the moment.

If it's the K. N. King's C Programming: A Modern Approach then yes, it is a scanned copy.
I actually have it myself.

That's a decent book as well. You may struggle if it's babies first language though.

I did a short module on matlab if that counts for anything.

std::cout has no extra overhead.
And it's type safe.

Here's how it looks like.
It's annoying but it's a good book.

>c++ is a horrible language

Let's settle this once and for all.
Is artificial intelligence a meme?
Is machine learning a meme?

std::cout actually has lower overhead than printf.
It doesn't have to parse the format string, and it can be better optimized by the compiler than printf.

I've seen crappier scans. Wonder why the author doesn't have a decent electronic copy of his book.

Sort of. Unlikely we ever get real AI in the sci fi sense
And no ML is not a meme. Its very useful in a lot of areas.

Not exactly a compile-time Rust macro though is it?

To stop people pirating it most likely.

LIES!
I just made a very simple test, and printf was faster than cout:
/* printf */
#include
#include

int main(void)
{
int i;

for (i = 0; i < (1

I'd seriously consider buying it if it wasn't $100

>-O0

got an adroid question, is it possible to take and access an photo aka a bitmap without having to save it to a file first? Right now it seems I can only access the thumbnail unless I want to fuck with the content resolver

which

let color = isBlue ? "blue" : "green";

or

let color;
if (isBlue) {
color = "blue";
} else {
color = "green";
}

We don't want the compiler to optimize the difference between them away.

the first, obviously.

All college textbooks have ridiculously inflated prices.

The ternary.

Remind me why ifelse doesn't behave like a ternary again

>and it can be better optimized by the compiler than printf.
way to miss the point

Currently between semesters studying Computer Science
Wanted to learn something more instead of just working/playing vidya all summer.
Decided I'd go through all the courses that Codecademy has.
I thought something like this would kill any desire to keep learning to be a programmer, but it did the opposite.
I'm more than half-way through and realized I could also just read some books instead, so I went through the Sup Forums wiki.
Now I'm just considering which book I should start on.
SICP seems like a good place to start.

>SICP seems like a good place to start.
Ah, the meme book.

I did the same with -O3, and the results are the same: printf still beats cout.
Sometimes they run in the same amount of time, and sometimes printf is faster.

I wish I had real physical books instead of PDFs.

Of course, Rust macros btfo both C and C++ when it comes to formatted printing.
It has both the comfort and simplicity of format strings and the type safety of C++ streams (due to the format string being precompiled).

Future versions of C++ might be able to do the above, though. We just need to improve constexpr and templates a little bit, and maybe wait for reflection to land, and we should be able to precompile format strings into stream statements.

You suck at benchmarking.
These are my results using the exact same code, O2 optimizations, compiled with g++:
$ time ./printf > /dev/null && time ./cout > /dev/null
./printf > /dev/null 0.00s user 0.00s system 63% cpu 0.003 total
./cout > /dev/null 0.00s user 0.00s system 68% cpu 0.002 total // point
$ time ./printf > /dev/null && time ./cout > /dev/null
./printf > /dev/null 0.00s user 0.00s system 80% cpu 0.004 total
./cout > /dev/null 0.00s user 0.00s system 65% cpu 0.003 total // point
$ time ./printf > /dev/null && time ./cout > /dev/null
./printf > /dev/null 0.00s user 0.00s system 59% cpu 0.006 total
./cout > /dev/null 0.00s user 0.00s system 79% cpu 0.004 total // point
$ time ./printf > /dev/null && time ./cout > /dev/null
./printf > /dev/null 0.00s user 0.00s system 69% cpu 0.002 total // point
./cout > /dev/null 0.00s user 0.00s system 80% cpu 0.004 total
$ time ./printf > /dev/null && time ./cout > /dev/null
./printf > /dev/null 0.00s user 0.00s system 60% cpu 0.003 total
./cout > /dev/null 0.00s user 0.00s system 74% cpu 0.002 total // point
$ time ./printf > /dev/null && time ./cout > /dev/null
./printf > /dev/null 0.00s user 0.00s system 62% cpu 0.003 total
./cout > /dev/null 0.00s user 0.00s system 58% cpu 0.003 total
$ time ./printf > /dev/null && time ./cout > /dev/null
./printf > /dev/null 0.00s user 0.00s system 72% cpu 0.002 total
./cout > /dev/null 0.00s user 0.00s system 72% cpu 0.002 total


cout: 4
printf: 1

But really, it's about the same.

> >/dev/null
What's the point of printing if you're redirecting output to /dev/null

Apartments are storage constrained systems. Storing large amounts of objects in them is prone to cause book shelf overflow

Because we're not benchmarking how fast the terminal can render characters you fucking retard, we want to get rid of that bottleneck.
We want to benchmark purely how fast printf and std::cout can format and write it's arguments out to stdout.
And they're about the same.

C Primer Plus?
What The Fuck is this shit OP?

the physical copy of the sicp is shit
the pages are thing, bendy crap and the cover's plastic peels

What's the origin of the SICP snake meme?

ancap autism

both clang and gcc convert it to puts anyway. Also >using fputs for intended stdout

I am playing around learning rust, and I am trying to write a this function that compares two strings and returns how many characters they have in common with each other. I keep getting an error about borrowing chars1 and chars2 as immutable and then as mutable afterwards. Here is what I got:

fn commonCharacterCount(s1: String, s2: String) -> i32 {
let mut outputChars1: Vec = s1.chars().collect();
let mut outputChars2: Vec = s2.chars().collect();
let mut commonCharacterCounter: i32 = 0;

return countACommonCharacter(&mut outputChars1, &mut outputChars2, commonCharacterCounter);
}

fn countACommonCharacter(chars1: &mut Vec, chars2: &mut Vec, charsFound: i32) -> i32
{
for (i1, x) in chars1.iter().enumerate() {
for (i2, y) in chars2.iter().enumerate() {
if x == y {
chars1.remove(i1);
chars2.remove(i2);
countACommonCharacter(chars1, chars2, charsFound+1);
}
}
}
return charsFound;
}


And here is the compilation error:

error[E0502]: cannot borrow `*chars1` as mutable because it is also borrowed as immutable
--> file.rs on line 14:17
|
16 | for (i1, x) in chars1.iter().enumerate() {
| ------ immutable borrow occurs here
...
19 | chars1.remove(i1);
| ^^^^^^ mutable borrow occurs here
...
24 | }
| - immutable borrow ends here

What am I doing wrong?

SICP is pretty good for some intro concepts for comp sci.

The fact that it's taught in Scheme, a functional language, means that you'll learn stuff like high order functions and why they're useful. And if you have any hesitation in using recursion, this will get rid of it.

It will teach you some basic data structure stuff like stacks, queues, trees, etc. Plus some real applications of that stuff, like Huffman coding trees.

mitpress.mit.edu/sicp/full-text/book/book.html

retard

day 18 done!

Yeah, SICP is an exception, I prefer this copy of it:
github.com/sarabander/sicp-pdf

So that's what Emacs looks like... Not so bad.

A better print than the cheap one actually does exist
(top left in this picture)
principia-m.com/ts/0050/index-jp.html

where can i find a table of assembly instruction sets? like MOV a, b or ADD a,b