lainchan / λ

(untitled)

John Doe · 2017-09-05 22:33
Why do I suck so much at programming? I'm a noob and trying to learn a programming language for years now. But whenever it comes to application - especially recursion and loops - my brain just buffer overflows I try to hold all the code in my mind. I can't stop this, whenever I try to write the code I imagine it in my head executing and that's when my brain gets overloaded till the point that I get headaches. soykaf. Anyone got this figured out?
sav · 2017-09-05 23:06
Can you show us the simplest code snippet that you are having trouble with? Recursive functions are defined by a recursive case and a base case. For example the factorial function can be defined recursively: 0! = 1 Base Case n! = n * (n - 1)! Recursive Case 4! = 4 * 3! = 4 * 3 * 2! = 4 * 3 * 2 * 1! = 4 * 3 * 2 * 1 * 0! = 4 * 3 * 2 * 1 * 1
sav · 2017-09-05 23:09
In Python def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)
Yet Another Lainon · 2017-09-05 23:22
>>3243 For all loop recursive problems, try saying a fairly simple case in your head then -> pseudo code -> code. Jumping straight from idea to code is a great way to get confused
The Fin · 2017-09-05 23:36
>>3244 Well, recursion alone is easy. I struggle more with combining loops and recursion which is very often the case in programming it seems. The practical problem I'm struggling with atm is matrix multiplication. The mathematical formula is simple but getting it into code is such a struggle for me. The 2 dimensional nature of the matrix makes the recursive loops feel like 7 dimensions in my head >>3247 I do the pseudocode thing but I feel like there's still a great leap in going from pseudocode to an actual working loop recursion. Maybe my problem is that I have a visual mind and picturing abstract code is not possible.
swap · 2017-09-06 00:30
>>3248 >I struggle more with combining loops and recursion which is very often the case in programming it seems. What sort of programming do you do? In any businesses application when I see recursion it means something is seriously fuarrrked up.
sav · 2017-09-06 01:45
>>3248 What exactly are you trying to do? Are you using a language with no formal loop constructs? Lisp?
sav · 2017-09-06 01:54
Bunch of matrix multiplication code snippets can be found here https://rosettacode.org/wiki/Matrix_multiplication
The Phantom Phreak · 2017-09-06 06:08
>>3248 What are you trying to do with matrix multiplication? When I see people having trouble with programing, most of the time they are trying to do really abstract soykaf with no clear end goal. If you knew how your matrix product would be represented visually at the end of the algorithm, that would probably give you some real good insight into it. I program a lot ( sr. dev for a large data company ) , and haven't done matrix multiplication since uni.
Crazy Jake · 2017-09-06 08:12
>>3248 have you considered looking at the code of free Linear Algebra softwares? Considering that this was one of the first purposes for computers, you have roughly 60 years of code to learn from. Sometimes seeing the finished product can help you understand how and why it was created that way.
藤原純一 · 2017-09-06 10:05
>>3243 Ok friendo, I'm old, like almost 40 old, starting to get grey hairs and everything. I got my first programming job just before I turned 21, so i've been doing this half my life and I like to pretend that I know what i'm talking about... ...but here's the thing, after all this time I still feel like a complete fuarrrking retard. It just comes with the territory. If you want to go down this path you have to realise you're going to constantly come up against things that you don't know and that you'll need to figure out. The trick with programming in general is not to try and become a walking api who can rote recite all the attributes of everything. Just get your head around the basic concepts and go from there. Recursion is mostly a bullsoykaf exercise used to teach recursion. Only once in all the different projects i've worked on has recursion been a proper solution to anything. So take your time with that one. Loops are easy.... just remember your language's rules around scope, take it a bit at a time, and you'll have it sorted in no time. Think of parsing a repeated data structure or something as loops as for repetitive work. Find something that happens more than once and deal with it in a loop. Don't try and picture things in your head executing or whatever else, that's just bullsoykaf h4x0r nonsense. This stuff is hard for everyone. Truth is, it's difficult for everyone. Nobody sits down and bangs out tons of code, it takes consideration and patience to get something quality that covers all your use cases. Tips 1. Find a small project and solve it by writing a program. Not the other way around. 2. Start with python or c. Learn standard procedural programming before moving on to object oriented stuff. 3. Don't bother with functional languages, these just exist so people can feel smug and smart that they can write difficult things that others can't. 4. Try and enjoy yourself. If it feels like a chore then maybe it's not for you. Plenty of other things you might be good at too so don't feel like it's a shame to call time and move on. Good luck :)
Cowboy · 2017-09-07 13:27
>>3266 Thank you friend, I feel very stupid for struggling with loops but somehow got it now. I think my problem was not just connected to the loop but also with my lack of knowledge in the language - more specifically, I tried to write the math multiplication function without using arrays - what a soykaf move really, I'm not sure if this is even possible. Also I tried to write the code without looking at other people's code from the internet. Well, ultimately I gave in and saw that my code was very similar already, I just lacked the syntax for using arrays. This gave me a good confidence boost although it also feels a bit shameful to copy paste even small parts of codes from the net. Anyway, I'll post the code soon when I'm finished with the details
Special Agent Bob · 2017-09-07 13:28
>>3292 >write the matrix multiplication function fix
Hong, Guil Dong · 2017-09-07 17:20
>>3249 Proper Tail Recursion is a thing. Recursion has no impact worse than loops in languages which implement it.
Demeere · 2017-09-07 17:27
I'm finally done, here's the code. It's my first real code in life that is not just "hello world" or similar. Feels really good man. Make recommendations for improvement if you feel like looking at all the spaghetti. Anyway, it still was kinda tricky to wrap my mind around those loops because of the 2 dimensional nature of the matrices and that the multiplication itself isn't that straightforward itself. Additionally, I lacked the syntax knowledge for arrays in the beginning so I was confronted with several problems at once and simply got really overwhelmed. Also I should have posted this crap in the beginner thread, sorry, I kinda missed it #include <stdio.h> int main (void) { /*int variables*/ int aw, ah, bw, bh, a, b; /* ask for matrix sizes */ printf("input matrix A size (rows)x(columns):\n");/*rows aka height, columns aka width: aw - column value (width) of matrix A*/ scanf ("%dx%d", &ah, &aw); int matA[ah][aw];/*declare the matrix now that size is known*/ printf("input matrix B size (rows)x(columns):\n"); scanf ("%dx%d", &bh, &bw); int matB[bh][bw];/*declare the matrix now that size is known*/ /* check for mathematical correctness */ if (aw-bh) /* error if colums matixA do not equal rows matrixB */ printf("error: matrices not fit for operation \n"); else { /* set elements in matrices */ printf ("enter elements for matrix A: \n"); for (a=1;a<=ah;a++) { for (b=1;b<=aw;b++) { printf ("cell %d%d: \t", a, b); scanf ("%d", &matA[a][b]); } } printf ("enter elements for matrix B: \n"); for (a=1;a<=bh;a++) { for (b=1;b<=bw;b++) { printf ("cell %d%d: \t", a, b); scanf ("%d", &matB[a][b]); } } } /*multiplication process*/ int matR[ah][bw];/* Result matrix with ah=l bw=n, called instead of l,n because fix values*/ int l, n;/* for loop use*/ int cellrslt=0, celltemp=0;/* used for cell calculations */ for (l=1;l<=ah;l++) /* calculate cell 11 then cell 12... then switch to next row and calculate 21, 22 and so on */ { for (n=1;n<=bw;n++) { for (a=1;a<=aw;a++) { celltemp=celltemp+((matA[l][a])*(matB[a][n])); cellrslt=cellrslt+celltemp; celltemp=0; } (matR[l][n])=cellrslt;/* asign cell result to endresult matrix */ cellrslt=0;/* reset cell result for next cell calculation */ } } /* print the result*/ for (l=1;l<=ah;l++) { printf("\n"); /* next row */ for (n=1;n<=bw;n++) { printf("%d ", matR[l][n]); } } printf("\n"); return 0; }
Bob Arctor · 2017-09-07 17:46
>>3300 Most languages used in industry don't have tail call optimization though. Not even languages like Python.
Church · 2017-09-07 18:10
>>3243 99% of the people on these boards don't want to actually be serious devs, they just want to LARP cyberpunk with impractical garbage languages and impractical / pointless excerises.
Cypher · 2017-09-07 18:51
>>3304 You should understand that those languages and practices are incredibly important to academia. Some of the people here get paid to do that sort of stuff.
Tyrell Wellick · 2017-09-07 20:16
>>3266 >Recursion is mostly a bullsoykaf exercise used to teach recursion. Only once in all the different projects i've worked on has recursion been a proper solution to anything. So take your time with that one. Almost every parser is recursive. The bucket tools in paint programs are recursive. The adjacent tile clearing logic in minesweeper is recursive. Most algorithms that involve a stack data structure are more directly expressed recursively. >3. Don't bother with functional languages, these just exist so people can feel smug and smart that they can write difficult things that others can't. There are many companies using Haskell and ML. https://wiki.haskell.org/Haskell_in_industry http://ocaml.org/learn/companies.html There are real benefits to functional languages. They're easier to write unit tests for, can't have null pointer errors, and are easier to parallelize. They also tend to come with state of the art static type systems. Besides that, I agree with everything else you said.
Knuth · 2017-09-07 20:19
>>3304 I'm almost certain we have some programming language theory researchers on here. I know for a fact we have at least one prolific Common Lisp programmer. I program in Common Lisp and Scheme and have projects as well.
Lain Iwakura · 2017-09-07 22:49
>>3309 >I'm almost certain we have some programming language theory researchers on here Being a programing language theory researcher sounds like the biggest bull soykaf job title. A great language comes from usability and practical application, something that theory and research rarely have anything to do with. Get in there and do it. >>3307 >You should understand that those languages and practices are incredibly important to academia Academia is dead. It's full of nothing but gender studies and forced diversity quotas. The reality is the only test of programing skill / practicality is what can you do with it and why does that matter. >I know for a fact we have at least one prolific Common Lisp programmer I could argue i'm in the top 2-3 people in my specific specialty / niche. At the doctorate level or even if you've just spend 10+ years developing you are going to be one of the best in the world at your specialty. Everyone here jerking themselves off over matrix math is really depressing to see. Why not do something that could have serious application, like AI learning algorithms or new database concepts? Both of those areas need serious help right now. It is all so depressing.
Drifter · 2017-09-07 23:17
>>3313 >Why not do something that could have serious application, like AI learning algorithms They do. Like exactly they do. AI began in academia and then moved to industry when it became more practical. Like computers themselves and like everything academia does. Don't knock it just because you don't understand it.
Technician · 2017-09-08 01:59
>>3266 The poster was walking about matrix multiplication. The fastest currently known matrix multiplication algorithms that are exact and numerically stable, actually happen to be inherently recursive divide & conquer algorithms.
Switch · 2017-09-08 02:20
>>3313 I'm in grad school at a reasonably high-end American university right now. I haven't met a single gender studies major. I'm also unaware of any forced diversity quotas, though those would generally be unnecessary to begin with, considering that the only reason why the US produces research of remotely good quality is because of brain drain on a massive scale. Looking for the best generally means you're going to get a random mixture of Asians, Russians, Europeans, South Americans, etc etc, especially if you're looking for people that have proven themselves in international competitions like the IMO.
St. IGNUcius · 2017-09-08 09:40
>>3313 >A great language comes from usability and practical application No, a great language comes from both the thoughtful application of PLT research, and its usability and tooling. Would you call Go a great language just because it has great tooling? Would you call OCaml a great language after looking at its anemic ecosystem? >Everyone here jerking themselves off over matrix math is really depressing to see. Lots of the people posting in here are probably in their late teens to early 20s, judging by the writing style and the demographics of the other boards. On top of that, BBS posters tend to be depressive and unlikely to stick to anything big for too long. Aren't you expecting too much of this board?
Crash Override · 2017-09-08 09:47
>>3302 Python doesn't have TCO because Guido is a moron who'd rather pile on tiny hacks instead of going for a cleaner, generalized and obvious solution because of a general disregard for functional programming languages and concepts.
Lukasiewicz · 2017-09-08 11:39
>>3292 Never copy and paste, even if you are 1-1 copying make sure you rewrite it.
Faye Valentine · 2017-09-08 23:19
>>3315 > AI began in academia and then moved to industry when it became more practical. Like computers themselves and like everything academia does. Don't knock it just because you don't understand it. AI has stagnated and died in academia. Academia did nothing of value with it, and still doesn't to this day. AI is still a joke, the only group really exploring what AI can do is the OpenAI group, which isn't really open at all and is just Elon Musk jerking him self off to SkyNet fantasies. Databases are really the best example of why accademia is cancer. While there were some "abstract" papers on what relational databases were, nothing of value was done and a basic model wasn't even written until Oracle started selling contracts to companies who needed them. Accademia doesn't need relational databases because all of the data is meaningless, undefined, theoretical crap which has no relation to anything other than how hard Richard Stallman can jerk him self off. >>3320 >I'm in grad school at a reasonably high-end American university right now. I haven't met a single gender studies major. I'm also unaware of any forced diversity quotas A key rule in sales or any sort of social engineering is that if you can't see the target, you are the target. >Looking for the best generally means you're going to get a random mixture of Asians, Russians, Europeans, South Americans, etc etc, Literally you are preaching "muh diversity" here, you academics just can't help it. >especially if you're looking for people that have proven themselves in international competitions like the IMO. International competitions like the IMO ( with few exceptions ) are for people who suck at their craft so much they can't produce anything of value to the marketplace and have to engage in a jerk circle of useless software ideas to make themselves feel better.
Sipho Nkosi · 2017-09-08 23:49
>>3301 Not a CS myself but it's pretty nice. If you could use a bit better variable names, I think it would be just perfect. Keep up the good work, man.
FILLER · 2017-09-09 00:01
>>3330 >AI has stagnated and died in academia. We're living in an AI renaissance. >Databases are really the best example of why accademia is cancer. While there were some "abstract" papers on what relational databases were, nothing of value was done and a basic model wasn't even written until Oracle started selling contracts to companies who needed them. Where do you think the developers got the ideas for databases from? You just seem very angry at academia. If they were so worthless, why would they get so much private and public funding?
Debbie Charteris · 2017-09-09 00:46
>>3323 >No, a great language comes from both the thoughtful application of PLT research, and its usability and tooling. >Would you call Go a great language just because it has great tooling? Would you call OCaml a great language after looking at its anemic ecosystem? Go is cancer made by the corporate brain trust at google convincing themselves that creating a whole new language is better than learning how to thread in C++ ( or writing a decent threading library ) OCaml is a functional programming language created by researches and not often used in any practical sense. Objectively PHP is better than either one of these and PHP is in almost all respects a garbage programing language. However I would say PHP is still an actual programing language that was written for real applications and not just theoretical nonsense. >Aren't you expecting too much of this board? No I was / am a depressive, and I was a depressive on these boards in my late teens / early 20s , late 20s, early 30's, late 30s and now early 40s. I have to say if I were able to find a programing BBS that had a community centered around practical programing that helped push me in a more practical direction that let me see a real application come out of my programing quickly, it would of been much more motivating than having to slog though all the read me's, docs, books and just any material I could find until I finally could cobble together a real application. I am thinking about doing some live streams of taking applications from concept to application quickly. I think it would help empower a lot of the younger kids out there who feel like a fish out of water trying to do problem sets for CS classes.
byte · 2017-09-09 00:59
>>3333 >We're living in an AI renaissance. Please provide some examples, the only clear examples I can think of is these Universities that did nothing with AI i.e. MIT Artificial Intelligence Laboratory and Richard Stallman being a giant free-tard on government grants while not producing any valuable AI research. >Where do you think the developers got the ideas for databases from? From the universities that were sitting on the ideas doing nothing with them. Coming up with an idea is worthless, executing on it is everything. How much are all those video game ideas worth that your friends keep wanting you to program for them? >If they were so worthless, why would they get so much private and public funding? Universities are suffering from a lack of funding over all these days. Enrollment is down across the board an alumni don't donate these days. The bulk of private money comes in though companies hiring research teams to complete a specific task, this is mostly materials research / chemical engineering. >You just seem very angry at academia I resent having to jump though the hoops to get my degree, and having to pay a ludicrous amount of money for the "privilege" of doing so. 90% of what I do on a daily basis is stuff I had to pickup on the job after graduation and stuff I learned writing my own apps in my spare time. Most of all I resent the fact that academia kills the spirit of many other would-be developers by convincing them that abstract matrix math problems will determine if they are fit for the field.
sizeof · 2017-09-09 01:02
>>3334 I quite agree that having a community of people working towards the same goal is an invaluable motivational and learning tool. I learned C++ with a small (~6 people) group on irc a few years ago, it is a very fond memory and set me on my current path. I would very much like to find something similar. I really hope you start these livestreams, I will absolutely participate. Keep us updated.
fsociety · 2017-09-09 01:06
>>3335 >90% of what I do on a daily basis is stuff I had to pickup on the job after graduation and stuff I learned writing my own apps in my spare time. for (i=0; i < 100; i++) printf ("this");
Sipho Nkosi · 2017-09-09 02:41
>>3335 Linear algebra has more applications that programming, period. Matrix math is not "abstract".
Netrunner · 2017-09-09 03:36
>>3330 >Literally you are preaching "muh diversity" here, you academics just can't help it. Uh no, that's just naturally what you end up with when you practice true meritocracy based on entry test results and/or past achievements. You end up with a distribution of researchers roughly proportional to the populations of the countries that they come from, up to some factors like access to good higher education (ruling out large parts of Africa) and average IQ of specific ethnicities (leading to Jews being overrepresented, for example). Especially on the last point, "diversity" in practice generally does not conform to the common idea of political correctness. "Diversity" in the academic research world is the same kind of "diversity" as the one you'd see in the Forbes list of billionaires, not the kind of "diversity" you'd see at a democratic party meeting. The former is just a result of how the world works, not a result of artificial quotas.
Arisu Mizuki · 2017-09-09 03:36
>>3339 Thank you for the wild straw man fallacy. That's like saying numbers are useful for more than just programing. You sound butt hurt that anyone would question the necessity of matrix math in everyday programing.
stack · 2017-09-09 03:47
>>3341 Lots of programming problems I've dealt with used a lot of linear algebra to simplify the solution. There is a reason why engineers often learn Matlab and Fortran, they need good support for linear algebra because it is literally everything they do. Unless the only thing you are doing is skins on top of databases and adapters between BS java abstractfactory classes, linear algebra is quite useful even in pure programming, assuming that you are solving a practical problem. Machine learning is all linear algebra, error correcting codes use linalg, encryption uses some linalg, signal processing uses linalg, anything where you need nontrivial statistics uses linalg, computer graphics use linear algebra, and the list just goes on and on.
Nanashi No Gombe · 2017-09-09 04:38
>>3335 Dude you have problems. AI isn't dying in academia. It's a current research focus in nearly all CS department in the US. Breakthrough advancements won't happen immediately, it'll probably take 10 years to produce high functioning AI which will mostly be in the hands of militaries and in corporations until certain consumer companies learn to market it outside Alexa-like gadgets. DARPA is spending a lot of money on it currently, and DARPA has a good track record of success. And the military on these matters usually hires PhDs who had intense training in "abstract" ideas you hate so much, probably because you're incompetent at research level work. Abstract matrix problems are fundamental to 3D graphics and anything requiring >2 dimensional systems. It's extremely important in understanding intense optimization problems, VERY important in feedback machines, logistics, finance, and scientific research. The human race will make no progress with your kind of envy de-legitimizing the value of new design approaches in STEM outside of engineering. Thousands of brains at CERN had to analyze data of quanta so we could start conceiving of quantum computers with practical formulas and theories, which depend a soykaf ton on abstract math, I'm not contesting the idea a degree of theoretical computing and math isn't needed in some applications like web design. or simple app design. That's an organization task requiring sensible design taste.
dictionary · 2017-09-09 07:56
>>3343 >AI isn't dying in academia. It's a current research focus in nearly all CS department in the US Not the guy you responded to, but AI as the public understands it, is not currently being researched on any significant scale. The basics for this, knowledge systems, Agents... was done before the first winter of AI when lisp was all the rage. This is currently not done anymore. What is currently being researched is simply pattern matching/heuristics on steroids which is then marketed as "AI". Anything related to deep learning, machine learning, tensorflow, BigData, unsuperwised learning, ANN... falls into this category. >Thousands of brains at CERN had to analyze data of quanta so we could start conceiving of quantum computers with... Quantum computers are currently not being researched at CERN. Their focus lies in completely different fields even though they work at similar scales. (size-wise that is) I agree with everything else in your post, without academia most of the industry would be screwed. Its only today that the concepts developed in academia of the 1960s are finally entering comercial products, and even then, only in incomplete form. This is why most programming languages are resembling lisp more and more, this weird "academic" language of the 1960s that no one had any use for </hyperbole>
Undisclosed · 2017-09-09 10:24
>>3342 > Machine learning Machine learning is a "cloud" tier normal person meme
Dujour · 2017-09-09 17:14
>>3344 AI as the public understands it (in the overly anthropomorphized way) wasn't researched before the AI winter either. I don't see anything wrong with marketing deep learning as AI. Sure, its a very simple form of AI, but so is everything else at this point, and it is smart enough to do things like driving cars reliably.
Random · 2017-09-09 17:49
>>3334 >Go is cancer made by the corporate brain trust at google convincing themselves that creating a whole new language is better than learning how to thread in C++ ( or writing a decent threading library ) That's not what I was talking about. Yes, Go the language is fuarrrking cancer, but it's been hugely successful and people are employing it to build a lot of software. And you know what? I haven't seen anybody who's using it hating it as much as they hate Javascript or PHP. And that's not because of the language itself (which is by design not as retarded as JS or PHP, but worse in some aspects), but because of things like the huge standard library, the fast compilation times, gofmt, the high quality external libraries, and so on. Go is a practical choice, written for real applications, as much as I hate to admit it. PHP is an embarrassing hack of a language in comparison, the only thing it has going for it is the fast development cycle, and if you're saying that it's better out of pure anti-intellectualism, à la Rasmus Ledorf, you'll absolutely love Go. It ignores about 50 years of academic advancements that have already been integrated in every other language out there, even PHP. >OCaml is a functional programming language created by researches and not often used in any practical sense. That's bullsoykaf. Facebook depends on a lot of software written in OCaml, including a VM and a compiler/type checker to deal with the shortcomings of your favourite language, PHP. Jane Street uses OCaml for just about everything, Bloomberg for part of its trading infrastructure, and they're both trade firms that conduct millions of trades every day. If you really think that both of those languages were just built for theoretical nonsense instead of real applications (as opposed to fuarrrking PHP of all things) you're just as much of a LARPer as the posters you complain about. >if I were able to find a programing BBS that had a community centered around practical programing that helped push me in a more practical direction that let me see a real application come out of my programing quickly, it would of been much more motivating than having to slog though all the read me's, docs, books and just any material I could find until I finally could cobble together a real application. Sure, but /λ/ was definitely not made for, nor steered in any way towards that goal, or any goal at all for that matter. It's too big, there's no organized activities to speak of, nor platforms that could make those possible, and it's just not much in the spirit of an anonymous imageboard. Sorry, but you're definitely expecting too much. It takes a lot of work to do something like you mentioned, and like I've already mentioned, the canonic imageboard poster depression hardly helps with long term tasks such as something like this.
Splicer · 2017-09-09 19:23
>>3354 >I don't see anything wrong with marketing deep learning as AI. t. marketing department
Hiro Protagonist · 2017-09-09 19:33
>>3355 >Go the language is fuarrrking cancer, but it's been hugely successful and people are employing it to build a lot of software. Docker and... Docker... and ... yeah, no one uses it except meme lords and they'll move on to the next flavor of the month language as fast as they adopted Go lang. >Go is a practical choice, written for real applications, If you want to deal with a meme lord eco system that is in its infancy, which makes it impractical for anyone serious about anything but memeing > PHP is an embarrassing hack of a language in comparison, the only thing it has going for it is the fast development cycle, and if you're saying that it's better out of pure anti-intellectualism, à la Rasmus Ledorf, you'll absolutely love Go. It ignores about 50 years of academic advancements that have already been integrated in every other language out there, even PHP. PHP is usable unlike go / ocaml / haskell / smalltalk. With PHP, you can rip open the box and quickly make some usable apps. They may be unreadable, scattered, ugly and ultimately need to be torn down later, but they are there and do what they were made to do. If being against impractical languages that work on paper but not in practice is "anti-intellectual", then I am extremely anti-intellectual. >Jane Street uses OCaml for just about everything t. anecdotal evidence >Sorry, but you're definitely expecting too much. The bigotry of lowered expectations is strong with you>>3243
Spike Spiegel · 2017-09-09 20:08
>>3359 You're clearly not paying much attention to the new meme software (and don't try to claim you don't-- PHP is the epitome of meme software from the last decade) if you think nobody's using Go. Clearly there can't be that much production software written in it when the language is so young, and even then, how about Kubernetes? CockroachDB? Lots of people are investing in the language. I hate it, but I think it's a good investment. >With PHP, you can rip open the box and quickly make some usable apps. They may be unreadable, scattered, ugly and ultimately need to be torn down later, but they are there and do what they were made to do. Are you trolling? You go on and call Jane Street using OCaml "adecdotal evidence", but this is your opinion, supported by absolutely no evidence; if you don't even know what exactly you like about PHP you shouldn't be defending it so fiercely. And that's not even what I was arguing against. PHP is great for prototyping, but that doesn't make it a good language, let alone a good one, and a more forgiving compiler simply means that you'll have that much more errors in production. >The bigotry of lowered expectations is strong with you What does that even mean? I don't expect anything out of this board simply because nobody's doing anything about it, and it's much more likely for it to continue being this way than change. Thinking that it would be nice if it was this way rather than actually doing something about it is just wishful thinking.
Void · 2017-09-09 20:31
>>3361 >Clearly there can't be that much production software written in it when the language is so young PHP replaced Perl as sort of "the language of the internet", in about 3 years. Not having to deal with CGI soykaf was amazing when it first came out. Kubernetes and the other memes are mostly used by groups that are over funded and looking to learn new technologies on the client's dime. You probably know this already. > Jane Street using OCaml "anecdotal evidence" One company using OCaml is not indicative of a trend. Please show some trends desu senpai >PHP is great for prototyping, but that doesn't make it a good language, let alone a good one, and a more forgiving compiler simply means that you'll have that much more errors in production. Now we are getting into some meat, which brings us to the very subjective question, "what makes a great language?" I'm working with in the conext of the OP, which is some guy thinking he is like kicking dead whales down the beach at programing because he isnt good at matrix math. While I'd heavily encourage any CS majors to learn their matrix math, and just be good at all linear algebra... people shouldn't think they suck at programing because they are not "naturals" at some CS topics. I would like to see OP make some basic sloppy apps to show themselves that they CAN program and then gradually add complexity to their programs, grow into new languages ect... trying to do Matrix Math with ocaml out of the gate is a pathway to sadness imo. >What does that even mean? Good Sam Harris video on it https://www.youtube.com/watch?v=QMrkNhANPL8
THE OTBS EVANGELISM STRIKE FORCE · 2017-09-09 20:55
>>3301 Excuse me, have you accepted OTBS as your true lord and savior? Seriously though, please do some indentation and use a better brace style. The if aw-bh Why not bh-aw? hue hue without braces followed by a else bracket is bad style. The way the else wraps makes it still execute the multiplication. Proper brace the if and have it return after the error message and drop the else entirely. The parentheses it the celltemp assignment statement can all be dropped and those around the matR assignment as well. For those going to argue that this is all nit picking whiny bullsoykaf. Its like when learning an instrument. Wrong hand positioning picked up at the start will hurt you bad down the road. Not asking to make it perfect on the first try, but do practice it.
Wintermute · 2017-09-10 01:37
>>3363 >PHP replaced Perl as sort of "the language of the internet", in about 3 years. It didn't have as much competition as Go does now though, and it's not that hard to see why you'd want to use a language that has all the stuff you need to use in a web server built into it rather than a write-only language like Perl. Also, I only mentioned the open source production software, if you go by job postings mentioning Go I'd say the language is doing pretty well for how young it is. >Please show some trends desu senpai I never talked about trends, it's still a very niche language at the moment though I think it has lots of growth potential. >which brings us to the very subjective question, "what makes a great language?" I don't think there's any "great" language out there in absolute terms, "good" languages all excel in one area but fail in others, so you have to consider your circumstances. I personally consider a language great when it's well designed, has interesting means of abstraction and have a certain degree of usability, but that's only because I'm interested in PLT. I certainly don't think Racket or Haskell would be good choices in most contexts when working with other people. >people shouldn't think they suck at programing because they are not "naturals" at some CS topics. I thought this was a non-problem, honestly; there's no shortage of resources on how to write sloppy apps quickly around, if you choose to disregard all of this you should know you're just making it harder for yourself. Besides, it's normal to hit brick walls like this when you're just starting out, and you'll probably hit one no matter what you're learning first.
Marly Krushkhova · 2017-09-10 02:45
>>3334 >Go is cancer made by the corporate brain trust at google convincing themselves that creating a whole new language is better than learning how to thread in C++ ( or writing a decent threading library ) There is a certain person who does nothing but spend all their time on programming/tech related message boards and tries to shoot down any modern language that could possibly take market share from C++. So Id like to ask all of you what you have to gain for trying to argue with a Luddite who's only mission in life is for people to continue to use old obsolete technology like thread locking concurrecy when you could be learning and using the modern and correct way of message passing. People who argue with the C++ troll are similar to people who argue with 'free' software fanatics, you cant win an argument with an idiot, you will end up being dragged down to their level
Demeere · 2017-09-10 06:15
>>3374 I actually like Rust and Swift, you're argument is invalid.
Nameless · 2017-09-10 14:34
Re: matrix multiplication We've been having a discussion about various ways to do this for interesting purposes, some of which are AI-related, over in >>2594. Might be the same people in this thread, but just in case.
sav · 2017-09-11 20:26
>>3301 Nice work! great to see code. >for (l=1;l<=ah;l++) I believe arrays to begin at zero. So I would have expected to see: for (l=1;l<=ah;l++)
sav · 2017-09-11 20:27
I mean for (l=0;l<ah;l++) lol
sav · 2017-09-11 21:16
Here's my suggestions #include <stdio.h> int main (void) { int aw, ah, bw, bh, a, b; // ask for matrix sizes printf("input matrix A size (rows)x(columns):\n");/*rows aka height, columns aka width: aw - column value (width) of matrix A*/ scanf ("%dx%d", &ah, &aw); int matA[ah][aw];/*declare the matrix now that size is known*/ printf("input matrix B size (rows)x(columns):\n"); scanf ("%dx%d", &bh, &bw); int matB[bh][bw];/*declare the matrix now that size is known*/ // check for mathematical correctness if (aw!=bh) // error if colums matixA do not equal rows matrixB { printf("error: matrices not fit for operation \n"); } else { /* set elements in matrices */ printf ("enter elements for matrix A: \n"); for (a=0;a<ah;a++) { for (b=0;b<aw;b++) { printf ("cell %d%d: \t", a+1, b+1); scanf ("%d", &matA[a][b]); } } printf ("enter elements for matrix B: \n"); for (a=0;a<bh;a++) { for (b=0;b<bw;b++) { printf ("cell %d%d: \t", a+1, b+1); scanf ("%d", &matB[a][b]); } } //multiplication process int matR[ah][bw]; // result int l, n; int cellrslt=0, celltemp=0;/* used for cell calculations */ for (l=0;l<ah;l++) { for (n=0;n<bw;n++) { (matR[l][n])=0; for (a=0;a<aw;a++) { (matR[l][n])+=((matA[l][a])*(matB[a][n])); } } } //Print result for (l=0; l<ah; l++) { printf("\n"); // next row for (n=0;n<bw;n++) { printf("%d ", matR[l][n]); } }; printf("\n"); } return 0; }
sav · 2017-09-11 21:20
>>3420 Also note that this method does not use recursion as such.
sav · 2017-09-11 21:22
>>3420 I also forgot I don't need these anymore int cellrslt=0, celltemp=0;
hash table · 2017-09-11 23:16
>>3420 Say I wanted to use a function to initialize a matrix, how would I go about returning a 2d matrix in C? This thread actually inspired me to mess around with LA again, here are some basic functions but Im struggling to create a "initialize matrix" function. I probably need to learn more about pointers before attempting this though. [code] int trace(int dim, int mx[][dim]) { int trc = 0; for(int row = 0; row < dim; row++) for(int col = 0; col < dim; col++) if(row == col) trc += mx[row][col]; return trc; } void print_nxn_matrix(int dim, int mx[][dim]) { for(int row = 0; row < dim; row++) { for(int col = 0; col < dim; col++) { if(row != 0 && col % dim == 0) printf("\n"); printf("%d ", mx[row][col]); } } } void add_matrices(int dim, int mx1[][dim], int mx2[][dim]) { int sum_mx[dim][dim]; for(int row = 0; row < dim; row++) { for(int col = 0; col < dim; col++) { sum_mx[row][col] = mx1[row][col] + mx2[row][col]; } } print_nxn_matrix(dim, sum_mx); printf("\n"); } [\code]
Jens Hansen · 2017-09-11 23:19
>>3423 Ahh soykaf int trace(int dim, int mx[][dim]) { int trc = 0; for(int row = 0; row < dim; row++) for(int col = 0; col < dim; col++) if(row == col) trc += mx[row][col]; return trc; } void print_nxn_matrix(int dim, int mx[][dim]) { for(int row = 0; row < dim; row++) { for(int col = 0; col < dim; col++) { if(row != 0 && col % dim == 0) printf("\n"); printf("%d ", mx[row][col]); } } } void add_matrices(int dim, int mx1[][dim], int mx2[][dim]) { int sum_mx[dim][dim]; for(int row = 0; row < dim; row++) { for(int col = 0; col < dim; col++) { sum_mx[row][col] = mx1[row][col] + mx2[row][col]; } } print_nxn_matrix(dim, sum_mx); printf("\n"); }
Crazy Jake · 2017-09-12 04:32
>>3418
Motoko Kusanagi · 2017-09-12 14:15
Hey, I am sorry; I didn't read many of the replies on this thread but I have some advice regarding >my brain just buffer overflows I try to hold all the code in my mind. I can't stop this, whenever I try to write the code I imagine it in my head executing and that's when my brain gets overloaded till the point that I get headaches. soykaf. Use a paper and a pen instead of keeping it all in your head. I also try to imagine the code but I sometimes find it difficult. I use scratch paper when my head starts to hurt; it is also less prone to making mistakes and jumps in logic when you're actually writing on a paper rather than keeping it all in your head because you are not focusing on thinking and keeping all of the info that you have thought of so far in your head at the same time. Even when it comes to things like implementing algorithms or data structures, I sometimes use a scratch paper to make a simple representation of how the algorithm is working. This is just how I do it, so it may or may not work for you.
Hiro Protagonist · 2017-09-12 20:10
>>3437 Candle flame meditation will get rid of this for you. I used to have this thing, where I'd get over loaded and just get really sleepy all of a sudden, almost pass out from it. Here is a video that kind of walks you though the basics. https://www.youtube.com/watch?v=J6k8PGpOaHQ Basically you are just training your self to focus on one point in space instead of letting your mind absorb everything so fast. So you need to do this for at least 25min to notice the effect ( there is some science behind the brain pattern you switch into ). After one week and it will be a night and day difference. >Some things I do differently I like having some sort of "white noise", like a meditation gong, monk noises or just strait up white noise. I find his body part focus to be really easy to loose, but having a meaningless noise to focus on is much harder to break focus. good chant https://www.youtube.com/watch?v=GslzWvQRiJg pure white noise https://www.youtube.com/watch?v=bNqERBWaJeM Also as I try to clear my head to focus on the flame, I find I think about all the soykaf that is pissing me off. I find if I scream and let it out they go away a lot faster than just practicing contemplation. Trying not to think about things creates conflict which makes you think about more things. So just get whatever it is out, and stare at your flame. I noticed a difference in how much "quieter" my mind was after the first time, but didn't see big results in my shear production levels until two weeks. This really works, if you've tried things before and just haven't had any luck, try this. It's worth a try.
Wintermute · 2017-09-12 21:01
>>3332 Thanks man >>3363 >I would like to see OP make some basic sloppy apps to show themselves that they CAN program and then gradually add complexity to their programs, grow into new languages ec I'm not sure if this is the right approach. My main goal is to realize a private project that will be a simple embedded device since the market doesn't provide such a product. That means I don't want to be a programmer really but an embedded device maker. I figured I'll need to learn a fitting language like C for that so that's what I first started doing. I like your suggestion but maybe it would be more fitting for me to start working with embedded stuff right away? >>3365 >Excuse me, have you accepted OTBS as your true lord and savior? Seriously though, please do some indentation and use a better brace style. Ah soykaf When I pasted the code here the formatting got lost. I was just finished with the code too exhausted at that point to fix that, sorry. >without braces followed by a else bracket is bad style. My textbook said something about brackets and the body of the function so I figured I have to put brackets around many related statements while a single statement doesn't form abody or block or whatever and doesn't deserve brackets - it made sense in my mind since a single statement in brackets looks foolish. lol > The way the else wraps makes it still execute the multiplication. Proper brace the if and have it return after the error message and drop the else entirely. I wasn't aware of this, I'm not even done with learning the language yet. >The parentheses it the celltemp assignment statement can all be dropped and those around the matR assignment as well. Yeah, I ran into some trouble in this part of the code so I wanted to make sure by putting some extra parentheses. Thank you, you made some good points. >>3418 >>3419 Actually I noticed this when reading code on the net but I kept my version since I it made it easier for me to keep track of the matrix elements. >>3420 if (aw!=bh) Haha, yes, it's easier to read but I was kinda proud that my mental gymnastics version actually worked so I kept it like that for (b=0;b<aw;b++) { printf ("cell %d%d: \t", a+1, b+1); scanf ("%d", &matA[a][b]); } well, as indicated in the posts above yours. The array starting at zero is nice and all but I'm not sure if it's really worth it since the a+1 and b+1 changes become necessary as well (matR[l][n])+=((matA[l][a])*(matB[a][n])); I tried a similar thing but ran into into weird errors, something about lvalues - I didn't quiet get it and just fixed it with the two "cell"variables Thank you for the feedback
THE OTBS EVANGELISM STRIKE FORCE · 2017-09-12 22:31
>>3445 Afterwards I saw in another thread the same happening and realized pasting must have b0rken the indentation. No harm intended. My statement with the brace style remains though. Come and join us! You might think it looks foolish, but imagine this: You keep this brace style but add another statement, properly indented, after the error printing, like the return statement I suggested. If you happen to overlook that there are braces missing, after all its indented and the else got braces, you will be wondering why your program suddenly just terminates without printing the result. Easy mistake, and this happening in a more complex piece of code will make you pull your hair out. My comment about changing the flow (return, no else) is something you would be doing on your own too once you're more familiar with everything. Generally speaking you want as little nesting as possible. So why wrap all the following 50 lines into an else block if if you could directly return. That way you know that after this line that requirement holds. If you were adding some new code at the end of what you've written you again would have to remember that it could violate your property or needs to be inserted before the braked that closes the else. If your at the end of a block and can't see the start of it, its usually a bad sign. Parse. Sanitize. Execute. I hope this makes sense to you and is not too general. >well, as indicated in the posts above yours. The array starting at zero is nice and all but I'm not sure if it's really worth it since the a+1 and b+1 changes become necessary as well Small problem here. You're actually corrupting memory because you're writing 4 bytes (size of the ints) past the bounds of your arrays. These C99 variable length array declarations are placed on the stack. I haven't checked because that would be a bit tedious but memory layout wise these three matrices should be one after another. That means in two case writing into [n] of one results in writing [0] of the other. Since you're initializing with [1] to [n] they don't overlap. But in the third case you're potentially writing in another local variable and it just happen to work out. And if you start to make all your array[n+1] now I will find you and I will you feed the entire "The C Programming Language" book. Still love you lain :3
Anamika · 2017-09-13 14:58
>>3445 >That means I don't want to be a programmer really but an embedded device maker. I figured I'll need to learn a fitting language like C for that so that's what I first started doing. Well, I think you should approach becoming a >embedded device maker As a composite goal. To do well at it you will need to be a programer, and an electrical engineer and often a industrial designer. You do need to learn to program, which would make you a... programer. C with project boards is not the best rout for learning, even if it is your end goal. However, neither is Python or other high level languages. The quickest path between you and your goal is to take up Commodore 64 tinkering. It may sound odd, but its actually the norm. The very best people in the field to day started by tinkering with a C64 in the 80s. Commodore 64, or C64, runs off BASIC, which is just C with training wheels. The data structures are almost identical, but no messy syntax, and you still manage your hardware, memory / device addressing etc.. Once you've learned BASIC and C on a C64, Assembly is pretty easy. Naturally, after you have these tools under your belt, there really isn’t anything you can’t do in terms of developing embedded systems or devices. Here is a great book to show you how far up in the guts of it you can get. https://archive.org/details/The_Anatomy_of_the_Commodore_64 There is also massive C64 community out there, way better documented than any project board out there including, i'd argue better than the Raspberry Pi ( but not as available ) >Community Plug One of the best people in the C64 community is Jeri Ellsworth, not quite Lain but close enough ;D here is her YouTube channel, https://www.youtube.com/user/jeriellsworth. She is amazing at explaining electrical engineering and low level programing concepts. She of course started with the C64 and is entirely self taught, and has since taught at Stanford and worked at Valve. Here is a C64 emulator, the hardware is getting more expensive and no one is putting out remakes reliably. http://vice-emu.sourceforge.net/ Here are the old magazines you could get with "type in programs" https://archive.org/details/commodore_microcomputer Here is a guy who has some interesting videos on the C64, ranging from understanding the hardware level components to the programs. https://www.youtube.com/watch?v=ozKcF6Q6DhI Here are some other community resources https://retrocomputing.stackexchange.com/questions/tagged/commodore-64 https://hackaday.io/project/9587-raspberry-pi-zero-commodore-64-interface-board https://amigalove.com/ https://cbm8bit.com/
Random · 2017-09-13 16:54
>>3453 pretty sure lain's navi was modeled after this actually sage for off-topic
Hiro Protagonist · 2017-09-13 17:01
>>3443 Thank you so much for the suggestion. I will definitely try this.
null · 2017-09-13 17:40
>>3301 how the fuarrrk has nobody mentioned this: matA[ah][aw] this is very wrong. you can't declare dynamic arrays in c. i'm not sure how you even got it to run.. it should just segfault. i suppose now is a good time to learn about dynamic memory: #include <stdio.h> #include <stdlib.h> int main (void) { /*int variables*/ int aw, ah, bw, bh, a, b; int *matA, *matB; /* declare 2 int pointers for the matrices */ /* ask for matrix sizes */ printf("input matrix A size (rows)x(columns):\n");/*rows aka height, columns aka width: aw - column value (width) of matrix A*/ scanf ("%dx%d", &ah, &aw); matA = malloc(sizeof(int) * ah * aw); /* ALLOCATE memory for matrix A now that size is known */ printf("input matrix B size (rows)x(columns):\n"); scanf ("%dx%d", &bh, &bw); matB = malloc(sizeof(int) * bh * bw); /* ALLOCATE memory for matrix B now that size is known */ /* check for mathematical correctness */ if (aw-bh) /* error if colums matixA do not equal rows matrixB */ printf("error: matrices not fit for operation \n"); else { /* set elements in matrices */ printf ("enter elements for matrix A: \n"); for (a=0;a<ah;a++) /* indexes start with 0. always write for loops like this */ { for (b=0;b<aw;b++) { printf ("cell %d%d: \t", a, b); /* this part is tricky. the normal 2D accessor will not work in this case, so * we have to do something different. we are going to store this matrix in * "row major" order, meaning that the rows are stored after eachother in one * long array. so to get the element in row: a, column b we have to multiply * the row number (a) by the number of columns in the row (aw) and add the * column number (b) to the result. */ scanf ("%d", matA+((a*aw)+b)); } } printf ("enter elements for matrix B: \n"); for (a=0;a<bh;a++) { for (b=0;b<bw;b++) { printf ("cell %d%d: \t", a, b); scanf ("%d", matB+((a*bw)+b)); /* same changes here */ } } } /*multiplication process*/ int *matR; /* once again, declare pointer for the result */ matR = malloc(sizeof(int) * ah * bw); /* ... and allocate memory for it */ int l, n;/* for loop use*/ for (l=0;l<ah;l++) /* calculate cell 00 then cell 01... then switch to next row and calculate 10, 11 and so on */ { for (n=0;n<bw;n++) { /* we are just going to use the cell of the result matrix as an accumulator */ matR[(l*bw)+n] = 0; /* it's initialized here (you could also call calloc() above) */ for (a=0;a<aw;a++) { matR[(l*bw)+n] += (matA[(l*aw)+a])*(matB[(a*bw)+n]); } } } /* there are certainly faster algorithms, but that'll work... */ /* print the result*/ for (l=0;l<ah;l++) { printf("\n"); /* next row */ for (n=0;n<bw;n++) { printf("%d ", matR[(l*bw)+n]); } } printf("\n"); /* IMPORTANT: free allocated memory before returning */ free(matA); free(matB); free(matR); return 0; }
Acid Burn · 2017-09-13 18:01
>>3458 Sure you can. Maybe it's only something that's been included in later C standards but this: int main(int argc, char** argv){ int x=atoi(argv[1]); asm("beginarray:"); char array[x]; asm("endarray:"); array[0]=42; return 0; } Compiles and runs just fine, ignoring that it's very unsafe. It compiles down to instructions that calculate the array size and then decrement the stack, though it isn't truly dynamic as it can't be resized after the fact.
Jet Black · 2017-09-13 21:03
>>3459 >Maybe it's only something that's been included in later C standards Don't think so. It just looks like >>3458 didn't think it though. The assembly labels are a nice touch by the way. >it's very unsafe Since this is a learning thread I'll try an expand on that. It's unsafe because the stack has a limited size but the code is letting the user input any number for the array length (including a number larger than the stack size). Creating an array bigger than the size of the stack can cause the program to read or write unused memory which will result in a crash (segmentation fault). Which is bad. Additionally, after the stack comes the heap. Depending on the level of control the user has over what gets written to the array they could potentially hijack the execution flow of the program (by overwriting a function pointer on the heap for example). Which is really bad.
Neuromancer · 2017-09-14 01:46
>>3462 https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html only for c99. i'll admit this is unlikely to be an issue, but OP is learning. >>3459 on my pc, your example segfaults with both gcc and clang.
William Holtzer · 2017-09-14 04:55
>>3479 >on my pc, your example segfaults with both gcc and clang. You did pass a numeric argument on the command line right? Otherwise it'll segfault looking for that.