[ art / civ / cult / cyb / diy / drg / feels / layer / lit / λ / q / r / sci / sec / tech / w / zzz ] archive provided by lainchan.jp

lainchan archive - /λ/ - 21073



File: 1482561702094.png (865.28 KB, 212x300, patches.png)

No.21073

This is the Beginner's General for beginner's questions.

If you have a simple question and a suitable thread doesn't already exist, just post it here and someone will probably try to answer it for you.

Remember to do some research before asking your question. No one wants to answer a question that a simple search can already resolve.

  No.21074

To the fellow wondering about parsers from the last thread:
Assuming the language you're doing this with has all of the JSON datatypes, that's what you should compile it to.

I'll use Common Lisp as an example, as it easily allows the programmer to have the parser execute arbitrary programs upon finding certain characters. So, [ begins creating an array and { begins creating an object. What makes it simple is that the parser handles the nesting for me, as I could begin parsing anew in each of these programs and so have it do most of the work for me. In short, reach a character and begin compiling the data; upon encountering other building characters, nest and do the same.

So, a JSON parser really only need dispatch on characters like this. I'll point you to the library if you want.

  No.21075

To anyone that's curious about what the thread pic is of; it's a page in Thinking Forth :)

  No.21076

>>21075
Yes. All of these Beginner's General images are from that work.

  No.21079

>Home for Christmas
>Bought the C++ primer so parents would think I was doing something productive on my computer
>I'm probably not going to open it
How do I make it look like I know how to code

  No.21080

>>21079
Learn Python, it is easy and useful.

  No.21082

>>21079
Learning Python is terrible advice, as Python is a terrible language. On that note, so is C++.

Learn RPN and learn how to program a simple stack machine. Then go from there. I can elaborate, if you want.

  No.21087

>>21082
So is everything made made in MIT. Forth is garbage too.

  No.21088

>>21079
play nethack or go to telehack.com. Otherwise just open tmux with a few panes, with stuff like top(1) and keep irssi in one panel and idle all day at #lainchan.
on the other hand you should consider trying to actually code, the stack machine idea is good

  No.21092

>>21087
Then what's something good based on your opinion?

  No.21103

>>21079

Dunno why you'd do that, really. If you got no interest in coding, why pretend to know how to code?

There are an unlimited number of productive things you can do on a computer (contrary to popular belief, the weren't invented for porn and Facebook games), surely something will interest you. Or hell, put the C++ book to use - install Unreal and work through some tutorials on game making.

  No.21112

>>21087
Python isn't from MIT.

However, you could make the arguement that Lisp is.

  No.21114

>>21079
Pick a random tutorial online, specially something practical, step-by-step. Follow a random guide and make a little software, shouldn't take more than a week, spending half an hour every day or even less.

  No.21122

File: 1482769844510.png (1.37 MB, 200x65, 3.26 sicp.bmp)

>>21047

So, had i structured the procedure in a way that it mutates the table with set-cdr instead of set! like i did with the exercise 3.25 (see picture), i would not have problems related to shadowing?

Anyways, i solved 3.26, but using 1 key records instead, here's the solution:

(define (entry tree) (car tree)) 
(define (left-branch tree) (cadr tree))
(define (right-branch tree) (caddr tree))
(define (key entry) (car entry))
(define (make-tree entry left right)
(list entry left right))

(define (adjoin-set record set)
(cond ((null? set) (make-tree record '() '()))
((= (key record) (key (entry set)))
(make-tree record
(left-branch set)
(right-branch set)))
((< (key record) (key (entry set)))
(make-tree (entry set)
(adjoin-set record (left-branch set))
(right-branch set)))
(else (make-tree (entry set)
(left-branch set)
(adjoin-set record (right-branch set))))))


(define (make-table)
(let ((table '()))

(define (lookup key records)
(cond ((null? records) false)
((= key (car (entry records))) (entry records))
((< key (car (entry records))) (lookup key (left-branch records)))
((> key (car (entry records))) (lookup key (right-branch records)))))

(define (get key)
(lookup key table))

(define (insert! key value)
(let ((record (lookup key table)))
(if record
(set-cdr! record value)
(set! table (adjoin-set (cons key value) table)))))

(define (dispatch m)
(cond ((eq? m 'get) get)
((eq? m 'insert) insert!)
((eq? m 'show) table)
(else (error "Undefined operation -- TABLE" m))))
dispatch))

(define test-table (make-table))
(define (show table) (table 'show))
(define (get key) ((test-table 'get) key))
(define (put key value) ((test-table 'insert) key value))

---------------------------------------------------------------------

> (put 1 'carrot)

> (put 2 'onion)
> (put 3 'lettuce)
> (get 2)
(mcons 2 'onion)
> (put 4 'tomatoe)
> (show test-table)
(mcons
(mcons 1 'carrot)
(mcons
'()
(mcons
(mcons
(mcons 2 'onion)
(mcons
'()
(mcons
(mcons
(mcons 3 'lettuce)
(mcons '() (mcons (mcons (mcons 4 'tomatoe) (mcons '() (mcons '() '()))) '())))
'())))
'())))
> (display (show test-table))
((1 . carrot) () ((2 . onion) () ((3 . lettuce) () ((4 . tomatoe) () ()))))
> (put 0 'orange)
> (display (show test-table))
((1 . carrot) ((0 . orange) () ()) ((2 . onion) () ((3 . lettuce) () ((4 . tomatoe) () ()))))

  No.21136

>>21122
>set-cdr instead of set!
>not have problems related to shadowing
In order to use set-cdr! there has to be a non-null cons cell to modify. With an empty tree there is no such cell, since a dummy node doesn't make sense for a binary search tree because you cannot predict the key type. The easy way to avoid shadowing interfering with assignment is to choose a different argument name.

Your code exhibits the expected behavior to its callers, but there are two problem areas.

First, you are breaking abstraction when doing (car (entry records)) in lookup and (set-cdr! record value) in insert!. It's much cleaner to have all interactions with tree nodes and entries go through the abstraction methods which hide their internal structure.

And second, adjoin-set rebuilds the tree along the path from the root to the insertion point. This was fine in the previous chapter when mutation wasn't available, but in this chapter you're supposed to take advantage of mutation to avoid such global rebuilding. You also have the side-effect of duplicating the entire search when inserting new keys, once in lookup and again in adjoin-set.

In the mutation chapter you should perform a single traversal from the root to the insertion point, then mutate as needed. For example:
- handle the empty tree case separately and get it out of the way
- subsequently always have a non-null current node
- on key match mutate the value
- before recursing on the appropriate branch, check for a null branch and handle it by inserting under the current node
- only recurse into non-null branches

And some notes:
- In lookup, after testing for = and < the > test is redundant.
- Instead of getting the key of the entry of the current node multiple times, a let would be cleaner.

  No.21162

How do i get started with web development?

Im looking for a getting started guide in something that isnt php basically.

I want to write a pastebin clone, and i had a sort of one in rust but i was running into threading errors and stuff, so i figure should actually learn what you're supposed to do first.

  No.21163

>>21162
If you don't know a programming language, learn one. Either way, you'll need to know a scripting language or other HLL. Whether it's Python, Ruby, Perl, Bash, or even Lisp, it doesn't matter.

The fastest way to get into server-side web development is CGI. It's relatively slow, but it's also dead simple, and can do what you want. As implied above, you can do CGI work in any language. Just read the docs for your webserver (how to enable CGI, and get it to run your code): if you haven't picked one, I suggest lighttpd. Also read RFC3875, which explains CGI itself.

From there, it's pretty simple. If you want to get into more complex things, stuff gets more language specific, and you might have to deal with FCGI, WSGI, etc., or even something else entirely.

  No.21175

>>21162
In addition to what >>21163 said, see if your language of choice has any libraries to deal with the web server plumbing. Most languages have some sort of tiny web framework (eg, in Python I'd go for Flask) which handle decoding requests, routing them to functions, and returning responses to the web server for you.

  No.21176

>>21175
...Which also means that you don't have to rely on CGI itself, making your apps faster.

  No.21191

I am currently working on a project in game maker studios where should i start? Is there any better place to start?

  No.21194

>>21191
try to be more specific in your questions, I don't understand what you mean. Your desk is probably a good place to start.

  No.21199

Why is using gdb with systemd such a hassle? I just looked up info on were systemd keeps coredumps but the fix only served to break gcc (I think).

/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

this is what it is giving me now at compile. Before the fix it gave no errors (but also made coredumps a PITA)

  No.21204

>>21199
Just disable systemd's coredump collection feature.

Or uninstall Lennart's soykaf alltogether.

  No.21207

how do you backup/restore docker named volumes?

When I google it, all I can find is the process for volume containers

  No.21267

>>21255

One idea is to have a keystroke timer. If the user has typed something in the last five seconds, just hold the message.

If the user hasn't, or if a message is being held and the timer times out, then delete everything the user has typed so far, print the new message, and replace what the user typed.

This will probably require putting the terminal in raw or cbreak mode and keeping keystrokes in a buffer. The easiest way to do that is to just use curses. You can use curses for a lot of stuff besides just full-screen terminal apps.

  No.21279

I started to code in C some months ago but didn't continued for some reasons. Now I get in it again and I'm learning structure. But when I've seen the syntactic sugar foo->bar that replace (*foo).bar I just thought "why adding always symbols ?" - So would you consider a code that don't use the syntactic sugar still as a good code ?

  No.21280

>>21279
in C, I think it's more readable to use foo->bar than (*foo).bar. The latter one is hard to read, and the -> symbol takes the place of a very common idiom. It's also easier to remember and think of how you'd do foo->bar->baz without the sugar.

  No.21284

>>21279
>I started to code in C some months ago but didn't continued for some reasons.
It's not a great language.

>But when I've seen the syntactic sugar foo->bar that replace (*foo).bar I just thought "why adding always symbols ?" - So would you consider a code that don't use the syntactic sugar still as a good code ?

Syntactic sugar causes cancer of the semicolon - Alan Perlis

The C language has a great deal of syntactic sugar and doesn't allow the user to define their own. With all of this said, -> is too common and simple to avoid using. Almost every C program will use it and it's good style in C to do so.

  No.21291

>>21280
>>21284
Thanks for those answers.

For the later one. Do you know an imperative language (c-style) that allows you to define your own syntactic sugars ?

  No.21293

Hey besides *, what are some similar search keys I can use? I looked up regular expression, but it is very inconsistent, I want to know what each symbols do.

  No.21294

>>21293
If you are looking for bash shortcuts: type "linux wildcards" in Google. Else, learn regular expressions: they are the most powerful way to do such a thing.

  No.21296

>>21293
You can use ? to mean one or none of the previous character.
Anything between brackets can be matched [] whereas anything between brackets beginning with a caret is ignored.

You're correct in that regular expressions are very inconsistent, I mostly described bash; one solution is avoiding them.

Bash also allows you to use {a,b,c} to specify patterns a, b, and c, along with any others delimited by commas.

  No.21297

>>21291
>Do you know an imperative language (c-style) that allows you to define your own syntactic sugars ?
No; I don't use C style languages and also aren't aware of any that have that characteristic.

  No.21299

>>21291

I haven't tried it, but check out Seed7.

There is also operator overloading. Again, I haven't tried it, but Algol 68 allowed you to define your own operators in a more general way than, say, C++. There are some interpreters that are fairly recent, but I don't know if any Algol68 compilers still work.

  No.21301

Can a good samaritan review a code I just did ?

I tried to implement linked-lists.

http://sprunge.us/ZOLC?c

I checked it in Valgrind and it found 0 memory leaks.

  No.21302

>>21299
Thanks for this one.

  No.21303

>>21301
The structure "first" is simply a pointer on node, so it's a bit useless.
Also, init_list() doesn't free the former children of the list, so you can use it to init a list, not to reset it.

  No.21304

>>21303
Yeah thank you for your help

  No.21305

>>21303
I think that this structure is actually useful: when you initialize a list you might not put content in it. But as I'm just starting maybe I say too much bullsoykaf xD

  No.21308

>>21301
>http://sprunge.us/ZOLC?c

>void print_ll (first *starting_point) {

Try it on an empty list.
>malloc(sizeof(char) * strlen(str) + 1);
If you choose to use sizeof(char) the order of operations is wrong.
>void print_last (first *list) {
Try it on an empty list.
>void remove_list (first *list) {
Try it on an empty list.

  No.21309

>>21301
"copy_node" does not free the previous string in dst. It's also very similar to "create_node", maybe you could one in the other.

  No.21310

>>21309
>>21308
Thanks for those answers

  No.21311

>>21308
I fixed the empty list cases. But I don't get the point about malloc.

  No.21312

>>21311
It's "malloc(sizeof(char) * (strlen(str)+1));"

Notice the parens.

  No.21314

>>21312
Oh yes thanks. I didn't noticed.

  No.21334

>>21333
Go to /tech/. Your question isn't about programming and is better suited to the Technical Talk Thread: https://lainchan.org/tech/res/32465.html

  No.21335

fuarrrk, I dont know who I want to be anymore. Few months ago I have decided to be an computer scientist and started to read SICP, some math books, bought Arduino. And about a week ago I realised that I really want is to make games, I started to learn how to draw, play around in GameMaker. And now I have no idea in which way to proceed, cs or gamedev.

  No.21336

>>21335
you sound just like me (except I'm between lisp and low level).
My advice is don't sweat it, do each when you feel like it, each can even be an aid to each other in some way.

  No.21337

>>21335
>>21336

Sounds similar to me as well.
I practically stopped caring about school (not uni) and spent my time programming and messing around. My parents were expecting me to go somewhere like MIT so it really hit them hard when they realized that wasn't the case.
I'll probably end up getting a comp sci degree from an average uni.

All I can say is whatever you choose, stick with it.

  No.21338

>>21335
>>21336
>>21337
This isn't /feels/.

  No.21352

Ok so this is a realitively simple question. I've created a script to backup my files with cron (https://ghostbin.com/paste/xuwjt) and currently it writes the archive to my hard disk before encrypting, then uses rm to delete it (because using srm is time-consuming for a 200mb file). Is there a way to store the archive in ram, encrypt it, and then write it to the hard disk so the unencrypted archive doesn't stay on the hard drive?

  No.21355

>>21352
Perhaps a ram filesystem?
in linux it's something like
mount -t tmpfs -o size=[SIZE] tmpfs [MOUNTPOINT]
Be sure to do your due websearch before you try stuff.

  No.21362

I don't understand. What syntax should I learn from: Python 2.x or 3.x

Trying to get a quick understanding with PTHW(Python the hard way) but it seems kinda dumbed down like I shouldn't be wasting my time and use an actual book.

  No.21364

I'm a freshman who had a change of heart regarding majoring in comp sci. I'm coming in with AP credit for the first level course and are trying to graduate as soon as possible for financial reasons, but are panicking because I'm significantly rusty in the subject. What's the shortest possible introduction to basic concepts in programming (specifically soykaf like sorting algorithms, recursion, etc) that you're aware of?

  No.21365

>>21362
Perhaps python is not a good language to learn. For starters, Zed's books suck ass. And then there's still this version breach with python, even though python3 has been out for years.

There are much better languages to learn than python. Take a look at Racket or Ruby which pretty much have the same scope only they are better.

But if you really need python for some reason, go for python3.

"Learning python" is really just learning to program in the procedural version of object orientation. There is not much more to the language itself, it's usefulness relies on the libraries and the ease of development, but python itself doesn't need any learning beyond the syntax if you already know how to program.
That said, you need a book that teaches you how to program. Perhaps "How to think like a computer scientist" would then be a good python book. But again, consider ñearning Racket instead, The Little Schemer would be the book to get started. Also much more entertaining than a dull intro book.

  No.21367

>>21365
I think you're looking at the subject as a seasoned programmer and dont see the value in kind lf dull intro books.

Python is a great first language, also if you learn anything it should be 2.7, nobody really uses 3.x in any company I've been working at, simply the libraries are not there, lots of legacy plugins would need to be ported for that still. Also as you pointed out the whole point is having all those libraries, that's why 2.7 is still better.

I dont like Zed personally, but his python series is geared towards total begginers and really drills the basics into you. I would recommend it as a starting point.

I would have loved to start out with python instead of pascal, c, assembly, c++ then java and finally python. It just feels more fun.

  No.21372

>>21367
Python lacks too much to be a good language - no monads, no proper lambdas, no macros system, OOP model is subpar at best, syntactically stretched to the point where it rips all round stitches. Not to mention 2-3 schism and low execution speed.
Haskell, on the other hand, has entire great mathematical foundation under it, is efficient and it is simply much more to work with and doing all sorts of amazing abstraction. If you want to do programming, why use inferior tools? Better start right.

  No.21373

>>21372
Python has loads of material for beginners and most of Haskell's is intended for experienced programmers and heavily draws from imperative programming comparisons, especially early on (the worst possible time for complete beginners). Python has good libraries and speed critical things can be done in C to run faster than Haskell. It's obvious that Haskell is a better language but when you want to teach how to program eg a dynamic website it's much easier to not have to explain a concept like monad transformers. Speed generally isn't a problem in my experience with either language.

  No.21375

File: 1484256742326.png (26.91 KB, 167x200, 9eb8c63cac463672c38feae5a14714cc69bfdb11ced9b2af618ca376cfc02e89.jpg)

>>21372
>languages are soykaf if they don't have monads

  No.21382

>>21373
I disagree with python being a good beginner's language. Sure it keeps you from any language specific features, but it also is much too limited, it just teaches you to think sequentially and not even the way the computer would do it. Plus it forces OOP on you very early. And as >>21372 pointed out, it lacks any interesting feature, that's the worst thing with python, which supports it's "There's only one way to do it" mindset.
Haskell is not bad at all for beginners, you don't need to be an experienced programmer and you can learn programming starting from the functional approach perfectly well. Whatever language you learn, you are being taught the model of the language as well. If it's an imperative, you learn imperative, if it's a functional, you learn functional, if it's a lisp, you learn spooky parentheses magic.
I've heard that some people that started with imperative struggle with haskell, however if haskell is your first (a very good option, better than python imho) you won't struggle because it's your first.
But it does depend on why the guy asking the question wants to start programming. If he wants a job, maybe python is an option. If he wants to learn programming for it's own sake, any of a handful of languages (Lisp, C, Haskell, Forth, Assembly, are imo good starting languages) will do.
From experience though, I do believe that the language you start with shapes the way you approach programming onwards.
But python is pretty much nothing. Even if he wants the `usefulness' of python, as I said, you don't really need to learn it, and starting with haskell or lisp will free his mind.

  No.21396

>>21382
>I disagree with python being a good beginner's language.
I never said anything about the language itself being good, I just meant that it has a lot of good materials that lead students to success when they try it. (FWIW, you replied to my first post in the thread-- sorry! Probably should've mentioned that.)

>forces OOP on you very early

This is not true. Think Python (great book!) doesn't emphasize OOP very much, focusing on recursion and abstraction (using functions).

>it lacks any interesting feature

"Interesting" doesn't mean very much for beginners. I agree that monads are more interesting but there's nothing wrong with a student learning Python and then picking up Haskell.

>I've heard that some people that started with imperative struggle with haskell, however if haskell is your first (a very good option, better than python imho) you won't struggle because it's your first.

I've never read a decent Haskell book written for a beginner, most stack overflow Haskell questions aren't about basic soykaf. The best books and courses for learning Haskell assume prior programming experience. While its true that you can have a weak understanding of monads and write IO code, for most nontrivial tasks it becomes much easier if you do learn about them early on (along with functors, applicatives etc). This is a lot for a beginner to pick up, and will possibly bore them. A language where writing fun stuff like

>From experience though, I do believe that the language you start with shapes the way you approach programming onwards.

I agree completely here. I think that teaching Haskell immediately to beginners is a mistake, but introducing it very early is a good idea, along with Lisp. I think that branching out early and often in terms of languages is a good idea and strengthens your programming abilities in general. I think learning and only using Haskell is just as bad as learning and only using Python. (Well, maybe a little better, if you manage to stick with it. It'll be harder though. What's important is branching out.)

>But python is pretty much nothing.

This isn't bad! A beginner can learn a lot just from functions and some basic data types. Scheme is a good example of this. I would argue that a simpler language is better for a beginner than an advance one, but at the core of most languages is a very simple language, and one can usually just teach this.

  No.21397

Arguing about beginner languages is a waste of time. Just pick one you like and have fun with it, it doesn't really matter.

  No.21401

>>21397
You are absolutely right. Djikstra "Basic will make you braindead" is garbage (well not really, I got his point but for beginners that is true).

1 - Take whatever language and code, the one with the most and best educational ressource and that will get you result fast. Take a basic dialect with good graphics package and a good IDE with a built in debugger and just do stuff
Don't try to do fancy project do small, one afternoon level project, keep the feedback loop short.

2 - Read good code, but don't dive directly into big project. Take one page code and don't just stare at it. Think a little about hypotheses you can make on the code, step through a debugger to verify them and only then start to really think about it. Empiricism is your friend.

3 - Once you have a good amount of practical exp, dive into more theoretical book, it will make a lot more sense by then. Read it and compare it to your project, there should be a constant back and forth.

4 - With what you learned, look at all the software you use and try to think about how it works, then check code if it is available. Or better yet learn to reverse engineer. It will show my security bias, but trying to guess compiler output and comparing it to the real thing is a fun and rewarding experience.

5 - Relating to the above if you like how computer really works, go check the Nand2Tetris course as well as CS351 (both available online), they give you a really nice overview of the hadware and software interact. Btw, typing "<computer topics> assignment" will give you lot of nice ressources on the web.

That was a bit ranty, but if you are beginner, you should first experiment, a lot, and have an exploratory approach to programming. I think lot of good coders forget their beginning with 80s era computer, with their ,sometimes clumsy, but tight and focused programming environment and their fantastic accompagning book.

  No.21403

>>21397
>>21401
I object.
Maybe this topic merits it's own thread, given the discussion that has developed.
But as I said before, the first language you learn shapes the way you see programming. Of course it depends on the goals of the person who wants to learn, for some python may be the best option by far. >>21396 got me in all points indeed.
But again, some languages will teach you to think sequentially, and some others more theoretically. It's not the same to start with python or C than Haskell or Lisp.
Again, maybe a new thread for this to avoid further derailment.

  No.21408

>>21403
I started with an imperative language, but almost every other language I've learnt changed how I saw programming, sometimes radically. What you start with doesn't matter, you are just confusing beginners. Instead, we should encourage more experienced programmers to learn a wide variety of languages in all the important families and paradigms, so they can develop a more well-rounded view of programming and hopefully grow out of this ridiculous language elitism.

  No.21409

>>21403
This is an appropriate thread that already exists: >>13410

  No.21435

So after reading through this thread and a few other threads on /lam/ I'm gonna start with Haskell after not touching programming for nearly 3 years. I used to use C++ and Python pretty consistently, but after starting college in a different field I completely forgot everything about programming besides the raw basics. What's a good place to start for Haskell (like what install, etc.) and is there anything else I should install to help out? I have NPP as well.

  No.21436

>>21435
ghc is the de facto implementation for haskell
http://learnyouahaskell.com/ is a good place to start.

  No.21442

Anyone got a recommendation for a good book or resource for someone that is already a programmer but wants to pick up Ruby?

Seems like everything I find is either "Ruby for beginners" or is all about Rails and assumes you already know Ruby.

  No.21458

>>21442
Ruby is super easy to learn by practice. Search Ruby basics and then try to get the usage of gems and POO. If you are French I can give you a good link.

  No.21467

>>21458

Nope, I'm not French, but thanks for the offer.

Ruby does seem relatively simple to pick up. I just want to make sure I don't miss anything important. Learning a language just by diving in and writing code can lead to a spotty understanding of the language.

  No.21468

>>21467
That was my approach. You can read Ruby Under a Microscope or Metaprogramming Ruby when you feel at ease with the language to fill the spots.

  No.21474

Should I read a book on how to program, as in the structure of programs and what is a good way to do it or just learn about how things work in the languages I want to know [ex. learning how to make/apply arrays in python or C or something]

Would it be better to have a book on something like how-to:programming as I follow through something short like K&R?

Im afraid I'll learn the syntax of languages and how to make things happen in those languages but if it were to come time for me to start a project on my own I'd become completely blank trying to think of how to do in in x_language like I wouldnt know if I had all the information I already needed or needed to move to some advanced form of learning whatever it was it had to offer like 400 pages on libraries to use or something. To tell you the truth it becomes daunting.

  No.21480

>>21474

You're putting the horse behind the cart here.

No matter what else you learn in computer science, you need to learn to program. You can read theory all day long and it won't help you if you can't put it into practice.

Get a book for whatever language interests you and run with it. Find one that matches your learning style. If it has exercises, do them (that's where you'll learn the most). Work on simple projects, and then try modifying more complex ones.

Once you understand the basics of programming, then start studying the theory. It won't really make sense otherwise, and you'll miss a lot of the nuances.

  No.21487

>>21480
>horse behind the cart

Was this deliberate, or...?

  No.21494

>>21487
"to put the cart before the horse" is an idiom, meaning to do things in the wrong order. While unusual, "horse behind the cart" is just another way of saying the same thing.

  No.21504

Is there really no reasonable way to make menu interfaces and keyboard-event driven stuff for the command line in Java? I'm still learning the basics, and learning how to make GUIs seems like putting the icing on a cake that isn't done yet.


  No.21510

Is there a list of medium-sized programming projects (i.e., bigger than solving some specific problem like Project Euler, but not so big that it would require a whole team; maybe think IRC clients, FTP clients and such) that has rough estimates of difficulty for each?

  No.21513

>>21510
but a simple IRC client is not that big, neither would be a simple FTP client. I think that the /g challenge list is a good one, while some of the problems may be a bit too big, most of them seem reasonable.

  No.21514

>>21513
>but a simple IRC client is not that big

That's precisely what I'm looking for. I want to move up from making tiny programs for solving tiny problems, to making bigger and more "realistic" programs that could theoretically be useful, while not being so big that I would be out of my depth.

That challenge looks more or less like the kind of thing I wanted. The only thing it doesn't have is the difficulty estimates.

  No.21527

>>21487

It's pretty much like >>21494 says. I had a brain fart when I was typing that out and forgot the actual phrase.

  No.21528

>>21504

The problem is that there's no universal API for what you can do at a console (or even what a console is). Windows/DOS has its own API for it, and on UNIX terminals can have all kinds of different features.

While it seems logical they'd make something like AWT for terminals, early Java was focused on browser applets, backend web/business logic services, and GUI applications. Fullscreen DOS apps were going away, thanks to Windows, and they never were horribly common on UNIX anyway. They're more of a mainframe thing, and anyone programming on that level could just use JNI.

  No.21539

>>21435

Haskell book is probably the best intro book for the language by far. You can buy it here http://haskellbook.com/

The book is meant for absolute beginners of programming, so it tends to drag a bit before the monoid chapter. (I skipped a bit at this stage). It gives really good explanations for what apppicatives, functors, and monads are.

  No.21542

How do I learn x86 assembly?

Also, is there any (practical) difference between x86 and 80x86 assembly?

  No.21544

File: 1485066423546.png (548.84 KB, 200x113, 1483091413051.png)

>>21510
How's this? This has difficulty estimates too.

  No.21548

File: 1485092862813.png (377.56 KB, 200x183, 1437193628318.png)

>>21542
So, the main difference between x86/x64 assemblies is the default register size.

In 16-bit assembly (MS-DOS), main registers are 16 bits long (2 bytes) and are called AX, BX, CX, DX, SI, DI, BP, SP.
In 32-bit assembly, main registers are 32 bits long (4 bytes) and are called EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP. They contains the 16-bits registers (like Russian puppets, ie the 16 lower bits of EAX are AX).
In 64-bit assembly, main registers are 64 bits long (8 bytes) and are called RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP, R8, R9, R10, R11, R12, R13, R14, R15. They contain the 32-bits registers which contains the 16-bits registers.
There are other differences too. In 32-bits and 64-bits mode, the segment registers have usually the same value so you don't have to care about segments at all. And the ABI (application binary interface, ie "How do I printf???") differ according to the OS and the x-bits mode.

If you're using Windows, I'd recommend using MASM32 (http://www.masm32.com/). It has tons of libraries and there is a forum and tutorials and soykaf.

On GNU/Linux, there's this Lovecraftian nightmare called the AT&T syntax, which is used by all the GNU softwares (including GAS, the Gnu ASsembler, and gcc). I'd recommend using NASM instead. Also code in the mode of your computer (usually 64 bits). There's https://forum.nasm.us/ for help. Also get some reference (ie read "man syscall" and syscall.h) about the 0x80 interruption (it's the way to interact with the kernel, ie all the <unistd.h> functions). Note that you can use all the C functions (printf...) too. The ABI is described in https://people.freebsd.org/~obrien/amd64-elf-abi.pdf

Get the "Intel® 64 and IA-32 Architectures Software Developer’s Manual" (https://software.intel.com/en-us/articles/intel-sdm) as a reference manual (it's thousands of pages long though). The first seven chapters of the first volume are a must read though.

For the lulz, here is a simple program written in NASM for a 64-bits GNU/Linoox:
; to compile this code:
; nasm -f elf64 test.asm
; gcc -o test test.o

extern printf ; so I can use the C printf function
extern scanf ; idem for scanf

SECTION .data ; global data is here
str: db "Hello world! Enter a number: ", 0 ; 0 ends the string
str2: db "The number is: %d", 10, 0 ; 10 correspond to '\n'
strscan db "%d", 0

SECTION .bss ; global uninitialized data is here
foo: resq 1 ; res(erve) 1 q(uadword) (64 bits)

SECTION .text

global main ; main, just like in C
main:

; printf is a variadic function, so rax must be 0 if you don't have float arguments
; ABI summary: the arguments are passed in this order: rdi, rsi, rdx, rcx, r8 and r9 (except floats that are passed through xmm registers)
mov rdi, str ; "mov a, b" corresponds loosely to the C instruction "a = b;"
xor rax, rax ; set rax to 0
call printf

mov rsi, foo ; foo is a pointer
mov rdi, strscan
xor rax, rax
call scanf

mov rsi, [foo] ; [foo] is the value pointed by foo (ie *foo)
mov rdi, str2
mov rax, 0
call printf

mov rax, 0 ; error code 0, no error
ret ; NEVER forget to end your program

  No.21556

>>21548
wasn't there a way to get GAS to use intel syntax?

  No.21562

>>21544
That's even better than the one I found. Thanks!


  No.21599

>>21338
We /lam/feels/ now
>>21337
>>21336
>>21335
i can't focus on a single language, and i don't really have a direction to go it feels, i wanna get a compsci degree to go into devops, but my real passions are in FOSS and gamedev, i just don't know how to proceed or even teach myself before uni. i guess i'll just keep playing around with code until it clicks, rn im writing a roguelike in python and annotating code that i read on github

  No.21606

I figured out two ways of multiplying (natural numbers only, though) without *, would one of them be considered better than the other?
#include <stdio.h>

int main(void)
{
int a;
int b;
a=3;
b=6;
int p = 0;
for(int i=0;i<a;i++){
for(int z=0;z<b;z++){
p++;
}
}
printf("%d",p);
return 0;
}
vs
#include <stdio.h>

int main(void)
{

int a=3;
int b=6;
int p;
for(int i=0;i<b;i++){
p=p+a;
}
printf("%d",p);
return 0;
}
thank u lamb

  No.21607

>>21338

Actually, managing own emotional state while learning is an undervalued skill. Wasn't Feynman who said the prerequiste of challenging intellectual work is tranquility of mind?

  No.21608

>>21599

Hmm, if your writing code before Uni, experimentation should be your priority. Ignore those who say you should learn THE perfect tool/way before starting anything, and keep doing stuff with a short feedback loop. Your roguelike project (text based?) sound awesome as a first one, stick with it, but small digression (implementing some basic demoeffect, making a simple twitter reader?) are perfectly commendable.

And annotating code is good, but for this kind of activity, if there is something to remember, it is that code is meant to be dissected, not read. Vivisection is even better.

  No.21609

>>21542

My advice :

1. Reverse simple C code, use http://gcc.godbolt.org/ (don't forget to play with compiler option such as assembly)

2. Gdb can serve as a nice C repl, and stepping through assembly instruction is good for your soul. Don't forget to predict what will be the instruction result!

3. https://www.xorpd.net/pages/xchg_rax/snip_00.html I just did the first one but those look like nice ASM puzzle.

4. http://256bytes.untergrund.net/home.php 256 bytes demos, they contains lots of little trick but be warned those are VERY dense asm code. And I doubt it's practical value, but it's fun.

  No.21610

File: 1485303473283.png (65.33 KB, 134x200, 1398079376255.jpg)

>>21606
The second code is faster.
Indeed, in the the first code, the outer loop is executed "a" times, and the inner loop "b" times each time, ie the "p++;" instruction is executed "a*b" times.

In the second code, there is only one loop, which is executed "a" times, so "p=p+a;" (you could have written "p += a;") is executed "a" times only.

Also, the execution time of a single "p++;" is almost the same as the execution time of a single "p+=a;" (as it is basic arithmetic). Therefore the crucial part is how much you loop. As "a" and "b" are variables, we can imagine they could get bigger values, which would make the program slower in both cases, but much slower for the first code.

Look for a course about (time) complexity.

  No.21611

>>21610
I see, thank you.
Though im not sure I should look for a course about such a thing when I've studied C for two days and the most I can do is fizzbuzz and that, but I'll remember the idea for later.

  No.21653

how do I go from writing simple scripts, to full fledged oop programs?

  No.21657

>>21162

Python, Ruby, and Node have prevailed in this facet (besides PHP of course).

Python has a very strong WGSI implementation and frameworks that utilize this method to plug into web servers. Look out for frameworks like Flask, Bottle, Django.

>>21163 I'd like to add a caveat. CGI, although dead simple to get started with server side learning, is notoriously hard to get correct in regards to security. Even Nginx's fast-cgi implementation can go awry very quickly since most people misconfigure cgi/fastcgi set ups. This article addresses the issue nicely: https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/

Node has Express and has very good support and maturity. Although I loathe the way JS does async. But that's mostly a stylistic choice. I prefer coroutine and generator syntaxes for "concurrency" idioms.

Ruby, I know nothing about Ruby save for that is used with Rails and is often seen in webdev to some capacity.

I've found the python+flask+SQLAlchemy a very easy way to get into server side programming.

  No.21680

This isn't really a programming question, it's web, but I'm trying to add a simple /λ/ link to my home, but instead, it creates a /%CE%BB/ link. Wat do?

  No.21681

>>21680
Back in the day, web browsers (and servers) were rather stupid and could pretty much only deal with the printable ASCII characters. A standard was defined to escape everything else. This is why you'll often see "%20" in URLs instead of spaces. "%CE%BB" is the URL encoding of "λ".

  No.21685

>>21681

How do I make it unstupid so my link shows λ??

  No.21688

>>21685
try adding this to the head
<meta charset="utf-8">

  No.21721

File: 1485849507233.png (522.64 KB, 200x133, IBM_Blue_Gene_P_supercomputer.jpg)

Hey lains. I want to work in IT but I didn't graduate for this field beside a certificate which doesn't hold much value (let say it covered the basics of sysadmin and webdev). I'm currently following a course in math but still want to work ASAP.

I recently opened a Gitlab account to put code on it but currently I only have a folder of a few scripts I use and work on daily to automate stuffs, applying new programming concepts and get used to the Python standard libs. I intend to upload every projects I find suitable to public exposure. I also had the idea to open a blog (maybe a custom engine) to share processes I document regarding IT/technical stuffs.

Which leads me to the following question : Should I add the link to my git repo on the resume right away? I fear to seem even less employable if I link to a repo without not as much to show as a "real" programmer.

  No.21722

>>21721
if you want to work in IT then grind the relevant certs.

if you want to become a programmer then study up on programming interviews.

  No.21725

I had a question, so I'll start with some general background. I've been using Python a lot for programming in the past year and a half and I'm looking to try a new language. I'm graduating from school soon and I'm looking to work in database and cloud development as I have some connections to get employed (pretty solid pay as well where I live.)

Anyway, the first programming language I used was Java, I believe Java 5 which I did in school (before college) when I was young. At the time, I barely understood any of it, but was able to make a calculator in it which I found exciting at the time.

Recently I began reading this Java book:
http://horstmann.com/javaimpatient/index.html

And so far I'm really impressed with Java 8 and I can definitely see how much different it is from Python. In particular, I like how programs are structured with classes and I can see how advantageous this would be in larger programs.

The job I'm looking at involves a lot of database work and systems programming. Would learning Java be worthwhile? I was also considering C++ as I read it's used a lot, but so is Java. I'm also very familiar with SQL, it's quite straight forward and is more of a database language to me, not as much programming.

tl;dr I know Python well, but want to dive into another, possibly more "difficult" language like Java or C++.

  No.21728

>>21725
Java is a good choice. If you are concerned with the job, you should ask around what they use there and look into those. I think for cloud Java is more popular while for DBMS C++ seems to be a better fit, but they could be using anything.

No matter what you choose, you can't really go wrong. If you only know Python nearly every language will teach you something new that will make you an overall better programmer.

  No.21731

>>21653
A simple script that does one thing (like backing up files or something) doesn't need unnecessary OOP. If you want to jump into OOP programming I'd suggest making small games. I learnt alot using SFML and C++ because it's easy to imagine things like players and NPCs as classes. Try it out sometime with your favorite programming language.

  No.21753

>>21653
OOP is a domain-specific solution, and it would be unwise to use it for everything, you end up working around OOP itself.
As [posterabove] said, games are ideal for this situation.
Anything where reasonably independent discrete units share are managed is in the domain of OOP

  No.21757

File: 1485997555419.png (1.75 MB, 200x113, 1476150430136.jpg)

>>21688

Thank you lain, this worked! Ily.

  No.21759

>>21731
>>21753
If you really want to bake your noodle, fiddle around with Smalltalk and then learn about the Actor Model. Smalltalk's OOP (the 'original' OOP) is fundamentally different from the OOP of C++, Java, or whatever else.
That being said, once your are enlightened by Smalltalk's design the OOP that you would write in C++ and Java will be better because you will have a better concept on how to structure your program.

I consider learning Smalltalk to be a miniature offshoot of The Structure and Interpretation of Computer Programs.

  No.21760

File: 1486016745252.png (12.01 KB, 200x200, apustaja.jpg)

When other people say they "know" three or four languages, is it more likely they're really able to make useful programs in each language, or that they can make useful programs in one or two and for the others "know" just means "able to write fizzbuzz and hello world"?
Like people who say they "know a little bit of [language]" when they can say "hello how are yuo were are the toilet ples"
I both wonder how inadequate I should feel and how I should think about studying a language after my first one.

  No.21764

Best books to learn C++ when you're really lacking a basic understanding? I tried to take lessons online, but, for example, I don't understand what "standard stream objects that input and output data" means, or things like that. Is there a book I can read that teaches me very basic concepts of programming before I get into C++?

  No.21770

I know is both a contentious and subjective topic, but if I had to learn one of the two major text editors without any prior experience (ie Emacs or Vim), which one would you suggest?

  No.21777

>>21760
>When other people say they "know" three or four languages, is it more likely they're really able to make useful programs in each language, or that they can make useful programs in one or two and for the others "know" just means "able to write fizzbuzz and hello world"?
I can't speak about averages, but I know several languages very well. Each language has its particular way of solving an issue and all of these seep into the others when solving any problem.
Many languages are very similar, so it's reasonable that a person could say they know Java and C#, as an example. All of the languages I know are very different, however.

>I both wonder how inadequate I should feel and how I should think about studying a language after my first one.

Don't feel inadequate; that won't help at all. Which languages do you currently know?

>>21770
>I know is both a contentious and subjective topic, but if I had to learn one of the two major text editors without any prior experience (ie Emacs or Vim), which one would you suggest?
I like Lisp, so I use Emacs. I used a few different editors without touching Emacs or Vim but eventually found myself gravitating towards Emacs, because I don't use Qwerty.

It's fair to say that Emacs has more features out of the box and has a better language than Vim. At this point, I do most of my work in Emacs and it's really nice. I recommend it.

  No.21781

>>21777
I was mostly joking about the adequacy thing, its just a way of saying 'gauging how much I know relative to the norm'
I dont know any, im studying C at the moment.

  No.21782

>>21781
>I was mostly joking about the adequacy thing, its just a way of saying 'gauging how much I know relative to the norm'
Being intimately familiar with at least five languages is what I would set the low bar of high things at. Try to strive for that. Also remember that you probably shouldn't learn a language just to learn it; you should have an idea of what you want to use it for; it would be hard to truly learn the language, otherwise.
>I dont know any, im studying C at the moment.
Do keep in mind that C is a terrible language for beginners. The language specifies hundreds of cases of undefined behavior that the main compilers will ruthlessly and transparently exploit for optimization. Also keep in mind that even experienced C programmers tend to make the same class of error as beginners, which should be telling.

I would recommend you learn an assembler language, if the lower levels were what you were targeting, but you probably have an Intel machine and so that would be awful to try to learn. Take a look at a language called Forth, if you're inclined.

  No.21785

>>21760
I think knowing a little bit of a language means that they've used it before but would need to consult the reference manual a lot during work and might end up writing things that could be expressed much better using the language.

In my opinion every programmer should learn at least one language in each main paradigm.

  No.21811

>>21782
I'm not finding C especially intimidating so far, but I havnt made anything even a little complicated.
My reasoning for using C is "I use UNIX", and also that the excercises in automate the boring stuff with python were of no interest to me and I'd honestly rather do wank like math problems and fizzbuzz than practical solutions to problems I dont have.
If you're very serious about C being soykaf for the inexperienced I'll consider switching to Forth or lisp or something while im still early in.
>your request looks automated
why?

  No.21812

>>21811
>I'm not finding C especially intimidating so far, but I havnt made anything even a little complicated.
That's not uncommon. There's a sharp drop in pleasantness when you start using C for more and more.

>My reasoning for using C is "I use UNIX", and also that the excercises in automate the boring stuff with python were of no interest to me and I'd honestly rather do wank like math problems and fizzbuzz than practical solutions to problems I dont have.

If you want to do math programs, I'd recommend using a language that implements a nice model for numbers, such as the numerical tower many Lisps support.

>If you're very serious about C being soykaf for the inexperienced I'll consider switching to Forth or lisp or something while im still early in.

I'm very serious. Consider that Forth implementations are very small and fast, but Forth programs also generally have this. Then consider that GCC and LLVM with Clang are behemoths. Why should a language apparently so suited to being efficient (It's not, really) need such gargantuan compilers for this?

I firmly believe this is due to a lack of metaprogramming. Forth and Lisp have excellent metaprogramming. Forth doesn't inline procedure results, as an example, but the programmer can force this where it's wanted.

I recommend you start with ANSI Forth. By the time you start doing things ANSI Forth isn't good for, you'll be ready to move on to a leaner Forth.

  No.21813

>>21811
Don't listen to the elitists, C is fine.

  No.21814

>>21813
this, people in this board like to soykaf on languages they don't like (actually... they do everywhere).

  No.21815

>>21813
>>21814
I feel that I've given reasonable credence to why I believe what I do. Meanwhile, neither of you are saying anything with any substance.

  No.21829

>>21812
>>21815
The other reason for C I didnt mention is that I'd like to contribute to projects when I have the skill to do so, which I wonder if I could do with Lisp or forth.
If that wasnt a consideration I'd have gone straight into SICP from the beginning.

  No.21832

>>21829
>The other reason for C I didnt mention is that I'd like to contribute to projects when I have the skill to do so, which I wonder if I could do with Lisp or forth.
I won't lead you astray. From what I know, there's more public projects written in C than either of Lisp or Forth.

That doesn't mean that there's nothing to contribute to, though; StumpWM, Maxima, and many implementations of languages are written in Common Lisp. Forth is used heavily in resource-constrained and bare environments.

So, the places Lisp and Forth are used are generally lower level or higher level than C can reasonably be used at. That's something to keep in mind. If you're really concerned with having a large ecosystem to contribute to, you may as well learn something like PHP or Ruby, my point being that ecosystem size isn't necessarily a good metric to optimize for.

  No.21836

File: 1486219052329.png (112.41 KB, 200x113, 696a98f98afec55fcb6714af98ebff70c6536906109b72829d8c00546b3fd917.jpg)

>>21815
You do this every single time someone talks about a language that's not Lisp, Forth or maybe Haskell.

It doesn't matter which language you start with. In fact, just starting with the first language you come across is certainly better than spending months not learning anything because you keep changing languages since everyone tells you that their favourite pet language is the perfect language for learning programming and everything else is like kicking dead whales down the beach.

If someone wants to learn C, help them learn it, or just let them be, but there's really no reason to ram your pet languages down their throat. C is a perfectly fine language, it's not perfect, but no language is. Millions have learnt programming using it without any permanent damage to their programming ability. All this elitism does is discourages beginners. Maybe it makes you feel better about yourself, but otherwise it's not helping anybody and it's getting really boring.

  No.21838

File: 1486227210615.png (80.27 KB, 200x113, maxresdefault.jpg)

I learned how to program using AppleBASIC back in middle school on machines like pic related and migrated to QBasic once my school had Win95 machines (it was the 90's so yeah). Does this make me a bad programmer?

Anyone I have asked has told me that learning any BASIC dialect ruins you for life, even moreso than learning Java.

  No.21839

>>21838
Some legendary computer scientist did. And now just because he did, everybody parrots it around.
My answe would be no, and stop worrying

  No.21840

>>21839
Dijkstra had some rather extreme views on learning to program. He thought everyone should be taught how to formally specify and prove correct software before they're introduced to a real language.

  No.21841

>>21836
>You do this every single time someone talks about a language that's not Lisp, Forth or maybe Haskell.
Firstly, I don't like Haskell. Secondly, I make it very clear that this is my opinion, but I do go the extra length to explain myself. Thirdly, I appreciate languages asides from Lisp and Forth, such as machine codes and APL, but these are less appropriate in many circumstances. Fourthly, I'm not trying to be some annoyance that goes around spreading his opinion and bemoaning others; I'm trying to stimulate a discussion; simply because fewer people question someone being told to learn C as a first language doesn't mean I should or will.

>It doesn't matter which language you start with. In fact, just starting with the first language you come across is certainly better than spending months not learning anything because you keep changing languages since everyone tells you that their favourite pet language is the perfect language for learning programming and everything else is like kicking dead whales down the beach.

I've never once said that any of the languages I suggest are perfect; that would be naive. I do assert that it very much matters what language one begins with. Do you mean to say that a complete beginner to programming would be better off trying to learn, say, C++ rather than something several orders of magnitude less complex that also has, say, a grammar that can be understood deterministically and has excellent debugging tools?

If someone wants to learn how to program, they should really start with a good book that teaches algorithms and data structures and whatnot, first, and then move on to a language.

>If someone wants to learn C, help them learn it, or just let them be, but there's really no reason to ram your pet languages down their throat. C is a perfectly fine language, it's not perfect, but no language is. Millions have learnt programming using it without any permanent damage to their programming ability. All this elitism does is discourages beginners. Maybe it makes you feel better about yourself, but otherwise it's not helping anybody and it's getting really boring.

I can't in good conscience tell someone C is a perfectly good language to learn with, because, for the reasons I've given, I believe it very clearly isn't. I'm curious if you would tell someone that learning COBOL as a first language is a bad idea; millions learned with it without any permanent damage to their programming ability.

It's as if you don't want me sharing my experience, purely because it goes against a group thinking. It's obvious that some languages are better for beginner's than others and that's exactly what this thread is about.

  No.21842

>>21841
>If someone wants to learn how to program, they should really start with a good book that teaches algorithms and data structures and whatnot, first, and then move on to a language.

If you can reccomend such a book, while I'll probably keep with C for some time at least, I'll probably read it.

  No.21844

>>21841
>I do assert that it very much matters what language one begins with.

In my experience, it simply does not. My first language was Visual Basic 6. I don't still use it. I have learned other languages since then. I now primarily write Haskell, so it would be hard to argue that VB6 has somehow permanently shaped how I program. The same is true for everyone I know who programs: the choice of first language is important insofar as it determines the order in which concepts get introduced to you, and some languages are more complex than others and so harder for a beginner to pick up; but once you are learning your second or third language, what the first one was was almost totally irrelevant.

>Do you mean to say that a complete beginner to programming would be better off trying to learn, say, C++ rather than something several orders of magnitude less complex that also has, say, a grammar that can be understood deterministically and has excellent debugging tools?


Are you saying C++ does not have excellent debugging tools? There has been a lot of effort into high-quality tooling for C-like languages, it's simply delusional to say that there isn't anything.

People love to trot out the "parsing C++ is undecidable" line, it's true, but the proponents of this argument always miss one thing out: someone has to actually write such a program using the C++ template system for the parsing to become crazy. It doesn't just happen by itself! By that same line of reasoning, Common Lisp is a terrible language, because I could write arbitrary macros, making parsing not necessarily deterministic or decidable.

>It's obvious that some languages are better for beginner's than others and that's exactly what this thread is about.


Oh, some languages are definitely better for beginners than others, we are in agreement there.

I would say that languages which have large communities and vast amounts of available learning material, documentation, and existing projects to examine, are better. C and C++ fit those criteria much better than Forth does.

  No.21846

>>21841
> they should really start with a good book that teaches algorithms and data structures and whatnot, first, and then move on to a language.
Worst idea I've heard so far

>purely because it goes against a group thinking

here in this site it is actually going along with groupthinking trying to convert everybody else to lisp or forth

  No.21847

>>21841
Read this thread, we already had this discussion. This topic comes up all the time and never amounts to anything. This thread is to answer beginners' questions, and nobody asked what your opinion of C is. One of the early /λ/ stickies even advised against bringing up this topic and said to just pick python, what happened to that?

  No.21848

>>21841
forgot one
>I can't in good conscience tell someone C is a perfectly good language to learn with, because, for the reasons I've given
>Why should a language apparently so suited to being efficient (It's not, really) need such gargantuan compilers for this?
I don't think those are arguments. You're trying to push the idea of complexity, so you go for arguments that are not in the realm of a newcomer to programming in general.
C is not complex, it is actually very simple. And it is also (imo) more straightforward than juggling a stack, simply because it actually maps to what the computer is doing in a not too bad humanly readable manner (do this; do that; do something else) and the semantics are pretty clean.

>>21844
>I would say that languages which have large communities and vast amounts of available learning material, documentation, and existing projects to examine, are better. C and C++ fit those criteria much better than Forth does.
This very much, nice as Forth would be, there are simply no resources: two books and a standard are all you got, and a horrid texinfo document.

Just let people be, I've been into programming for a few years now and even for me it gets fuarrrking confusing all this soykaf with the language wars and elitism (my language is superiooor!), I can only imagine how much more confusing it would get for a beginner who is starting to learn what a loop is.
Beginners should just focus on getting acquainted with the field and actually being able to instruct the computer to do stuff, rather than wallow in theoretical (disguised as practical) rhetorics.
Finally, language wars are silly, languages are different, they serve different purposes, and in the world we live, they are all relevant. Bitterly charging agains other languages, especially when someone is just starting to get to know this messy sinking ship of a field, does nothing but kill the fun and the awe ("yay! I can make a computer do what I want!" turns into "EVERYTHING is like kicking dead whales down the beach BRING BACK THE LISP MACHEEN").

tl;dr don't discourage people's learning experience

  No.21849

"I hope the field of computer science never loses its sense of fun. Above all, I hope we don't become missionaries. Don't feel as if you're Bible salesmen. The world has too many of those already. " - Alan Perlis (I'm sure you've all read this quote)

Whatever language happens to fall in your lap first, you're fuarrrked, they all suck anyway.
If you really want to build good programmers, the language comes to be one of the least important things. Give them good solid foundations. if you really want to push your ideal language on others, pick a good lambda calculus book and have 'em read it, nobody will get into pointless (because they are pointless) arguments and the new guy will learn something really nice.

Sorry for all the posting I'll stop here.

  No.21868

>>21764

It's hard to learn the "basics of programming" without learning a language. An introductory C++ book will cover the basic concepts of programming.

For C++ specifically, I wouldn't recommend an online book. C++ was stagnant for a while and then had some major changes just in the last few years, and you're best off learning the "new" C++. Most online sources will be focused on older C++ style. It won't make much difference as a beginner, but as you advance and start dealing with memory management you'll want to use the newer features when possible.

I suggest either shelling out the cash for a C++ textbook published in the last couple of years or pirating one. Or picking a different language.

  No.21870

>>21842
>If you can reccomend such a book, while I'll probably keep with C for some time at least, I'll probably read it.
I don't want to recommend anything that will be too complex, so, diverging a bit, read this book; it's nice and rather language agnostic:
www.charlespetzold.com/code/

After familiarizing yourself with lower levels of computing machines, simply read of how data structures are implemented at this level. A good example is learning of pointers and then learning of linked lists, which are usually implemented as nodes of two pointers side-by-side in memory.

>>21844
>In my experience, it simply does not.
It matters in terms of speed of learning. Starting with certain languages will obviously speed this learning and others will slow it.

>Are you saying C++ does not have excellent debugging tools? There has been a lot of effort into high-quality tooling for C-like languages, it's simply delusional to say that there isn't anything.

I come from an interactive language background, so yes, I'm writing that.

>People love to trot out the "parsing C++ is undecidable" line, it's true, but the proponents of this argument always miss one thing out: someone has to actually write such a program using the C++ template system for the parsing to become crazy. It doesn't just happen by itself! By that same line of reasoning, Common Lisp is a terrible language, because I could write arbitrary macros, making parsing not necessarily deterministic or decidable.

You fundamentally misunderstand. For one thing, Common Lisp has a very simple syntax, which is all most tools help write. C++ has a very complicated syntax. Now, my point is that a Common Lisp programming tool is integrated into the same system that loads and evaluates Common Lisp code, which dissolves this reader macro issue; once it's evaluated, that's it. Meanwhile, a C++ programming tool will either need to parse the code itself, have a compiler vomit an intermediate representation, or poke the binary, which is orders of magnitude more complicated.

If I misunderstand something on the C++ side of this, please correct me.

>Oh, some languages are definitely better for beginners than others, we are in agreement there.

Alright.

>I would say that languages which have large communities and vast amounts of available learning material, documentation, and existing projects to examine, are better. C and C++ fit those criteria much better than Forth does.

That's certainly fair to say. I would make the argument that, since Forth is simpler, one would also need a smaller community.

I'm simply trying to help this person avoid the need to eventually read this and related material; I'm well aware of how complex C gets once one digs deep and at least want them to be fully aware of this:
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html

  No.21871

>>21846
>Worst idea I've heard so far
Would you explain why? Perhaps the reverse, learning a language and then going language-agnostic in learning, is better for others.

>here in this site it is actually going along with groupthinking trying to convert everybody else to lisp or forth

Those languages are certainly popular here, but I believe this is a reasonably diverse place in that respect.

>>21847
>Read this thread, we already had this discussion.
I'm aware. I'm often one of the participants.

>This topic comes up all the time and never amounts to anything. This thread is to answer beginners' questions, and nobody asked what your opinion of C is.

I'm trying to help a beginner, which is reasonably on-topic.

>One of the early /λ/ stickies even advised against bringing up this topic and said to just pick python, what happened to that?

The /λ/ moderator changed it a ways back.

>>21848
>I don't think those are arguments. You're trying to push the idea of complexity, so you go for arguments that are not in the realm of a newcomer to programming in general.
I don't understand what you mean.

>C is not complex, it is actually very simple. And it is also (imo) more straightforward than juggling a stack, simply because it actually maps to what the computer is doing in a not too bad humanly readable manner (do this; do that; do something else) and the semantics are pretty clean.

We simply disagree, then.

>>21844
>This very much, nice as Forth would be, there are simply no resources: two books and a standard are all you got, and a horrid texinfo document.
Well, there's plenty of material on stack machines and the greenarrays website has excellent documentation: http://www.greenarraychips.com/

>Just let people be, I've been into programming for a few years now and even for me it gets fuarrrking confusing all this soykaf with the language wars and elitism (my language is superiooor!), I can only imagine how much more confusing it would get for a beginner who is starting to learn what a loop is.

I'm only trying to help. I'm not trying to be some language elitist.

>tl;dr don't discourage people's learning experience

You've your opinions and I've mine.

  No.21925

I'm designing a P2P marketplace for learning purposes.
The thing is that the vendor has to use the same bitcoin address for every transaction. (all transactions are 2-of-3 escrow) Should this be a problem for vendors? Should vendors use a new Bitcoin address for every transaction? (this is impossible in the current model)

Thanks

  No.21927

Do you think Perl 5 will still be relevant in the years to come?
I like the language and want to learn it better for my own work but I fear it'll be a futile effort
100 year code lisp zealots abstain pls

  No.21931

>>21927
relevant in the way that say sed and awk are because of how deep-seated it is in the Linux/BSD ecosystem.

you really don't need to get deep with perl 5 to do a lot of stuff with it anyway.

  No.21936

>>21927
>Do you think Perl 5 will still be relevant in the years to come?
No. To my knowledge, there aren't many very large Perl programs. It's my understanding that most Perl programs are only a few hundred or thousand lines, at most.
Part of the reason languages like COBOL are still around is because they do their job reasonably perfectly and are rather too large to easily replace; it's also my understanding that Perl has neither of these qualities, on average.
>I like the language and want to learn it better for my own work but I fear it'll be a futile effort
If you want to learn a language, then do so without any regard for practicality. I try to learn languages that are very rather different from those I already know when doing this, however.
>100 year code lisp zealots abstain pls
I like Lisp, but that Paul Graham essay was just silly, although I don't remember all of it that well.

  No.21942

I'm not sure this is the best thread to ask, but is it a bad idea to use ccache for some dkms modules?
I will be compiling the same source for different kernels so that sounds convenient, but will it be able to deal with some major changes in the kernel?

  No.21948

File: 1486579274358.png (214.11 KB, 200x113, 1444518804271.gif)

Speaking of C again,
//take user input of a number and assign it to n
int n;
puts("番号をいれてください");
scanf("%d",&n);

//array of size n
int arr[n];
//print all its elements to test what they're set to
for(int i=0;i<n;i++){
printf("%d\n",arr[i]);}}
The output of this for an entry of 33 is
[/code]番号をいれてください
33
10
0
4196136
0
-1552923648
32555
0
0
0
0
-1555782352
32555
-1552902336
32555
-2077627276
32764
4196167
0
11960320
0
0
0
-1556250222
32555
0
0
-2077627280
32764
-2077627280
32764
-1550642928
32555
-2077627280
[/code]
WHY THO

  No.21949

>>21948
what im trying to do with this works when I set every index to 0 with a loop manually.
Is this because, like, memory is allocated for the array, but its not cleared up? So whatever information was sitting around in that memory before I designated it for the array is still there until its overwritten?

  No.21950

>>21949
Yes, that's exactly what's going on.

  No.21952

>>21925
bump
any help apprciated

  No.22045

I've only ever done small university type projects, have basic knowledge in many languages but no depth. I want to do a project on my own or contribute to open source, and learn more programming in the process. I'm interested in lainchan type topics like privacy. How do I get started? I'm a noob at C++ but would like to learn that more, or i'm already kind of good at python.

I almost made a new thread asking if people have suggestions of open source projects that arent too hard to contribute to

  No.22047

>>22045
>i'm already kind of good at python
https://github.com/rg3/youtube-dl/issues

  No.22073

>>21949
You're right. Just memset the memory to 0 and you'll be fine.
memset(arr, 0, n);

  No.22106

Hi all, simple question here. If I declare a variable in a for loop like so
for (int i=0; i < 10; i++);
when does i go out of scope? Would it be at the end of the loop?

  No.22111

>>22106
i is in scope for the entire loop body. In your case, there is an empty loop body: which starts at the ) and ends at the ;

  No.22113

>>22111
Awesome, so that is to say that i would be popped from the stack after the loop terminates?

  No.22129

>>22113
That wouldn't make sense, stack frames are made for function environments, the location refered to by i stays in the stack frame for the function until it is exited, but previous error-checking stages in the compiler keep it from being referred to anything outside of the for loop.

  No.22149

So I have a non-CS degree, learning programming through a vocational school, and now have about 2 years of industry experience. My main language is Java followed by JS, and I have a pretty decent grasp of Lisp and Scheme (self taught).

Two questions for those more experienced than me:
Does it make sense to jump straight into a CS major? Most places won't hire me because of having an unrelated bachelors, so I think I need to get back to school to get over that wall, but I'm worried my purely practical education might hold me back.

2: what's the best resource to self teach C? Most entrance exams I've found have a lot of C on them, so it seems a necessity to learn. And if not for school, it seems necessary to be well rounded anyway.

  No.22161

>>22149
quite surprised to read that you aren't being picked up on the strength of your experience alone. are you getting interviews at least? imo heading back for a CS degree is not worth the time or cash.

>Most entrance exams I've found have a lot of C on them

for one, i'm again surprised you are even sitting an entrance exam of any kind and secondly, that it is in C. where in the world are you that does this?

take a look at 21st Century C by Klemens first. if that looks incomprehensible then check out Modern C by Gustedt http://icube-icps.unistra.fr/index.php/File:ModernC.pdf

  No.22166

>>22161

I'm only starting to look elsewhere now. I like my job, the pay is good and the corporate culture is great, but it's just webdesign stuff, and I don't feel like I'm learning, or growing, or getting to work with some of the really interesting or fun aspects of programming, so I've mostly been staying out of convenience. I'm trying to look for something a little more romantic, but whenever I see something I like the degree stuff, or use of languages that still seem esoteric (Scala etc.) scare me off from even applying.

By a lot: I mean 2. It's basic concept stuff, and with an OO background I generally get the idea, but I'd rather have a better examples of some of the things C has that for example Java doesn't (null terminator's for example)

And thanks for the PDF!

  No.22179

File: 1487493650350.png (956.21 KB, 200x200, Kernighan & Ritchie - The C Programming Language.pdf)

>>22149
If I were you I'd jump straight to K&R, it's one of the most concise and overall best books I've ever read
Once you've got the basics down the next step depends entirely on what you want to learn

  No.22185

>>22179
>>22149
The code examples are awful by today's standards (well, obviously) but other than that it's a good book. No need to force yourself through it all page-by-page but also keep in mind that use little well rather than make a mess with lots.

  No.22186

File: 1487506420125.png (66.93 KB, 200x200, IMG_20170218_173238_processed.jpg)

I would like to help the lainzine out but I do not understand a thing about how git works. My only experience with git is navigating .exe files when i used to download free games from gitHub. Does anyone have some beginner videos and documents I can consume so I can edit and upload files into gitLain? It looks so simple and the last thing I want to do is ruin something on accident...

  No.22188

>>22186

For an initial starting point the following articles http://robertgreiner.com/2010/02/getting-started-with-git-and-tortoisegit-on-windows/, or http://www.dalsoft.co.uk/blog/index.php/2011/08/30/getting-started-with-git-on-windows/ which provide how to get started with Git and TortoiseGit(Windows GUI).

Just make sure to download the new versions of Git , https://git-for-windows.github.io/ and TortoiseGit https://tortoisegit.org/download/ instead of the versions in the guide.

The guide covers installation and creating a repository, adding code to the repository ,changing a file in the repository and committing as well as cloning the repository.

For a more complete beginners guide instead of just a blog article see https://backlogtool.com/git-guide/en/intro/intro1_1.html but ignore the backlog stuff.

For more details on how to use TortoiseGit see https://tortoisegit.org/docs/tortoisegit/tgit-dug.html which is the TortoiseGit daily usage guide.

Git is distributed which means that you won't ruin anything other than your working copy unless you push your commit to a remote server using git push or the Push option from the TortoiseGit dropdown menu and you can always clone a new working copy if you mess up your old one or check out a clean branch from the remote server.

  No.22212

File: 1487666502103.png (640.97 KB, 200x113, laincode1.png)

I was wondering which C library is lain's favorite for doing 2d drawing to the screen. I'm not actually a beginner so readable documentation / a support community are not as important.

Pic unrelated, some OC lain wallpaper for your trouble.

  No.22230

So, what should I study at college if I want to become a proficient C++ programmer?

Which career choice is the wisest (for my own goal)? if anyone has any experience, I'd like to hear it.

  No.22232

>>22212
SDL2 is nice and has bindings for C and nearly everything else out there (Python, etc).

  No.22238

>>21764

That's an odd goal.

Well, you could look for a college that uses C++ instead of Java or whatever as their base language. Then focus on data structures, algorithms, and operating systems*. Most of my classes weren't language specific, and I ended up turning in a bunch of stuff written in FORTRAN, Scheme, and Emacs Lisp - none of which were taught at my school.

Honestly, though, it doesn't matter what language you learn in. Most of what you learn in one language will transfer to other languages. You'll learn the most through personal projects anyway. Once you have one language down, pick up a modern C++ book and work through it.

* Operating systems courses aren't usually about /writing/ operating systems, but about things like memory management, shared resources, IPC, and multithreading.

  No.22239

>>22230

Bah, linked >>22238 to the wrong post.

  No.22240

>>22212

For high level, SDL2 is nice.

For lower level, check into Cairo. You'll have to provide your own windows and event handling, but it can do a lot that SDL can't.

  No.22252

Do we have any golang experts here? I would like to make a (linux) program that has multiple named pipes, and processes data when it comes in through that pipe, and another thread which writes things to other pipes

  No.22258

Can anyone link me to an in-depth explanation of malloc(), in C?

  No.22265

>>22258
The specific implementation of malloc() depends on the system it's running on. Look up how dynamic memory allocation works.

Chapter 9.9 in "Computer systems: A programmer's perspective" give a nice intro. You can easily find the PDF by googling.

  No.22266

>>22265
In depth was a bad choice of words, by 'in depth' I mean 'I'm a retard and this is confusing, so I want something that goes through how it works slowly and piece by piece"
I'll look that up, though

  No.22270


  No.22274


  No.22290

Am I an absolute madman to start coding in C or asm? My main interest is working with microcontrollers and things like that, so I don't think it's too out there. On the other hand, when I brought it up to my CS friends, you would've thought I was planning to do pushups with my dick or some soykaf.

Are they really that arcane?

  No.22291

>>22290
Neither of them is.
Higher level languages get a lot of hype. Overpopularized enterprise (Java) or webdev (javascript) languages get all the hype, as well as complexity bloated (C++) languages, so that the more modest roots of programming can be considered arcane and obscure by those who have been taught the way of the framework.
Nothing inherently wrong with starting with C or asm (despite the generalized lainchan mindset that C is like kicking dead whales down the beach, C is quite the elegant language).

  No.22292

>>22290
I think you're not a madman at all as someone else first really learning in C right now.
I tried python when I was a little younger,a nd maybe its just because I was newer to all this stuff then, but it felt like I was expected to just use a bunch of bullsoykaf and have it just werk without understanding how, which was completely confusing and paralyzing to me
studying C, now, everything seems simple, easy to grasp, and consistent. Even supposedly harder soykaf like pointers seems actually pretty simple and elegant.

  No.22300

>>22292
Ah yes, "I have to understand everything else first or else it'll scare the crap out of me" syndrome. I used to be like that. Nothing wrong with it, I can just empathize

  No.22303

>>22300
well, its worst for something like programming.

  No.22304

I'm going through the sicp, and in the first chapter, they told me that Fibonachi programm have exponentional grow in time, and linear grow in space. While I can figure out time's consuming, I dont get why space is linear. I mean you in order to compute fib(n), you gotta remember fib(n-1) + fib (n-2), and it expands as (fib (n-2) + fib(n-3))+ (fib (n-3)+fib(n-4)) and so on, you gotta remember 2x more addition every reduction steps, and it grows as 2^n, which is exponent.
(sorry for my english)

  No.22315

>>22304

If you were storing the state of the entire computation, then yes. But you're not.

You're only storing the parts of the tree above your current location. Once you return from part of the tree, that part of the tree is replaced with the return value.

  No.22335

Hey! I've got a question concerning AI dev. Given the fact that i'm learning to program, that I'm good at math and that I plan to pursue my education with math/physics, will both math and programming be the only requirements to understand AI ?

  No.22359

The most comfortable mono font?

  No.22364

>>22359
PragmataPro - it is on laintracker

  No.22368

>>22359
I use Terminus. It's a bitmap font, which means that at the right resolutions it's extremely crisp.

  No.22408

>>22359

I use DejaVu Sans Mono, but try Iosevka, monaco, ubuntu mono or stay with default settings.

  No.22445

Hello, lain.
I'm having quite a bit of trouble in the transition from raw HTML+CSS+JS into more robust systems like react + redux + webpack.
My problem is in setting up the environment, i can set up a basic react + webpack + redux environment, but whenever i have to extend my tools to include sass processing and/or ESLint, everything breaks down.

I've tried using pre-built boilerplates, however i'm not very much into using tools i don't understand, it's far easier to me to add a module at a time, and take the time to learn each one. Ramming them all together is quite counter productive.

Is there any resource you can point me to, lain? Remember, my problem isn't setting up basic webpack projects, it's the moment when i have to extend towards ESLint and/or Sass, or any other tooling probably, but these are the only 2 i'm going to use for now.

  No.22449

Is Structure and Interpretation of Computer Programs a good book for beginners?

  No.22450

File: 1489174067389.png (41.47 KB, 163x200, 9780262560993.jpg)

>>22449
Read this one first.
SICP can be hard because of how highly theoretical it is, but it is not beyond the understanding of someone with the resilience to go through it.

  No.22455

Oi lains! anyone can share nice themes for MOC? I want a nice configuration file or themes, the default ones are awfull. If you dont use MOC please share wich one are you currently using for listen to music on terminal.

  No.22472

Hello,

I'd like to ask what's the best "current" C (C89 or newer) book available?

I know, some of you guys might point me at K&R but pretty much everyone says it teaches bad practices.

On a side note, is there a FTP or something with a collection of sci/cs/tech books? because vola is dead af.

Have a good day.

  No.22477

I need some help with C inline functions.
  #include <stdio.h>
#include <stdlib.h>

inline int foo (int a, int b) {
return (a+b)/2;
}

inline int bar (int a, int b) {
return foo(a*10, a*10+b*2);
}

int main () {
printf("%d\n", bar(4,2));

return 0;
}
Here is the error I get when I try to compile:
  $ gcc -Wall --pedantic -std=c99 test.c
/tmp/ccidszuL.o: In function `main':
test.c:(.text+0xf): undefined reference to `bar'
collect2: error: ld returned 1 exit status

  No.22481

>>22477
Make the function declarations static
e.g.
static inline int foo (int a, int b) {
static inline int bar (int a, int b) {
fixes the problem here.
See
http://stackoverflow.com/questions/16245521/c99-inline-function-in-c-file/16245669 for further information as to why.

  No.22575

Hello, lain. Where can i research about my legal obligations as a developer? For example, Omegle bothers me and it would be pretty quick to make a copy of it that doesn't suck (no ads, no flash). But i wouldn't be willing to moderate at all, nor keep any data (since i can't pay for expensive servers anyway).

Should i worry about someone trying to sue me over someone else streaming illegal stuff, for example? How can i find out about that stuff?

  No.22583

How do i grok GUI programming, lain? I can understand frameworks like QT, but isn't there a principle behind all frameworks that i missed in my studies?

For example, how would you make something like Discord, that goes outside of common frameworks visual style? That applies to everything, really. How are game launchers made? They don't seem to use any specific frameworks, it's simple enough that you don't seem to need it. But i have zero clue on how i would even tackle a game launcher.

  No.22592

File: 1490124756815.png (72.48 KB, 148x200, 123456789 .png)

I know of Pascal's triangle, but that is something else. Explain please.

  No.22593

File: 1490129156619.png (42.4 KB, 200x99, Untitled.png)

>>22592
It's pascal's triangle, but they're only showing the last digit of each number in it.

  No.22594


  No.22596

File: 1490132822291.png (203.27 KB, 200x64, five writing systems.png)

>>22593
I see that, but is this representation known in math under some specific name?
>>22594
Something like that, but not in binary, but decimal. Could anyone of you build it in 3d calculated automatically, please?

  No.22597

>>22596
This picture is misleading.
Orthography is not language - All of these languages have far more vowels that are vastly different in how they are pronounced, regardless of how they are written.
Though it might be evidence that the tool of writing was only invented independently a couple of times and that the systems depicted here were never really fully isolated from each other.

  No.22599

>>22597
Image is not related and offtopic, but vowels are vowels (and the idea of consonant alphbts is a hoax)
Even when pronouncuation norms went astray and vowel is consonant and consonant is vowel (as in "new")
If this topic really bothers you, I'd make a thread in /sci/ or wherever you say.

  No.22610

File: 1490229787804.png (89.65 KB, 153x200, G4st0n.png)

Hello, anons.
I've been wanting to learn how to program for a long time and thing is that I just started my journey.
But unfortunately, i don't know where to keep going.
I've finished this course: https://class.stanford.edu/courses/Engineering/CS101/Summer2014/info

What do i do now? I was thinking about learning python or something else.
What would you suggest?

  No.22614

File: 1490263891177.png (455.45 KB, 154x200, o31PP92.jpg)

>>22610
That link doesn't show any info to me, so I'm not exactly sure what you've
learned already. That said, it depends on what you want to do, really.

If you just want to learn how to program and write some scripts/websoykaf,
Python is a good choice. It does a lot of stuff for you in the background
so you don't have to think about it (memory management etc.) and the
standard library is quite big so you can really focus on implementing
the 'what', not 'how'. Being interpreted you can also pause it mid-execution
and examine the state to debug things or just to look at what's really
going on. Supports OO as well, but I wouldn't touch that yet until you
are comfortable with imperative programming.

Another good option is C, being the Latin of CompSci. It is however not as
'convenient' as Python, because you need to do most of the stuff on your
own — which is in my opinion a good learning exercise. It forces you to
think on the computer level, dealing with bytes and memory addresses. It
is a quite small language (the ANSI standard is around 500 pages long, but
that includes the standard library and other stuff as well, the language
itself fits on 150 pages) so there's only the basic and necessary language
constructs you'll need to learn, most of which translate to other common
languages (sans pointers probably). If you're interested in the
'background' stuff as well, and/or want to do some systems programming,
embedded stuff etc. C is the better (almost necessary choice). In any
case, proper knowledge of C will probably be beneficial even if you won't
program in it later.

The crazy option here is starting with Scheme and something like
The Little Schemer which does not require much knowledge about how
computers work, however it is quite different from other common languages,
so the learned skills and knowledge won't translate as well as with C or
even Python.

I'm not going to recommend stuff I haven't read myself, so I can't give
you anything for Python except docs.python.org — I've only used the
library reference, not sure if the other sections are sufficient to learn
Python. Also, watch out for the v2/v3 incompatibility when searching for
stuff.

As for C, the K&R (The C Programming Language by Brian Kernighan and Dennis Ritchie)
is the bible you should definitely get a copy of, as it describes the
language quite well. Get the second edition as the first one concerns
pre-ANSI C, which is quite different in many ways. That one also covers
only the C89 standard, so find you a C89-C99 difference list, preferably
with explanations. It's either fairly simple stuff (bool type, inline
functions) or stuff you won't really need, especially at the beginning,
like variadic macros. For the standard library (and system calls),
manpages are your friend if you're on a *nix, if it's Windows you can
google them but God help you because working with C on Windows is quite a
pain.

For Scheme I recommend The Little Schemer, which is a fun little book.

The most important thing is to actually program stuff, start doing
something like Project Euler if you don't have any ideas of your own, but
do write code, lots and lots of it. Just reading books won't teach you
much.

Good luck lainon!

  No.22617

how would I go about getting an arbitrarily large number from stdin?
so that when you invoke the program, it prompts for a number, and then finishes getting it when you hit enter.
fgets requires something to write into and the idea of declaring an array of the maximum possible size I want the program to be able to handle triggers me.

  No.22618

File: 1490293374730.png (23.96 KB, 200x174, 1479922910975.png)

>>22614
Thanks, lainon. This really gave me somewhere to go. I will read that docs.python.org and see what i can learn from that.
About the book on pic related, i found a PDF and I intend to start reading it today.
Although, I've found another book. Do you know this book?

https://www.amazon.com/Programming-3rd-Edition-Stephen-Kochan/dp/0672326663/

>That link doesn't show any info to me, so I'm not exactly sure what you've

learned already.

That's because you would need an account to log in and see the contents of the course, but nevermind.
Basically I learned how to set an imagem in black and white using code, and some others simple things.

Sorry for my poor English, It's not my native language but I try to do my best.

  No.22619

>>22617
malloc a buffer of size x, read into it until it's full, malloc a 2x buffer, memcpy the conent, continue until you run out of input or RAM. Assuming a sensible size of the initial buffer, you should be able to read most inputs using the initial allocation and only loop in extreme cases, where you should hopefully not need to expand the buffer many times, since you always double its size.

>>22618
I've skimmed the book, seems alright and should be a nice complement to K&R.

  No.22620

>>22619
Thanks once again, lainon!

  No.22644

>>22619
I did it like this
  #include <stdio.h>
#include <stdlib.h>

void main(void){
int maxsize=10;//this needs to be an int variable, if you just give fgets a normal number it segfaults
char *arr;
fgets(arr, sizeof(char) * maxsize , stdin);
printf("%s\n", arr);
int result = atoi(arr);
printf("%d\n", result);
}
it works on up to 9 digit numbers. it starts giving wrong numbers back somewhere in the 10 digit range for some reason, if you make fgets buffer bigger.

  No.22645

>>22644
There's several problems with this:
1. You did not allocate any memory. You've created a char pointer which is uninitialized and therefore working with it is undefined behavior. That's why you're getting the weird numbers.

Either use
char arr[maxsize];
or
char *arr = malloc(maxsize);
(don't forget to free() it after you're done in this case)

2. atoi() is deprecated and does not do any error checking, use strtol().

3. You don't need to sizeof(char), it is guaranteed by the C standard to be always 1.

Also, you should probably check the return value of fgets() to see if you've actually read anything, just to be sure.

  No.22648

Hello ^^

I am new to C programming. When you use a function from <windows.h>, there is a signature that will appear in the compiled executable, right? If you use, let's say, three windows.h's functions, what will define the order of the signatures that will be displayed in the compiled file? Thanks for reading!

  No.22743

File: 1490929481259.png (143.8 KB, 200x106, bone-think.jpg)

Any good tutorials for programming with ncurses in C/C++?
I want to make a customizable text editor, but there are certain things I'm unsure how to implement using this library. For example:
Coloring text (for keywords "this", "new", "delete", etc...)
Automatic indentation for parentheses (would I need to look up how to parse languages for this feature?)

Probably the thing I'm most passionate for this project would be to take code and make it printer-friendly. Like, for inline comments, make them "footnotes" (such as those in MS Word), have line numbers when printing, and have something similar to wikipedia's citations for function definitions
ie
void testFn(int *a)
would contain a little citation that would tell the reader where the implementation for the function is.


I know it might be a bit of a stretch, but I really feel like this is a decently-sized project for my skill level, I just want to get comfortable with ncurses before I tackle this.
Thanks in advance!

  No.22744


  No.22776

I want to make a script that goes to vpngate.net, choses a random vpn and downloads it to the current directory. I'm planning in doing this with Python.
The first step is to chose one, follow the url and then in that page, download it.
I already tried a lot of web scraping methods, plus I've been working on this the whole weekend. Result: nothing. Anyone have any idea on what I can do?

  No.22777

>>22776
Not experienced with this so it might be the wrong way to go about it:

First download the html file of site,
Search the html for a keyword that appears close to your specified location. That'll hopefully locate the right spot in the html file. Then read the next bunch of lines to get some ip or url.

Perhaps look up "extracting lines from html" and "read specific line of html".

  No.22778

>>22777
Thanks for the response.
That's what I did. I downloaded the html, placed all a tags in a list and then chose one randomly. This lead to 2 errors. One, that also happens when not using the script, the url redirects to the main page. And two, the a tags won't appear.

  No.22782

I feel really stupid about IDEs. I'm reading through a book on C++, and I'm stuck with windows on my stationary PC, and I can't seem to find something that works. I installed Visual Studio Community the other day, and I couldn't get it to compile a simple Hello World, it complains about not finding 500+ libraries when I all included was iostream. Tried compiling from CMD with the included "Developers Terminal" with correct path variables and it still whined about not finding libraries I have not included. I know nothing's wrong with the code since it compiles just fine on my netbook with slackware. I googled the errors I was getting but none that had asked about it had gotten any answers.

So I guess what I'm asking is, should I just install linux in a VM or is there something that actually works on windows (7)? But if I can't even get an IDE working on windows, could I even dream of a career in C++?

  No.22787

>>22744

Thanks, that looks like it'll be very useful.

The ncurses Programming HOWTO is also pretty useful. I had good success with that for the (so far only) ncurses-based program I wrote. It's old, but it's not like ncurses changes much.

  No.22788

>>22782

I'm no expert on VS, but I remember when I used it I was confused by the way it uses precompiled headers.

If you're not already using it, try putting #include "stdafx" as the first preprocessor directive and see if that works for you.

  No.22810

>>22778
Ah, hope you can work out what's going wrong with it then.

  No.22811

Folks -
I ran pacman -Syu, and since I've restarted, my urxvt won't actually reflect either of the dotfiles I've used for it. They're the same files - I made backups and replaced them. I was using .Xdefaults, and created an identical .Xresources. Neither are working, even after runing xrdb - a query shows that it's reading them, but the look of the terminal isn't at all like the config file specifies.

Any suggestions?

  No.22812

>>22782
Your IDE/ Compiler needs to know where your libraries are. I've dealt with this issue, but I can't remember how to fix it off the top of my head. If you email me, I will help you get your environment working.

  No.22830

File: 1491541085481.png (50.74 KB, 128x128, 1491539780339.png)

I can't understand this paragraph in sicp. I mean I can write iterative procedures on C, right? And their growth of memory should be constant, right? Just like this small Python procedure:
  def add (a,b):
if b==0:
return a
else:
return add(a+1,b-1)

  No.22831

>>22830
Put simply, if you already know the term, many languages aren't designed with TCO (Tail Call Optimization), which optimizes the last call in a procedure to what can be thought of as a jump that doesn't consume any stack space, as the calling procedure isn't going to be returned to anyways. A consequence of this is that a procedure that calls itself as its last call effectively jumps to itself with new arguments, which is a loop.

Python doesn't have TCO and so your procedure will eventually consume all stack space if run with a sufficiently large argument, but if it did then that Python would be correct, yes.

  No.22834

>>22830
  >>> import traceback
>>> def add (a, b):
... print ("--- [ stack inside add {} {} ]---".format (a, b))
... traceback.print_stack ()
... return a if b == 0 else add (a + 1, b - 1)
...
>>> add (10, 4)
--- [ stack inside add 10 4 ]---
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in add
--- [ stack inside add 11 3 ]---
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in add
File "<stdin>", line 3, in add
--- [ stack inside add 12 2 ]---
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in add
File "<stdin>", line 4, in add
File "<stdin>", line 3, in add
--- [ stack inside add 13 1 ]---
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in add
File "<stdin>", line 4, in add
File "<stdin>", line 4, in add
File "<stdin>", line 3, in add
--- [ stack inside add 14 0 ]---
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in add
File "<stdin>", line 4, in add
File "<stdin>", line 4, in add
File "<stdin>", line 4, in add
File "<stdin>", line 3, in add
14
>>>

  No.22842

File: 1491615560853.png (27.81 KB, 200x200, 1320478140982.png)

I decided to learn C as my first language and it has been a struggle. I had to look up a book I liked but my biggest issue are the little things, fox example I made an if statement and in the same line wrote a ; making he statement useless and I struggled for a long while to make the program work. Other programs I make compile successfully but crash at start later the exercises grew too complicated for me and I'm not sure why, plus I also have to deal with stuff like windows closing the program when is done so I don't get to see the program running.
I'm unsure if the problem is me, C or the environment I'm working in.