lainchan / λ

The Beginner's General

λx.x · 2017-04-12 19:34
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.
John Titor · 2017-04-12 21:01
This isn't really a beginners question but I don't think it warrants its own thread. What's the best (read: least annoying) way to build Android apps right now? I'm looking to build a fairly simple CRUD app but after reading through a bit of the official documentation of the Java API, I don't really feel like touching that if I don't have to.
word · 2017-04-12 21:20
>>15 For CRUD, Android ha a fairly straiforward SQLite implementation. Same for reading and writing files. Of course it depends on what you want to do.
Sabo Engle · 2017-04-12 21:29
>>15 >What's the best (read: least annoying) way to build Android apps right now? Use an implementation of a language that supports Android development. Ideally, the Android-specific parts would be very small compared to the actual logic of the program.
Batou · 2017-04-13 05:56
>>15 here. Thanks for all the answers. I decided to just go with the standard Java Implementations because my app is mainly GUI anyways.
Cypher · 2017-04-13 07:09
I have no programming background, although I know how to admin a unix server. I want to learn it, especially some scripting language such as Lua. I've tried it. No success because I think the way people teach programming is wrong. I don't want to know the syntax as the first thing, I want to understand the basic structure of a program and know, in a macro way, what's going on. So, any of you can recommend any way I can learn some scripting language in a way that does not focus only on syntax? I have tried some, including "thehardway" stuff, and also the original Lua tutorials. No success. The "prototyping" way to learn seems good, like, doing a basic program, instead of learn the syntax. Much more sense to me. Just as a hint, before people start: I don't consider myself dumb. I can learn most of the things easily, but programming hit me on the nerves for reasons that I don't agree with the teaching method generally used.
SHODAN · 2017-04-13 07:13
>>78 Unfortunately, it seems the languages that focus on syntax the least also aren't what most would call scripting languages. It doesn't stop me from scripting with Lisp, but it's questionable if you'd want to.
Debbie Charteris · 2017-04-13 09:17
>>78 what I did was setting a goal (in my case, an irc client) and just trying to create it, failing horribly, learning from my mistakes and restarting. it's what I recommend to most people, because reading how to program in a book or tutorial is not gonna stick. you gotta get hands on experience. best of luck, lainon!
Anonymous · 2017-04-13 09:24
>>78 if you are comfortable with Unix then why not dig a little deeper with shell scripting? think of it like learning about your tools while your on the job. in the long run maybe even take a look at languages like sed, AWK, or perl 5?
Meddler · 2017-04-13 09:47
I am not really a beginner, but I did not want to create a thread for my nonfactual question. I have experience with Java and Haskell , I am also able to understand Python code well, but I don't really like writing or working with Python. I am also looking into Rust. I want to dive into a new fun language that is...for the lack of a better word...a bit more "common", I hope you understand what I mean. Go seems really interesting to me, but since it is tied to Google and some comments here about how it is a harmful language scared me away. I know that questions like this are hard/impossible to answer, but what do you think about Go? Do you think it's worth learning in my case?
Colmerauer · 2017-04-13 10:28
>>92 If you want to learn anything new, you won't get that from Go. Go is pretty much a subset of Java, feature wise. The only "new" thing that it has going is the concurrency stuff, but Haskell has already had that for a long time. (If you're interested in that, I'd recommend http://chimera.labs.oreilly.com/books/1230000000929 , which you can read for free on the O'Reilly website) Go really just doesn't have much going for it. Depending on where you live, there might be a few jobs offerings, but that's about it.
Anamika · 2017-04-13 10:29
Request advice on 8086 assembly. I have been using Linux in my daily life for more than 6 years. I began with Python and later mastered an intermediate skill of Unix C programming (e.g. have spotted and sent patches to fix off-by-one errors in some basic system tools). But I haven't touched any underlying deeper things beyond C, my assembly skill is limited to writing C wrapper functions for embedded system calls. I tried to learn assembly twice but it's too painful for me to get started, Is there a modern tutorial for starters like me? I really need to know assembly because of my infosec interests.
maps · 2017-04-13 12:45
looking for suggestions for programming exercises, outside of standard operating principle of working towards a project i have some projects i'd like to work towards, but in the meantime i'd like to supplement my formal education with some challenges to keep myself sharp, self-assess learning, and round-out my skill set ie, more like this: https://adriann.github.io/programming_problems.html (unfortunately, for reference, the language i am learning is java)
Moore · 2017-04-13 12:56
>>115 There's the 99 Prolog Problems, derivatives of which are available in various languages (so you should be able to port the spirit of the questions to Java. - Prolog: http://www.ic.unicamp.br/~meidanis/courses/mc336/2009s2/prolog/problemas/ - Lisp: http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html - Haskell: https://wiki.haskell.org/H-99:_Ninety-Nine_Haskell_Problems >>92 Having worked professionally with Go for a summer, I agree with >>95. You probably won't learn anything new, and much of the language is frustrating, but it's a good one to learn currently if you're looking for a job and don't mind writing something only slightly higher-level than C. I don't think it being tied to Google is really a problem. It's in their financial interest to make the language as widespread and popular as possible, as then they need to do less training for future hires.
maps · 2017-04-13 13:02
>>117 neato, these look totally outside of my ZPD at the moment, but seem like they're useful. will tackle them when they're within reach of my skillset.
The Plague · 2017-04-13 13:12
>>2 What text is being shown in https://lainchan.org/λ/res/1.html ? >>115 >programming exercises • https://www.reddit.com/r/dailyprogrammer/ • https://programmingpraxis.com/ • https://codegolf.stackexchange.com/ >>78 As a newbie programmer to another, what I started with has worked well for myself and many others: https://www.cs.cmu.edu/~dst/LispBook/book.pdf - The reason for this book is because I believe as a beginner, one needs structure and lots of problems. See http://lisp-lang.org/learn/getting-started/ for setting up an appropriate Lisp environment.
sizeof · 2017-04-13 14:45
>>95 >>117 Thanks for your opninions. The fact that it's not far away from C is actually what makes it interesting to me. But then again, I might as well just learn C. However learning a comfy language I might find a job with is also a factor, as well as getting the option to contribute more to other projects, and the other way around.
Anonymous · 2017-04-13 16:16
>>2 Thanks for making the thread. I've been programming with things like Python and Perl for a while now and I'm starting to get good at basic syntax and program structure. I'm not sure where to start learning assembly and would love to get into some more high level stuff. Any suggestions?
Apoc · 2017-04-13 16:23
Could someone recommend an open-source project that has 1. Well-written, idiomatic C++ code that would be good for a beginner to learn from; something that you would consider a benchmark in code quality for C++ 2. Good design 3. Good documentation
Koos van der Merwe · 2017-04-13 16:29
>>129 There aren't many good resources on assembly language, but it depends on what you want to use it for. Do you just want to learn how things work under the good, be able to understand a disassembly or assembly listing, or actually want to write assembly language for something? For example, if you're interested in learning how machines work at the low level in general, or to do low-level tricks, then perhaps some other architecture (ie, not x86) would be best. Some 8-bit or 16-bit architecture, something like CHIP-8 or C64 assembly. On the other hand, for high-level languages: Haskell and Lisp are the most interesting high level languages.
Miho Iwakura · 2017-04-13 17:09
>>135 MIPS is always popular for learning assembly, there are also books that updated to ARM. "Computer Organization and Design" by Patterson/Hennessy comes to mind. I did not read it myself though. As >>135 pointed out, assembly learning resources are most often tied to computer hardware/architecture.
Armitage · 2017-04-13 22:06
Does anybody have a good top-down 2d car physics example?
Faye Valentine · 2017-04-14 05:53
I have so many questions (I'm a barebones beginner) >How can i start learning Lisp? >Any good book to start with C? >Should i learn Python? And why? >Why does many people loves java? >Does anyone knows about COBOL?
Turing · 2017-04-14 06:00
>>129 glad to see more assembly posts. I'm the first assembly poster, sorry for the insertion. I want to learn assembly to understand vulnerabilities and memory exploitation techniques, because I'm interested in attacks and compiler hardening around C code. >>135 I have the same thought, modern amd64 is a clusterf**k architecture that has been filled as many instructions as possible for practical reasons and clearly not good for a beginner (like me). MIPS sounds good and I have a box. But I don't know if it's easy to migrate the knowledge back to amd64 since most exploitation occurs on x86/amd64.
Ein · 2017-04-14 06:22
>>193 >How can i start learning Lisp? Lisp syntax is the easiest to learn of any language. But Lisp is the hardest language to master. Any Lisp book will easily teach the basic syntax >Any good book to start with C? "C Programming: A Modern Approach" by King >Should i learn Python? And why? you should know at least one general purpose scripting language, Python and Ruby are the most popular. I recommend staying away from Perl unless youre going to be a sysadmin. >Why does many people loves java? Java is the most basic language everyone understands, there is no weird or unusual syntax, everything works like you would expect. So its the perfect language for when you have thousands of programmers who all have to make software integrate together >Does anyone knows about COBOL? no one uses it for new software, you can make a lot of money maintaining legacy COBOL software
Ivan Horvat · 2017-04-14 15:39
>>194 >I want to learn assembly to understand vulnerabilities and memory exploitation techniques, because I'm interested in attacks and compiler hardening around C code. Then you want to read "Hacking, the art of exploitation". It covers that and gives a good paced introduction (plus practice) in reading assembly. On the topic of migrating your knowledge, if the case were that you wanted to learn to /write/ assembly (and do some cool bit tricks with it), then porting your knowledge would be the least of your problems. First learn2assembly, have fun (very important), and then migrating to a new architecture shouldn't be much of a problem.
John Titor · 2017-04-14 15:48
>>193 >How can i start learning Lisp? Common Lisp: A Gentle Introduction to Symbolic Computation (freely available through a web search) >Any good book to start with C? K&R. It's old, but the best introduction so far. >Should i learn Python? And why? Maybe. Python is a very dull language, and you don't really need to learn it. Also don't worry about should or shouldn't. Start with one language, learn to use it to solve problems, and don't worry about the rest of the world for now. >Why does many people loves java? Money >Does anyone knows about COBOL? If you want to land a safe job mantaining antediluvian code, it's okay, but it's very rare as well. For anything else, it belongs to a museum Again, learn one language, solve problems with it, don't worry about the world. Racket is a nice language to start, but Common Lisp is very much okay too. >>196 >Lisp syntax is the easiest to learn of any language >Java [...] there is no weird or unusual syntax Do you see the contradiction?
sizeof · 2017-04-14 16:02
HELP I'm doing an exercise from K&R, the book gave me a program that converted fahrenheit to celsius and the exercise is taking that program and making one that does the opposite, converting celsius to fahrenheit. So far my program compiles successfully but when i run it it sticks in a loop with the same numbers over and over again. #include <stdio.h> main() { float fahr, celsius; float lower, upper, step; lower = 0; upper = 300; step = 20; celsius = lower; while (celsius <= upper) { fahr = 32.0; celsius = 5.0/9.0; /* on the original program these variables were not written like this */ fahr * celsius; printf ("%6.0f %3.1f\n", celsius, fahr); celsius = celsius + step; } }
Iverson · 2017-04-14 16:07
>>228 >celsius = 5.0/9.0; Here's the problem. celsius is set to 5.0/9.0 at each step, so at the end (and before the test 'celsius <= upper') the value is 5.0/9.0 + upper, a constant (ie, always the same). also >fahr * celsius; This doesn't accomplish anything, it's wasted computation (the value isn't stored anywhere).
maps · 2017-04-14 16:23
>>228 i had some issues working through these same exercises. alongside the helpful advice from >>231 it's also useful to keep in mind that your calculation will want to involve both fields - storing the value in one field on one side of the equation, and modifying the value of one field with each step in the other. as a complete novice and non-mathematically inclined individual when i was working through these exercises, it took me a few tries. keep at it, you'll figure it out.
dup · 2017-04-14 17:03
What C/C++ IDE does Lainchan use?
Eldon Tyrell · 2017-04-14 17:47
>>235 I've never personally used one. I'd suggest just using the command line and makefiles.
Masami Eiri · 2017-04-14 20:14
>>231 >at the end (and before the test 'celsius <= upper') the value is 5.0/9.0 + upper Obviously you meant "+ step". Were it "+ upper" it would at least terminate.
byte · 2017-04-14 21:20
>>231 >>232 fuarrrk this, now I'm going to read pic related
⍕ · 2017-04-14 21:44
>>96 I have no personal experience, but a name user from ages past once said that disassembling small c programs is useful for learning assembly, and specifically for learning how real code translates into assembly
McCarthy · 2017-04-14 23:38
Is Sicp still the best book for a beginner ?
Von Neumann · 2017-04-15 00:15
>>264 Not at all. Don't let memes convince you of that, because it's an incredibly difficult book.
Lukasiewicz · 2017-04-15 00:41
>>266 could you suggest an alternative? also mentioning that sicp is a difficult book for a beginner is it worth coming back to it ?
Lady Jessica · 2017-04-15 01:28
>>267 Im not that guy, but if you want to learn Scheme the best, clearest and most direct book is "The Scheme Programming Language" which you can read for free online
Lady Jessica · 2017-04-15 01:51
>>267 I am going to disagree with the other two guys. Start with The Little Schemer, it's fun, and it introduces Scheme nicely. TSPL is a huge book for a small language. It is too verbose, and it's too expositive. People like calling SICP a meme, but it is actually a really good book and makes you thing, It's not at all easy, but you don't really need any prior knowledge to read it. It is not a Scheme book, it just happens to use Scheme. It is a book about computation, which explores it in a mathematical way. Note that by computation I don't meant programming, it's a heavily theoretical book.
McCarthy · 2017-04-15 01:59
>>274 Thank you, but i am aware of what you mentioned,the sicp book was recommended to me as an intro to cs but i am not too confident in my math skills,so i was looking for other books to ease up the learning curve
hash table · 2017-04-15 02:51
>>275 Just don't go learning calculus or something like that, it has almost no use (or perhaps none at all) in CS. I say this because I've seen people somehow think that calculus has anything to do. I really don't know what I'd tell you to look into, maybe just sharpen your logical thinking skills.
maps · 2017-04-15 04:13
>>258 i'm happy to share with you some pseudocode to help structure your thoughts around this hint: including your printf statement, you can do the entire calculation within the loop in three lines: equation print statement adjustment of iterated field you can actually do it in a single print statement, which is one of the following exercises iirc keep at it!
Cereal Killer · 2017-04-15 07:44
Lainons, I know this is a lowly request, but I'm stuck on an assignment and am not sure how to proceed. Here is the instructions. b.) Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method three times. Within the method, prompt a user for values for each field for a Lease, and return a Lease object to the main() method where it is assigned to one of main()'s Lease objects. Do not prompt the user for values for the fourth Lease object, but let it continue to hold the default Values. Then, in main(), pass one of the Lease objects to a showValues() method that displays the data. Then call the addPetFee() method using the passed Lease object and confirm that the fee explanation statement is displayed. Next, call the showValues() method for the Lease object again, and confirm that the pet fee has been added to the rent. Finall, call the showValues() method with each of the other three objects; confirm that two hold the values you supplied as input and on eholds the constructor default values. Save the application as TestLease.java Here is what I have come up with. import java.util.Scanner; public class TestLease { public static void main(String args[]){ Lease lease1 = new Lease(); Lease lease2 = new Lease(); Lease lease3 = new Lease(); Lease lease4 = new Lease(); lease1 = getData(lease1); lease2 = getData(lease2); lease3 = getData(lease3); } public static Lease getData(Lease l) { Scanner input = new Scanner(System.in); System.out.println("Please enter the tenants name: "); String name = input.nextLine(); l.setName(name); System.out.println("Please enter the apartment number: "); int num = input.nextInt(); l.setApt(num); System.out.println("Please enter in the rent amount: "); double rent = input.nextDouble(); l.setRent(rent); System.out.println("Please enter in the length of the lease agreement: "); int length = input.nextInt(); l.setLease(length); return l; } public static void showValues() { getData(l); } } cont.
Ivan Petrov · 2017-04-15 07:50
>>296 what i'm having an issue with is defining the showValues() method. I have tried every call to getData(), and every passed argument, as well as combinations thereof, that I can think of. I should point out that the current construction, with the unknown variable l passed to getData, is just a placeholder. I'm aware that a Lease object is required, but I can't figure out how to correctly pass it. I have a feeling the solution is fairly obvious, but I'm failing to see it at the moment, and am requesting that some kindly lainon could provide an example of how they'd structure that method, as well as an explanation. Now, I don't want the homework done for me, I'm just stuck on this part and would benefit from seeing a demonstration. I can figure out what knowledge I was lacking from there, and rectify that lack of understanding. Thanks in advance.
tofucat · 2017-04-15 08:44
>>298 > [...] declares four Lease objects You did not only declare them but you've also created aka defined them. You have to create new Lease objects in the getData() method and return the newly created objects so you can assign them to the declared variables; getData does not need any parameter. Your showValues on the other hand needs a parameter, you have to pass a Lease object to it to be able to access and print its attributes. I think it might help you to look at the first few chapters of the official java tutorial again, I have the impression that you have to consolidate your grasp of some basic principles as well as basic terminology (what's a reference aka pointer to an object? what's a declaration? etc.) I think you can learn this stuff, just sit down for a few hours to "relearn" Java and I'm confident you'll be able to do it.
Fred Nurk · 2017-04-15 10:20
Thank you for your excellent and helpful feedback. I'll admit that I skimmed this chapter - focusing on examples - due to time constraints, which made this assignment far more difficult than it needed to be. I will go back and review the chapter in detail. After reading and working on it, I managed to fulfill the requirements of the assignment: import java.util.Scanner; public class TestLease { public static void main(String args[]){ Lease lease1; Lease lease2; Lease lease3; Lease lease4 = new Lease(); lease1 = getData(); lease2 = getData(); lease3 = getData(); lease2.addPetFee(); showValues(lease1); showValues(lease2); showValues(lease3); showValues(lease4); } public static Lease getData() { Scanner input = new Scanner(System.in); System.out.println("Please enter the tenants name: "); String name = input.nextLine(); System.out.println("Please enter the apartment number: "); int num = input.nextInt(); System.out.println("Please enter in the rent amount: "); double rent = input.nextDouble(); System.out.println("Please enter in the length of the lease agreement: "); int length = input.nextInt(); return new Lease(name,num,rent,length); } public static void showValues(Lease l) { System.out.println(); System.out.println("Tenant name: " + l.getName()); System.out.println("Apartment number: " + l.getApt()); System.out.println("Monthly rent: " + l.getRent()); System.out.println("Length of lease: " + l.getLease()); } }
Spofer spoon · 2017-04-15 12:44
Does anybody knows about a good call spoofing service? (if its free, go ahead with it) I'd want to improve my social engineering skills (I KNOW, I KNOW, This is /lam/ but as we don't have /sec/ right now, im feeling forced to post it here)
Boole · 2017-04-16 13:50
Does anyone have good resources for learning to develop for the web? I'm thinking of a project along the lines of a small text-board or something. Most of what I come across is absolute beginner material that doesn't really explain anything. I can already programme and know the very basics of html/css/js, but I'm not really sure where to go from here.
shitfeinated · 2017-04-16 14:11
>>352 assuming you speak python: https://github.com/channelcat/sanic
Acid Burn · 2017-04-16 17:29
I'm working through Stroustrup's PPP2, and I've run into a snag in the exercises for chapter 9. I have this code here: int main() { Library l; Book b1 {"1-2-3-4","gubbinz","james bond",Date{ 1978,int_to_month(6),24},Genre::nonfiction}; l.add_book(b1); Patron p1 {"james", "12345678"}; p1.set_fees_owed(5.0); l.add_patron(p1); Patron p2 {"billybob", "87654321"}; p2.set_fees_owed(1.0); l.add_patron(p2); l.check_out(p1,b1); vector<string> users_in_debt; l.users_in_debt(users_in_debt); cout << users_in_debt.size() << '\n'; return 0; } If I make these changes Patron p1 {"james", "12345678"}; l.add_patron(p1); Patron p2 {"billybob", "87654321"}; l.add_patron(p2); p1.set_fees_owed(5.0); p2.set_fees_owed(1.0); I.e., If I move the calls to set_fees_owed() until after the calls to add_patron(), the change in fees doesn't get carried over to the representations of p1 and p2 inside the Library object l. As a result, the call to users_in_debt() returns an empty vector. I'm passing the patrons to add_patron() as references, and what I'm expecting that to do is to make any changes I make to p1 and p2 carry over to those internal references. Where am I going wrong here?
Trinity · 2017-04-16 21:29
>>365 >returns an empty vector Bad wording; it obviously doesn't return anything. Here are the files if it helps: Book.h http://ix.io/qSd Book.cpp http://ix.io/qSc Date.h http://ix.io/qSk Date.cpp http://ix.io/qSe Library.h http://ix.io/qSg Library.cpp http://ix.io/qSl Patron.h http://ix.io/qSi Patron.cpp http://ix.io/qSh
Crash Override · 2017-04-17 03:23
>>264 The reason why SICP is a meme, is partly because its authority, and of course, difficulty. The level of the book is not really high, but the point was MIT used to teach this in the fist semester for computer science courses, and it was quite difficult for newcomers without background to catch up...
Switch · 2017-04-17 04:48
I'm having some problems understanding TDD, Lain. I understand the principles behind the theory, not the implementation. The basic structure is that i write a test, watch it fail, then write the code so the test passes. But let's say i'm making a unit conversion program (kg to pound etc), if i write a test for "input 1kg, output xpounds", that test will certainly fail, but to make it work i would need to write a whole structure behind it. I would need to sanitize the input, convert the values and process the output. Should these be tested, too? And if they should, wouldn't that kill the whole workflow? Since the idea is test -> fail -> write -> test. In this scenario, i would test -> fail -> write -> fail -> write a bunch more tests and code so i can recursively make the first test work -> test. Using this example of a unit conversion, how would you go about it with TDD?
hash table · 2017-04-17 08:31
>>393 You have to write the simplest possible code to pass all the tests so far. So if your only test is 1 kg -> 2.205 pounds, your code should just constantly return with 2.205. Then you write the next test which will fail your code (for example, 2 kg is not 2.205 pounds), and repeat this cycle until you are satisfied with the tests and the code. You would only write the input sanitization once you have at least one test that actually needs the input to be sanitized, and should end up with separate test cases for all the errors possible in the input.
JARGON · 2017-04-17 08:40
>>400 What's to be gained from that approach, though? I understand the advantages of writing a test first, but writing a test that expects `1kg -> 2.205 pounds`, in which the code consists of `return "2.205 pounds` isn't just a waste of time? I gain no insight in the requirements of the project, nor am i covering a larger area of the system with tests.
Masami Eiri · 2017-04-17 09:39
>>120 It's Rechnender Raum or Calculating Space by Konrad Zuse. This is in the filename. >>235 Emacs is my environment, although I don't program in C or C++. Vim is also popular. >>401 I'm a different individual and I've never heard of this approach but already question its validity. For converting between units, have a base unit (typically metric is used) and define units in terms of others declaratively. Then, there'd be no need to test if it worked correctly in an automated fashion, as the system would simply be told that a pound is 0.45359237 kilograms and similarly that one pound is sixteen ounces and so on. Any flaw in your program would then indicate a flaw in the declarative machinery or the data your system is using. If all the system does to convert is multiply and whatnot, that would be hard to get wrong, generally. If this didn't help, just ask differently.
Lady 3Jane.. · 2017-04-17 13:26
>>403 But the point of the question isn't to create a unit conversion program, it's to understand TDD specifically.
Elliot Alderson · 2017-04-17 13:53
>>401 You end up with minimal code that's guaranteed to be fully covered by tests. Every part of your code can be justified by pointing to the test that makes it necessary. Or something like that, I'm not sure if anyone actually does it this rigorously.
Hopper · 2017-04-17 13:54
>>264 No SICP is really good but might be to hard to start with. There is How to design programs if you find SICP to hard. http://www.ccs.neu.edu/home/matthias/HtDP2e/ Anyway you can always look here https://teachyourselfcs.com/
Jane Doe · 2017-04-18 00:06
>>365 I "fixed" it, but I don't know how. If I modify p1 in main, that change doesn't get carried over to its representation in the vector inside the Library object. If I make a function that returns a reference to the representation inside that vector, and then make a change to that, that _does_ get carried over to p1 in main. I still don't understand how references work, but at least the program "works" now and I can move on.
Bob Arctor · 2017-04-18 11:53
>>452 http://stackoverflow.com/questions/7382090/c-vector-push-back#answer-7382107
Shogun · 2017-04-18 12:27
What is some really good computer science knowledge that is not natural to come across, Lain? For example, i knew a lot of the concepts in SICP before reading it, because most functional programming books/classes already teach them. So i dropped the book after the first chapter and reading the second (without doing the exercises). This happens often, most books try to be geared towards beginners (probably to sell for more people), and the same can be said for courses. I'm at a point in my career as a programmer where i don't know where to grow to. I don't feel like i'm good enough to do good things, but i also don't know what i could be doing better/learning.
Erik Johansson · 2017-04-18 23:46
>>470 You can always Go Deeper(tm).
Lain Iwakura · 2017-04-18 23:52
>>470 If you already know well the lambda calculus and denotational semantics, you could go into category theory and type theory. Proof theory also has some results that are interesting for the computer science. But those are all theoretical subjects. If what you want is some advanced /programming/ techniques, then perhaps just start doing lisp macros. Read On Lisp, or Let Over Lambda, and you could also take a look into Art of the Metaobject Protocol.
t · 2017-04-19 00:10
Anons, i've made a linked list in C and as a challenge for myself i've made several functions using loops and recursion. The problem is that i couldn't develop the remove function recursively, and i also couldn't find any legible code for this function on google. Can you guys help me? Not sure if it'll help, but here is the code for non-recursive removal: struct list* remov(struct list *head, int number){ struct list *previous = NULL, *current = head; while (current->number != number && current != NULL){ previous = current; current = current->next; } if (current != NULL){ if (current == head){ head = head->next; } else{ previous->next = current->next; } free(current); return head; } }
Liet Kynes · 2017-04-19 01:10
>>493 This is my attempt: http://0x0.st/xOG.c I'll comment it later
Hacker · 2017-04-19 01:12
>>494 sorry that last line shouldn't be return remov(...), it should be remov(...); return head; my bad
Zuse · 2017-04-19 01:35
>>493 Ok here's my attempt to comment out the remove implementation. https://p.memenet.org/fb1d5a I also just implemented the rest of the linked list so that I could run my tests.
Lukasiewicz · 2017-04-19 13:08
>>497 Thank you, anon! if i understand correctly your function is deleting a node based on its index inside the list, right? i didn't tried that heh But still, what its the void pointer inside the node?
Random · 2017-04-21 15:58
I'm still stuck on the same K&R exercise. I know fahrenheit is 17.22 celsius and celsius 33.8 fahrenheit but I don't know how to represent that on the operation. My program compiles correctly but sticks in a loop. #include <stdio.h> main() { float fahr, celsius; float lower, upper, step; lower = 0; upper = 300; step = 20; celsius = lower; while ( celsius <= upper) { fahr = (15.0/17.0) * (celsius-40.0); printf("%3.0f %6.1f\n", celsius, fahr); fahr = fahr +step; } } The fahr = (15.0/17.0) * (celsius-40.0) is the issue here and I have no idea how to properly write this operation.
Roy Batty · 2017-04-21 16:06
>>574 your loop is not iterating Celsius. The while is waiting for Celsius to be greater than upper but Celsius is remaining at 0.
Leto Atreides I · 2017-04-21 19:14
>>507 Just data associated with each element. If you just wanted to store a linked list of integers you can do without it. But later on in data structures, when you're doing binary search trees or skip lists or something, each node will have a key and a value on it, key is your "number", value is my "data" pointer. So then you could set the key to something like an employee ID number and the data pointer to a big employee record. Then when you need to look up an employee by their ID number in log(n) time, you can use a tree. When you find the node in the tree with the right ID number, just use that_node->data to get the whole employee struct with more stuff like their name, phone number, etc... that you don't want to store in each node. Plus you can then use the same tree code to hold other types of data without writing a new node struct
Moore · 2017-04-21 23:47
>>574 >sticks in a loop The reason is here >>575 and the final increment was already correct in >>228 so there was no need to change it. The constants involved in the conversion were also correct in >>228 so there was no need to make up bogus new ones. If you need the formula handed to you your search engine of choice will do that.
Koos van der Merwe · 2017-04-24 15:44
Why does this PAREN-DEPTH work? I can't see the underlying logic. (defun paren-depth (list) (if (atom list) 0 (max (+ 1 (paren-depth (car list))) (paren-depth (cdr list))))) I can take a simpler reduced form of this which just counts cons cells, COUNT-CONS. It's quite straightforward as something that isn't an atom is a cons cells (with our expect input), and so we add 1 until we get an atom for each recursive call. (defun count-cons (x) (if (atom x) 0 (+ 1 (count-cons (car x)) (count-cons (cdr x)))))
over · 2017-04-24 15:56
>>585 Okay I changed the line to : celsius = (5.0/2.0) * (fahr-32.0); the program compiles but when ran it only shows a pair of very long numbers. There is probably something I'm not taking into account.
over · 2017-04-24 16:52
>>706 go line by line through your program line by line and ask why that line is there and find the answer. why include stdio.h? what does float mean? how does it compare to int? what is a while loop and why do you use it? what is printf and where does it come from? what do you want your program to output? what is it outputting? why do you think the error is with the line that you think its on. you seem to be guessing on how to fix the program, stop doing that. once you understand the problem you can form a solution.
Incognito · 2017-04-24 23:17
I'd like a recommendation on a good book for PHP for a complete beginner. I know some C and Python, but I don't think it is relevant to this specific topic. Help me, please, lainanons.
Chan Siu Ming · 2017-04-25 00:29
>>704 >Why does this PAREN-DEPTH work? Ignore the fact that it's called paren-depth. That is a tree height counter. A leaf is chosen here to have height 0, so we are counting edges. It could just as well have been 1 and we would have been counting nodes. Having dealt with leaves we need to handle nodes with children. The height of a node is one plus the height of its tallest child. However, direct element iteration is not how we traverse a list in lisps, so we need to rephrase in terms of our list traversal tools. These tools give us the first element and the sublist starting at the second element. Due to hysterical raisins these are called car and cdr. In tree terms, instead of access to all our children, we have access to our first child and to a view of ourselves with the first child cut off. So instead of saying that the height of a node is one plus the height of its tallest child, we rephrase like this: the height of a node is the larger of one plus the height of its first child, and the height of the same node with the first child cut off. This phrasing then translates directly into code.
Lain Iwakura · 2017-04-25 18:39
>>711 Okay, I got the program working and doing what it was intended to do. The solution reminded me that before starting with programming a couple of years back I had read a book about formal logic and before starting programming I had this idea that I could plan my programs first as logic formulas. Should I try to recover that idea?
Armitage · 2017-04-26 00:42
>>739 You'd have to provide an example. There is also a programming language based on formal logic called Prolog, it may interest you.
Vasya Pupkin · 2017-04-26 21:05
>>747 I don't think I can write a logic formula for this specific program but I know I have to keep the logic I learned in mind from now on.
if · 2017-04-27 14:29
>>758 Well, actually, you could formally verify the solution to a problem. There's a thread about that and you can look something up in the pdf thread. I don't have any exact recommendations, I think the books on lambda calculus and type theory.
Liet Kynes · 2017-04-28 06:24
Ok, this is a ridiculously easy problem, but for some reason I've been struggling with it for considerably longer that I'd like to disclose. We are learning about loops in the Java course I'm in. I have an assignment wherein I'm supposed to create a class, then use a while loop in another class to fill in the data. At the end, I'm supposed to give the user the option to have all of the objects they constructed displayed, unto EOF. We haven't covered arrays yet, but I used one the previous week and though it was the most ideal way to create so many objects. If there's a simpler way of doing this that I'm overlooking, I'd be much obliged. Unfortunately, no matter what I try, I cannot seem to get past the NullPointer error. Here is, I'm sad to say, take 4 of writing this simple program. (I'm pretty embarrassed, to be honest.) It's not pretty; I was trying to get the logic functioning before making it spiffy. It's quite sloppy; I've definitely taken some convoluted approaches after the simple pseudocode and error corrections didn't pan out. Note the output for debugging. Apologies for lack of ugly indenting + spacing. What am I doing wrong here? I've tried to make sure that the loops are iterating correctly, and as far as I can tell, the objects are being created. If there's a better way to do this without arrays, I'd be much obliged. Thanks, lain. import java.util.Scanner; public class TaskCreator2{ public static void main(String[] args){ Scanner input = new Scanner(System.in); boolean loop = false; boolean done = false; double time, price; int ID, sel; int k = 0; int a = 0; int total = 0; String title; System.out.println("Welcome to the task creator!"); System.out.println("Would you like to create a task?\nPress 1 to create a task, or 0 to exit."); sel = input.nextInt(); switch(sel) { case 0: done = true; loop = true; break; case 1: done = false; total++; } while(done == false) { Task[] task = new Task[100]; for(int i = a; i < total; ++i) { System.out.println("Please enter in an id Number."); System.out.println("ID"); ID = input.nextInt(); System.out.println("String"); title = input.next(); System.out.println("time"); time = input.nextDouble(); System.out.println("Price"); price = input.nextDouble(); task[i] = new Task(ID, title, time, price); System.out.println("array: " + k); System.out.println("total: " + total); System.out.println("i: " + i); a++; System.out.println(a); System.out.println("Press 0 to end or 1 to make anotehr task."); } sel = input.nextInt(); if(sel == 0){ loop = true; done = false; } else { loop = false; done = false; total++; k++; System.out.println("Made it"); } if(loop == true){ //task[0].displayInfo(); //task[1].displayInfo(); //task[2].displayInfo(); for(int j = a - a; j < total; j++) { System.out.println("j: " +j); System.out.println("k: " + k); task[j].displayInfo(); System.out.println("J: " + j); System.out.println(done + " in loop"); System.out.println(loop + " in loop"); } done = true; System.out.println("EOF: " + done); } } } }
Leto Atreides I · 2017-04-28 06:48
>>782 Every time your loop runs it remakes the Task array. Try making the array outside of the loop.
John Doe · 2017-04-28 07:03
>>783 That was such a simple fix; now I feel even more embarrassed. Thank you for the fresh eyes and for taking the time to read over my code.
Pulse · 2017-04-30 22:49
What book (with exercises) should I read to learn for example how GCC or clang works ? Like what goes on when I add a -W* flag; what is optimisation; how are the libraries stored...
Unidentified · 2017-04-30 23:38
>>840 GCC or clang's documentation would be the place to go.