[ cyb / tech / λ / layer ] [ zzz / drg / lit / diy / art ] [ w / rpg / r ] [ q ] [ / ] [ popular / ???? / rules / radio / $$ / news ] [ volafile / uboa / sushi / LainTV / lewd ]

λ - programming

/lam/bda /lam/bda duck
Name
Email
Subject
Comment
File
Password (For file deletion.)

BUY LAINCHAN STICKERS HERE

STREAM » LainTV « STREAM

[Return][Go to bottom]

File: 1446244063159.png (186.72 KB, 600x450, cmonks.png) ImgOps iqdb

 No.11201[View All]

Happy Dennis Ritchie Day, Lains!

Pay respects to your lord and savior for creating the greatest language of all time: C.
66 posts and 5 image replies omitted. Click reply to view.
>>

 No.11582

>>11316
C's only reason was to program unix. without unix, there no c.

>>

 No.11584

>>11312
Dude, ever heard about listing reasons for *and* against something?

Saying that something is "obsolete" or "must" go and then list reasons is just ex post rationalization.

>>

 No.11598

File: 1446820383302.png (295.72 KB, 370x460, 1437880944607.png) ImgOps iqdb

>>11584
Everything isn't subjective.

>>

 No.11603

File: 1446831195492.jpg (518.32 KB, 1440x792, Aspect-Emperor.jpg) ImgOps Exif iqdb

I ordered K&R at a book store today. Within 10-14 days, nothing can stop me.

>>

 No.11615

>>11603
k&r is piece of crap. c primer plus is the only decent book on C.

>>

 No.11616

>>11615
That's definetly not true.
Even if it's not the best textbook for learning C, it's still an important piece of UNIX history and worth a read on that basis.

>>

 No.11625

>>11615
Deep C Secrets is the best C-related book I've read so far.

>>

 No.11639

File: 1446886244080.jpg (129.21 KB, 997x595, Bashrag-v-Nonman_sm.jpg) ImgOps Exif iqdb

>>11615
>>11616
To say that there's a conflict between a good teaching book and a good reference book is only partly true. For us who know that programming is just applied mathematics a good reference book is the best teacher.

Pic related, me to the right using C to fight some horrible OOP creation that uses 4 Kb of memory per instance.

>>11625
Thanks! I'll check it out too.

>>

 No.11640

File: 1446887298719.jpg (66.92 KB, 590x632, 161017757_44042348.jpg) ImgOps Exif iqdb

>>11639
>For us who know that programming is just applied mathematics
lel, k tard.
http://plato.stanford.edu/entries/computer-science/#Pro

>>

 No.11641

>>11639
> some horrible OOP creation that uses 4 Kb of memory per instance.
Nice meme. What's up with all the C fanboys thinking they hold the ultimate truth and everyone else is wrong?

>>

 No.11642

File: 1446893949762.jpg (56.99 KB, 500x600, C vs OOP in Oracle Java.jpg) ImgOps Exif iqdb

>>11640
A good algorithm on an low-performing computer will always beat a bad algorithm on a high-performing computer.

And exactly where did your link contradict me? Applied mathematics implies a lots of physical manifestations. Paper, pen, eraser, black/whiteboard, calculator, rulers, etc, etc, etc.

Also applied mathematics doesn't imply that it has to be fancy. Consider COBOL. It's made for accounting. True, you could say that it's more calculations than pure mathematics. But still, a better algorithm will make the tedious tasks better. Let's say that you want to calculate the price of something before a VAT of 15% was added. Here's a really bad way to do it:

price_no_vat = price_with_vat / 115;
price_no_vat *= 100;


And here's a better way:

price_no_vat = price_with_vat / 1.15;


Pretty basic algebra. Let's up the ante, shall we? Let's calculate the value of VAT. Here's a bad way:

vat_amount = price_with_vat / 115;
vat_amount *= 15;


And here's the better way:

vat_amount = price_with_vat * 15 / 115;


And it works even better if VAT is a variable:

vat_amount = price_with_vat * vat / (100 + vat);


Multiply this task with a few 100 000 or 1 000 000 and you'll see why it's better. :P


>>11641
Well, C is the base of C++, C#, Objective-C and so on. But do try to fiddle around with "bare metal" using Java C#. B-) Of course I will learn C++ and Objective-C. But as for now, the gnosis of C will do.

>>

 No.11645

>>11642
I'm sure it's pretty cool from a mathematical point of view, but please never use floats for money in a real system, they are inaccurate and someone will lose money on it.

>>

 No.11646

>>11642
What point are you trying to make by solving a trivial pen and paper problem in the most long-winded way possible?
>>11645
No types were defined, why do you assume he's using floats?

>>

 No.11654

>>11645
Good point! Thanks!

>>11646
The case for good algorithm is still valid. Of course I could use a more cumbersome example. Buy this was more simple.

>>

 No.11655

>>11642
I don't understand what the difference is between the "good" one and the first "bad" one. At best the "good" is slightly slower than the "bad" one. Sure, it is more flexible but from what I can tell your goal is to make it faster. It would also be easy to make the first one just as flexible as the last one by making the value 115 a variable.

Writing everything on one line does not, in fact, make the code run faster.

>>

 No.11660

>>11642
: vat  15 115 */ ;

C programmers are truly enlightened.

On a 32-bit machine, this uses a 64-bit intermediate result.

>>

 No.11666

>>11642
>And exactly where did your link contradict me?
have you read

7. Programming
7.1 Programming as a Mathematical Activity
7.2 Programming as Engineering Design
7.3 Programming as Theory Construction

>>

 No.11669

File: 1446931625812.jpg (1.87 MB, 2000x2610, c_unites_workers.jpg) ImgOps Exif iqdb

>>11641
Because the lower level you go, the more hardcore you grow.

>>

 No.11672

>>11241
>thought it would teach me more about how computers work than java has
In a way it does. You learn about pointers, manual memory handling and difference of signed/unsigned. But then you realize it's all just abstraction and design choices anyways. Don't worry, learning C is very good but don't think it's "closer to the metal". It's still a compiled language that doesn't map directly to hardware.

>>

 No.11684

>>11639
Programming in C is about as far as you can be from "programming as applied mathematics".

The fact that you're even talking about "memory" is evidence of that. What is "memory" to mathematics?

C programming is "applied von neumann computer fiddling".

>>

 No.11685

>>11684
Perhaps the concept of memory is where the "applied" part comes from.

>>

 No.11692

>>11685
That's stupid. By that logic, everything is "applied mathematics", mathematics with accumulated circumstantial limitations that have no universally applicable principles. Not mathematics at all then, just fiddling with a thing that doesn't work how it really should.

Low level programming is the opposite of mathematics, because it forces you to deal with non-mathematical mechanisms. High level programming is mathematical specifically because it abstracts away the non-mathematical reality of the computer and allows you to apply mathematics directly, so long as you have a fast enough computer.

And our computers are now very, very fast.

>>

 No.11706

>>11692
Memory usage and time are the only two resources that are accounted for when discussing an algorithm. I certainly remember my algorithms class talking about the space complexity of certain algorithms, and even discussing whether the algorithm can be done in place (which in general will only affect the constant in front of the space complexity).

Sure, you can argue that C forces you to consider the constant factors of space complexity. But to say that if you aren't ignoring memory usage you aren't doing applied math is wrong.

>And our computers are now very, very fast.

Then why does everything on my phone take seconds to load? Why does my phone lag? Why do half the programs I use at work put up a splash screen when loading? I'm sick of waiting for my computer and later reading that computers are "fast". If my computer really was fast I wouldn't need to be reminded.

>>

 No.11738

>>11706
Not the same guy but
Your phone lags because it's using jabba
And it's soykaf you should've saved a little more and buy a good one
It bothers you because you're unaware of all it might have to do to keep up with your playing angry birds while the facebook and google apps send all your sensitive data to the juice.
And computers are very fast, they've been steadily growing in speed for the past few decades, but you didn't really get to use a 386, you expect your phone to be faster than it is, amd so you think it's really slow.
In fact, computers are now so fast, that developers don't care much about efficiency nowadays, let an app interpreted by a virtual machine run an interpreted language itself, and let that language have poor algorithms doing fancy useless stuff on top of a hundred frameworks all piled up on top of each other because that's what an elite js programmer do, put eveey possible framework in a website evem if there's no need for it

>>

 No.11741

>>11738
Those were rhetorical questions.

>>

 No.11757


>>

 No.11766

File: 1447076947192.jpg (27.92 KB, 668x491, Pascals triangle.jpg) ImgOps Exif iqdb

>>11666
Nope. Please post some quotations that supports your case the best.

>>11692
>And our computers are now very, very fast.
Still no excuses for sloppy algorithms. Consider Pascal's triangle. One of the things it is a representation of possible combinations (foobar) of participants (bar) and those who show up (bar).

When foo is 0, then bar must be 0 and foobar is 1, and so on:
foo 1, bar 1, foobar 1
foo 3, bar 2, foobar 3 etc...

One atrociously sloppy way to calculate foobar is to let foo be the bit length of a digit and bar the amount of 1:s. Then you decide the largest foo-length binary number with bar 1:s and start to count down to the smallest number with bar 1:s:
foo 3, bar 1

100 - foobar++
011
010 - foobar++
001 - foobar++
This was just a simple case with only one negative hit. But if foo = 20 20 and bar = 5, then the amount of negatives are just too much.

The simplest way to decide foobar is to use a binominal equation (something that I can't do yet). One middle way is to use a matrix that simply creates a Pascal triangle. Not as efficient as that equation, but far better than than wading trough lots of negative hits.

My 2 cents? A C-64 using the matrix method can probably calculate the foobar of really high foos better than a modern computer using the "bit-method".


>>11706
Well, I'm taught that there's no excuses for bad algorithms. Consider this:
foobar = foo + 1 + bar - 1
Any middle school pupil realizes that the +-1 is just filling and will simplify it to:
foobar = foo + bar
But this simplification won't happen in the compiling, because the compiler can't decide that "This is just soykaf, I'll disregard it."

And of course programming is lots of other things than applied mathematics. But the fact that I prefer to sit on a comfy chair by my desk when I program doesn't make programming applied mathematics + a comfy chair.

>>

 No.11787

>>11642
I stand corrected. The two-line algoritm of vat_amount is just a little slwoer than the one-line. And both are far better than the third, really convoluted I believed was best:
#include <stdio.h>
#include <time.h>
int main()
{
clock_t begin_process[3], end_process[3];
double time_spent[3];
int algo = 0, total_algos = 3;
float price_with_VAT, VAT_percentage, VAT_absolute;
long int i, algo_loop;

printf("This program tests the efficiency of various algorithms of calculating the VAT.\n\n");
printf("Enter the price with VAT: "); scanf("%f", &price_with_VAT);
printf("\nEnter the percentage of VAT: "); scanf("%f", &VAT_percentage);
printf("\nEnter how many times you want the algorithm to be looped: "); scanf("%d", &algo_loop);

for(i = 1, begin_process[algo] = clock(); i < algo_loop; i++) {
VAT_absolute = price_with_VAT / (100 + VAT_percentage);
VAT_absolute *= VAT_percentage;
}

end_process[algo] = clock();
time_spent[algo] = (double)(end_process[algo] - begin_process[algo]) * 1000.0 / CLOCKS_PER_SEC;
algo++;

for(i = 1, begin_process[algo] = clock(); i < algo_loop; i++) {
VAT_absolute = price_with_VAT * VAT_percentage / (100 + VAT_percentage);
}

end_process[algo] = clock();
time_spent[algo] = (double)(end_process[algo] - begin_process[algo]) * 1000.0 / CLOCKS_PER_SEC;
algo++;

for(i = 1, begin_process[algo] = clock(); i < algo_loop; i++) {
VAT_absolute = price_with_VAT / ((100 + VAT_percentage) / VAT_percentage);
}

end_process[algo] = clock();
time_spent[algo] = (double)(end_process[algo] - begin_process[algo]) * 1000.0 / CLOCKS_PER_SEC;
algo = 0;

printf("\n\nVAT_absolute = price_with_VAT / (100 + VAT_percentage)\nVAT_absolute *= VAT_percentage");
printf("\nTime passed: %f ms", time_spent[algo]);

algo++;

printf("\n\nVAT_absolute = price_with_VAT * VAT_percentage / (100 + VAT_percentage)");
printf("\nTime passed: %f ms", time_spent[algo]);

algo++;

printf("\n\nVAT_absolute = price_with_VAT / ((100 + VAT_percentage) / VAT_percentage)");
printf("\nTime passed: %f ms", time_spent[algo]);
}

>>

 No.11794

>>11766
>But this simplification won't happen in the compiling, because the compiler can't decide that "This is just soykaf, I'll disregard it."
Actually that's exactly what happens.
$ cat a.c 
int add(int foo, int bar)
{
return foo + 1 + bar - 1;
}
$ cc -c -Os a.c
$ objdump -S a.o

a.o: file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <add>:
0:8d 04 37 lea (%rdi,%rsi,1),%eax
3:c3 retq

>>

 No.11802

>>11794
So exactly how much leeway will a compiler give you?

>>

 No.11809

>>11802
Modern compilers give you lots. They do as much as they can to optimise the resulting code, though it can be disabled through compiler flags. This specific example is known as constant folding.

>>

 No.11811

>>11809
So disabling the compiler flags is good for you?

>>

 No.11813

>>11794
>>11802
>>11809
>>11811
The problem with C is it doesn't provide any standard way to communicate with the compiler, except for register and perhaps one or two other things I'm forgetting.

This is why C compilers are now millions of lines long, because they need that to have an optimized program.

>>

 No.11926

>>11262
Fuck macros. Nearly puke every time I see a code macro.

>>

 No.11949

>>11813
What's your point? That optimizing compilers are bad?

>>

 No.11951

>>11949
Complicated compilers are bad.

Really, I'm skeptical that any program _needs_ to be 1000 lines long.

Now, if a standard library has 1000 functions, you're probably not going to be able to implement it in 1000 lines, but I think you get my point.

>>

 No.11953

>>11951

>Really, I'm skeptical that any program _needs_ to be 1000 lines long.


I hope this is rhetorical

>>

 No.11955

>>11953
I don't know what you mean.

Obviously you can extend programs with your own customizations, like you see with text editors, but operating systems and probably anything else can fit in 1000 lines if you try.

It's hard to do if you're going to just write a program without thinking, but careful consideration can make very efficient and very compact programs.

>>

 No.11956

>>11955
>operating systems and probably anything else can fit in 1000 lines if you try
I'm not sure if you're trolling.

>>

 No.11957

>>11956
I'm not trolling.

Do you think all of the operating systems for microcomputers and others were thousands of lines long, to give some examples?

>>

 No.11961

>>11955
>operating systems and probably anything else can fit in 1000 lines if you try.

I've written very very small operating systems.

The smallest one with any features you could reasonably expect today was well over 1000 lines.

>>

 No.11963

File: 1447463621282.png (51.23 KB, 1199x224, ide.png) ImgOps iqdb

>>11961
Chuck's site is currently having issues and so I can't get to the distribution to judge exactly how large the system is, but colorForth may have all or most of the functionality in under 1000 lines.
Here's an IDE driver in 5 lines:
http://www.colorforth.com/ide.html

Forget about operating systems though. Think about other programs now. Can you think of anything else that _must_ be expressed in more than 1000 lines?

>>

 No.11964

>>11963
an IDE driver is not the same thing as a full virtual file system.

as for other applications, I'd point to video games.

>>

 No.11967

>>11964
>an IDE driver is not the same thing as a full virtual file system.
ColorForth just writes directly to disk blocks. There is no filesystem. There's only numbered blocks.

>as for other applications, I'd point to video games.

That's similar to the above example of a standard library. If you're designing a video game, just the writing may take up tens of thousands of lines.

There's obvious limits on what you can fit in so much space, but I still don't think so many programs need to be 50,000 lines or however long. If you want a concession, I seriously doubt any program I use needs to be more than 10,000 lines long.

Try looking at TempleOS as another example. It fits games, documentation, and everything else in less than 100,000 lines. It's actually auditable by a single person. It's important to have software that a single person can fully understand.

Just trying to read some program sources isn't feasible because there will be thousands of lines alone dedicated to header includes and other cpp needs.

>>

 No.11969

>>11957
Sure. I don't disagree with the idea that useful and correct software can be written in 1000 lines. But there are large and complex systems that need to be controlled, and complicated languages that need to be compiled, as well. I don't think you could write an OS/compiler/etc. for those in under 1000 lines.

>>

 No.11982

>>11967
>There's obvious limits on what you can fit in so much space, but I still don't think so many programs need to be 50,000 lines or however long. If you want a concession, I seriously doubt any program I use needs to be more than 10,000 lines long.
How do you read and post to this website? cURL running on an rtos?

>>

 No.11987

>>11982
>How do you read and post to this website? cURL running on an rtos?
I currently use Firefox. I really hate it. It crashes constantly.
Lainchan is one of the only websites I use anymore and certainly the only one that I have problems browsing with links or eww.
It has a simple API, so I have considered building a utility specifically for using the site. I'm busy with a few other things though, so it's on the back burner.

>>

 No.12059

>>11201
>reading through k&r
>word count program
>copy code to the letter
>compile and run
>the word count of "Hello world": 1431706545
the fuarrrk?

>>

 No.12061

>>12059
nvm forgot to initialize

>>

 No.12097

File: 1447863091816.jpg (222.89 KB, 900x675, 1434472323789.jpg) ImgOps Exif iqdb

>>11309
You have successfully cracked the patter in posts where people fake knowledge in the topic.



Delete Post [ ]
[ cyb / tech / λ / layer ] [ zzz / drg / lit / diy / art ] [ w / rpg / r ] [ q ] [ / ] [ popular / ???? / rules / radio / $$ / news ] [ volafile / uboa / sushi / LainTV / lewd ]