/t/ - Technology

Discussion of Technology

[Index] [Catalog] [Archive] [Bottom] [Refresh]
Mode: Reply

Max message length: 8000


Max file size: 24.00 MB

Max files: 5

Supported file types: GIF, JPG, PNG, WebM, OGG, and more


(used to delete files and postings)


Remember to follow the rules

The backup domain is located at 8chan.se. .cc is a third fallback. TOR access can be found here, or you can access the TOR portal from the clearnet at Redchannit.
Upgrade success! 8chan.moe is now running on the LynxChan 2.4 engine with our custom frontend. Please report bugs on /site/.

8chan.moe is a hobby project with no affiliation whatsoever to any other "8chan" site, past or present.

Programming Thread: Up and Running Edition Anonymous 04/27/2020 (Mon) 19:03:16 No. 9
Hey Anon, Learn to Code! There's a bunch of free resources for learning to program. Come here to ask for advice or to discuss current projects. Download the complete Gentooman's Library: https://g.sicp.me/books/ Visit MIT OpenCourseware on (((YouTube))) https://www.youtube.com/user/MIT Or take one of these free online courses being offered by universities right now: https://www.freecodecamp.org/news/free-courses-top-cs-universities/
Edited last time by codexx on 05/04/2020 (Mon) 00:54:19.
learning to code is easy learning to code something with a degree of complexity well is a different matter where are the resources for that?
(106.35 KB 1200x675 C4iv_loUoAAcN-5.jpg)
>>15 I've added a few more advanced resources to the OP. >code something with a degree of complexity If you have something specific in mind, post a request and I'll dig up some resources. If you just want to learn how to do software engineering, there really is no substitute for actually joining a project or getting a job/internship, unfortunately. If you just want a chance to get beyond learning a language and repeating then the answer is to understand data structures/algorithms and to actually build a project for yourself.
>>16 yes, more on the engineering side. Naturally you only get good at it by actually working, but are there established do's and dont's?
>>64 There's what they teach you in a software engineering course about good and bad practices, but the actual practices change by company and in my experience insisting one way is "the right way" to do something will just draw ire from others on the team, especially those with seniority. Most software is developed haphazardly based on internal guidelines. The only universal rules would probably be >always use version control >documentation helps >set realistic goals and milestones Even something recommended like code reviews or style guidelines can be abused and turned into a hindrance. Good software engineering practices also vary by language. The way you want to package a Python product is much different from a C++ product, even if they have the same development pipeline. If you want recommendations, you should honestly focus on the stupid DevOps bullshit. Make sure you're comfortable with git. Write test cases. Configure a Continuous Integration pipeline to automatically build your code and run tests. These things, when done properly, make managing large codebases easier. The cruft and technical debt of a small script is very little. Having good regression and unit tests helps identify problems as you make changes. If you want to practice, you're probably better-off writing toy software that mimics actual products. Can you design a word processor? How about an image editor? These things will take more time than most of the project ideas included in the OP, but you will encounter the sort of problems real products face.
I don't want to spoil my brains with that garbage.
(2.92 MB 500x606 934h87tg9384h9384y3984y5.gif)
I actually ordered the SICP book because I'm a music autist and want to learn MIT Scheme for Lilypond music engraving. It's either that or paying some fag 2,000 bucks for what I need and fuck that shit.
>>92 Good luck, anon! We'll be here if you need any help. By the way, you can find the full text of the book along with assignments, code samples, etc on the MIT Press website. https://mitpress.mit.edu/sites/default/files/sicp/index.html
(23.36 KB 100x100 XD.gif)
>>93 Ooo, has the instructor side too. I saw it for sale but chose not to buy it. Neat.
What are some basic programming concepts that you failed to grasp when you were starting out? I completely misunderstood the utility of classes and essentially only used them to separate variables into several .cpp files. I didn't think to store related variables in one class until way later when I realized that it'd be convenient. The closest I came to that was storing related values of the same type in a vector, and eventually I thought "hey, there should be a way to access related variables by their name, shouldn't there?" and figured out that I'm a dumbass. That sort of comes with the territory of how I learned shit, learning a new language plus several libraries all at once from several disconnected jewtube tutorials and trying to get shit to work while googling errors until things worked. No, I'm totally not asking to see if you'll end up naming more things I might have missed. What makes you think that? Haha.
>>478 Mostly struggling with APIs or bindings. Over time I've realized that documentation isn't great or that I was using someone's half-finished project advertised as a complete solution. Sometimes libraries are just stuck in a different decade. A lot of them do their own thing, which might clash with the base language or other libraries. Not entirely my fault, but I've never found interfacing with other software as easy as it should be. Never struggled much with the code itself. Once I learn to read someone's style, it opens up to me. Most of my early learning curve was spent on tooling. Git takes time. Debuggers take time. Editors take time. Time to learn the basics. Time to learn how you can customize them. Time to build a workflow. Time to learn the idiomatic way to write code. Also, I didn't learn it the hard way (thankfully) but writing solid tests is worth it. Especially if you can configure a Continuous Integration pipeline. Not a big deal for small personal projects, but I find even a few unit tests to ensure my scripts haven't broken serves as a good sanity check.
>>478 Probably the importance of using 3rd party libraries. For example, one day I wanted to crawl a website and instead of using libcurl or some other library to do the webpage fetching I built my own engine using raw sockets and an HTTP parser I made. It was a piece of shit too, but it actually did its job. Also related, for some reason I find object oriented design very unintuitive and I often struggle a lot with it. What's even more funny is that when I code in C, every time I do it I end up writing object oriented C and I love the code that results from that. I don't understand why C++ gives me so much trouble.
>>478 >What are some basic programming concepts that you failed to grasp when you were starting out? < What OOP really is about I got taught the typical "a cat is a mammal, which is an animal" kind of OOP they teach everywhere. It's really easy to understand, but unless you program is built around zoological taxonomy, it's completely useless. I wish I could have just been taught what OOP really is about instead of having to work it out myself. < Assuming that if something is not said, then it doesn't apply This is really dumb, but I remember once reading in an API documentatin that a linked list has O(n) access time, while it said nothing about hash tables. So being a moron I used a hash table, even though at four items the overhad of the hash table would have probably been greater than the indirection of a linked list. Of course the realy solution would have been to just use an array. < Writing code more complicated than it needs to be By this I mean using 'foo.bar.baz()' several times instead of assigning it to a variable. I was young and thought "bah, there is no need for creating a variable here, I can read everything just fine". Now that I'm older I can still read it, but after having read so much code I don't have the patience for untangling all these chains. Now I declare my variables at the start of each block and break up big functions into smaller chunks.
>>491 >I got taught the typical "a cat is a mammal, which is an animal" kind of OOP they teach everywhere. It's fine for teaching inheritance. It's just utterly useless as a model for how to write a program. You don't necessarily need inheritance to use objects, and your objects don't need to be like real objects. They're just containers of similar variables with a defined interface. But that still doesn't really cover how they're used in industry, probably for two major reasons. First, because describing how to use them properly is nearly impossible. And secondly, because there's lots of "how not to do it" examples in industry where people have created horrible abuses of object-oriented programming, decided they were a genius, and then slapped a name on it and tried to convince others to do the same. And some people listened. And that's how you end up with all these custom typedefs to hybrid classes that all inherit from each other with the sole goal of operating a factory that produces custom objects at runtime. Instead of just designing the classes you actually needed to rigidly cover a set part of the spec.
what is the best internet browser?
>>493 >>3 Just realized there's no name field?
is college a good idea if your main goal for learning to program is to get a job?
>>498 Depends on what kind of job you want, really. Some will require a Bachelor's and will not look at you without experience. Most will care about experience over a degree, but your resume will need to be solid so expect to put the time you'd have put into school into projects. I think the biggest benefit of attending college is that you'll be forced to do tedious programming puzzles that a lot of employers like to ask people about. That can help. Otherwise you might spend more time doing real work and have zero experience solving problems in vacuum. Plus it will force you to learn a variety of subjects. You'll be exposed to a bit of everything at a good school. Some might complain about taking an Operating Systems class when they just want to do Machine Learning, but I think being well-rounded is beneficial. Same goes for your general courses; you'll be asked to read and write at a college level, and some STEMlords just fail at that and really need it. Going to school takes discipline but they'll give you assignments with deadlines and that has a way of getting people off their ass more than "I promised I would work from SICP today". So if you're bad at self-control when on a home desktop then college has another benefit there. But the downside is the cost. Unless you're going to a local school and your government is covering the bulk of it, the bill can be daunting. Definitely try a community college first to help on savings. If you go that route, sometimes an Associates is enough to get a programming job. It's also a minimum 3-4 years of your life being trained, so you need to ask yourself where you want to be in 5 years and hold yourself to a schedule. Otherwise you can spend forever lurking the halls of a costly institution. The alternative is to just do webdev, which doesn't require a degree basically ever. You'll be a glorified graphic designer doing frontend work in JavaScript frameworks. Absolute cancer if you ask me. But the pay isn't bad (although dealing with clients often is) and a total moron can pick it up with enough time. If you want to write software but can't be bothered to learn "real" programming, you always have that as an option.
(70.34 KB 1191x1684 file-001.png)
(70.23 KB 1191x1684 file-002.png)
>>498 I see four ways of getting a programming job. There are others, if your lucky. >Option A >No college >Either your really good or you know the right people >get job >Option B >be autist >College >git gud >no friends >do FOSS/side projects >send 100s applications >get job >Option C >be normalfag >College >network (parties and bar) >fuck bitches >network (volunteer and part-time) >fuck bitches >get job >Option D >all of the above >genius, never study, GPA 4 >party boy, zigachad >FAGMAN internships, 5 years experience before graduation >Is actually the hidden master of Linus and Theo t. collegefag
>>498 It's a waste of time if you can avoid it. My "computer science" college was a joke and full of downers. Literally being able to read a man page and knowing to put #define nigger_h #ifdef nigger_h at the top of your file already puts you an order of magnitude above eveyone else for the first 3 years. I dropped out near the end because I got a job paying good. I couldn't be fucked to finish it as all it would have taught was some more basic progrmaming shit, and it was pretty obvious at that point the "how are you gonna get a job without le diploma" meme is just that. This was 10 years ago.
(58.00 KB 644x573 oop.png)
>>498 College can definitely help you find work. Most of the material was shit, but I did get two internships through my program and made some pretty good contacts. Research whether your college has a work experience program. HOWEVER, you need to be aware of the job market in the areas where you want to work. (Which may just be the city you live in.) I'm in an awkward position now because all my work experience is in embedded and dsp, but most of the jobs in my city are webdev. I have been unable to get programming work for the past few months, probably due to the the economic downturn and my relatively niche field. My only comfort is that I am not a webdev.
>>513 >#define nigger_h #ifdef nigger_h that's not an include guard <#ifndef nigger_h <#define nigger_h <//coad <#endif nigger
>>493 >what is the best internet browser? Don't need fancy formatting? Use some terminal-based browser like lynx, w3m, elinks, or something. >Want CSS On anything GUI, keep Javascript turned off. Use Tor browser. >Don't care about being anonymous 100% of the time, want reprieve from capchas Brave. Chromium-based so it's highly compliant, de-googled, privacy-focused, and pays you crypto just for being on the internet. Also includes Tor privacy mode so you don't have to change proxy settings whenever you want to use it over Tor (but probably best practice to just use Tor browser when using Tor even though I just use Brave Tor windows lmao)
>>532 >Brave. Chromium-based so it's highly compliant Made up issue. Literally any bloatware browser is compliant enough for the jewniggernet. >1 BAT has been deposited into your account.
>>533 Are you capable of speaking without using a buzzword every second?
(9.00 KB 331x379 max 1.PNG)
(16.46 KB 613x640 max 2.PNG)
So, I picked up C three days ago. I am quite new to programming, with only some very small experience left and right, but good experience in MATLAB. I have two questions. In max 1 (which actually returns the sum, it should be sum() ), what is exactly happening with the pointers? I make a double array, and specify its three elements. I pass is to the function, and this is where my understanding stops: I think that the * at max() turns the a in main() into a pointer, which is then passed to max(), where I can use is as x[] to call values? In the second program my understanding is even worse: In main() (the commented code) I create a char array, which is filled with cmMod(111111) for example, which returns 1 km, 111 m and 11 cm. I can use this array to call its values, but why is the star then present at char *r? Secondly, why is the * present at *cmMod()? This would cause the function to pass a pointer to my array right? Finally, what does if(!r) return NULL; do?
>>569 >I think that the * at max() turns the a in main() into a pointer No, the * in max interprets whatever the function is receiving in that parameter as a pointer. You're probably getting confused because you don't see a * in main. In your example, you're using a vector, and vectors have a very similar behavior and syntax to pointers, in particular what's happening here is that the name of the pointer or vector when used yields the memory address it points to, so max is being passed that memory address and using it as a pointer. To give an example, you could have: int main(void) { double a=1.5;; printf("%f\n", max(&a, 1)); return 0; } And this would also be valid. Despite the fact that a is not a pointer, you're passing its memory address to max (because of using &), and max is interpreting as a pointer. This would not work without the & because then you'd be passing a value to the function and the function expects a pointer, so the compiler would complain. >why is the star then present at char *r? Secondly, why is the * present at *cmMod()? Please use line numbers the next time, it makes things easier. The * at declarations mean to specify that you're declaring pointers. Declaring a pointer means that the variable is meant to contain a memory address and that the variable (pointer) allows the syntax to examine and change that memory address (pointer syntax). If the * is not present at the declaration, the variable would be meant to contain values (integer, floating point values, or other values). So in this case the * are present because you're manipulating memory addresses (first returned by malloc() and assigned to cmMod::r, then returned by cmMod() and assigned to main::r ). This applies both to the variable declaration (char * someVariable) and the function declaration (char * someFunction() for instance). >Finally, what does if(!r) return NULL; NULL is a value that is supposed to be an invalid memory address. When you compare a pointer to NULL, you're checking whether the pointer contains a memory address that's invalid. Here, the code is checking whether malloc() returned a valid memory address or not. If the system is low on memory, or you request a fuckhuge amount of memory (3 terabytes for instance), malloc() can only return NULL and hope you catch in your code that it couldn't allocate the memory you requested. Fuck, I feel like making some code now.
(208.31 KB 500x375 cup of absolutely fantastic.png)
>>570 Holy shit, thank you so much for the detailed explanation! I'll have to look over it a few times, but this already really helps a ton dude. I've been making random exercises from websites for now, and I am already somewhat comfortable using the syntax and structure. Feels really powerful and straight-forward, and seeing there is a large chance I'll be using code for my career this summer project of mine is really helpful.
>>528 >I'm in an awkward position now because all my work experience is in embedded and dsp, but most of the jobs in my city are webdev. I have been unable to get programming work for the past few months, probably due to the the economic downturn and my relatively niche field. My only comfort is that I am not a webdev. I know those feels. >>571 Always happy to help someone get into C. >Feels really powerful and straight-forward It is, it's also pretty consistent. I love it. One thing I noticed about my previous reply: >>570 >Finally, what does if(!r) return NULL; What I wrote before is correct but I didn't notice the comparison was made as "if(!r)", which is a niggerish way to do it. Because in most systems NULL equals 0, and because 0 equals boolean false in C, "!pointer" is most of the times equivalent to "pointer==NULL", but there are systems where 0 is a valid memory address which is why NULL is implementation defined, so hardcoding it to 0 is not a good idea.
(25.31 KB 519x475 costs.PNG)
Yet another (probably) retarded script: a function to calculate energy costs. First 50 units cost 0.5 /u, next 100 units 0.75 /u, next 100 units 1.2 /u and all units beyond will cost 1.5 /u ; an additional surcharge of 20% is added. My question is not so much about the correctness (it shits out all the correct (edge) values, I manually verified) but more about the first 203-205 and 206-209. I want this script to be flexible, so I wanted to add 'delims' numbers of delimiters, which can be filled in independently of cost and unit limit. Finally, a final cost per unit is given and a surcharge. My problem lies in the use of arrays to store these values in. Initially, delims was just int delims = 3; , line 203 was int *unitdelim[DELIMS]; , lines 204-205 were uncommented, but compilation failed (expression { token, variable-sized object not initialized) in the array value assignment without using a loop - which was given as the solution on some websites? So, If I want an elegant solution without bombing my memory or leaving any remains after the function has been called, how would I approach this? >>572 Got it.
>>570 Also, I now understand nearly exactly what was going on! I described to myself out loud what exactly what is happening, and thinking in terms of the pointer as a special flag for handling said pointer did the trick: at last, I truly see how the addresses and values are manipulated and passed.
>>569 What >>570 forgot to mention is that in C arrays decay to pointers when you pass them as arguments to a function. That is, if you have an array of three integers and pass it as an argument to a function, all the function gets is a pointer to the first element of the array. The function does not know how long that sequence is, so you either need to pass the size as an extra argument or have a sentinel element (e.g. have the last element be a negative number when only positive numbers make sense). This array decay is one of the ugly parts of C. >>574 I don't understand what you mean, but I noticed a problem in your code: you need to tell malloc exactly how many bytes you want, not how many elements you want: < unitdelim = (int *) malloc(delim * sizeof(int)); Keep in mind that if you reserve memory that way it will be allocated on the heap, not the stack, so you need to manually release itas well. The array definition above is allocated on the stack and does not need to be released manually. Unless you need your data to persist after a function call you should prefer the stack. I also noticed that you did not declare any type for the allocated data. You need to declare the variable as a pointer to integer. Note that pointers and arrays are not the same, you cannot assign a memory address to an array variable. Arrays can decay to pointers, but they are not pointers and you cannot assign pointers to them. Are you learning C from websites or are you using a book? Websites can be really shit, I recommend the K&R C book, it's quite small for a programming language reference book, and very well written. With websites the quality is usually what you paid for. >>572 > but there are systems where 0 is a valid memory address which is why NULL is implementation defined, so hardcoding it to 0 is not a good idea. I'll need a source for that one. In my copy of K&R C (2en edition), section 5.4 it says > C guarantees that zero is never a valid address for data, so a return value fo zero can be used to signal an abnormal event, in this case, no space. > Pointers and integers are not interchangeable. Zero is the sole exception: the constant zero may be assigned to a pointer, and a pointer may be compared with the constant zero. The symbolic constant NULL is often used in place of zero, as a mnemonic to indicate more clearly that this is a special value for a pointer.
>>576 Let's try that then. Also, yeah, one of the advantages of MATLAB is that it is perfect for very mathematical things: matrix, vector and differential equation stuff are handled more conveniently.
(32.89 KB 1920x1080 autism.png)
>>576 >This array decay is one of the ugly parts of C. It can be pretty ugly, it's bitten me in the ass a bunch of times. In any case anon was handling it correctly. >>574 >I want this script to be flexible This is good practice. I think the easiest way to make this work would be to not declare a size for the array in the initialization and let C do this for you. Then you calculate (at compile time) the size of the arrays and assign it to delims: int unitdelim[]={50, 100, 100}; double unitcosts[]={0.5, 0.75, 1.2}; const int delimQty = sizeof(unitdelim) / sizeof(unitdelim[1]); What I don't like of this solution is that the arrays are disjointed. If you want to change your code later on, you will have to change two independent lines of code in a concerted way or your program will have bugs, and it's good practice to minimize this. Regarding the solutions you proposed: >which was given as the solution on some websites? C99 mandated that variable sized arrays like the ones you tried to use were okay according of the standard. Some compilers (MSVC :^)) didn't think it was necessary to comply with that because why comply with standards. C11 removed this restrictions because it was too difficult for some to implement it in their compilers and certify them as standard compliant, so it was left as optional, and you're left with a situation to resolve. Which you probably tried to do with >#define delims 3 Unfortunately #define will define delims for the whole rest of the file, which is undesirable. Slightly more elegant is to use an enum like a nigger: enum {delims = 3}. There aren't a lot of other elegant ways to solve this in a nice manner. >int *unitdelim[DELIMS] >unitdelim = (int *) malloc(delims) There are several problems with this. Like anon commented you're allocating only delim bytes, but you meant to allocate delim elements (of a certain type). The other problem is that you're declaring unitdelim as an array of pointers. This means each slot of the array will contain a pointer, not a value, which is what you want. Furthermore, despite the error of trying to assign the address of the array like anon explained, there's a conceptual error: malloc returns one memory address for a whole block of memory of the size you requested, so you'd be assigning one of the pointers in the array, not all 3, meaning the other 2 would still be uninitialized and would likely crash your program on access. See pic related for how things would look like in memory after this had executed, assuming pointer sizes and ints of 4 bytes. >unitdelim = {50, 100, 200}; In C, initializer lists may only be used on initialization (in the same line you define your variables), like in #203 on the image. >>575 das good. >>576 >I'll need a source for that one. In my copy of K&R C (2en edition), section 5.4 it says The NULL part is easy. Here's a link to one of the latest revisions of C11 (revisions are available for free): http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf >7.19 Common definitions <stddef.h> >The macros are >NULL >which expands to an implementation-defined null pointer constant So the standard doesn't mandate that NULL is 0. The other part (0 being a valid memory address) comes from experience as there are embedded microcontrollers where this happens (they have 0 as a valid memory address), but to be honest I assumed this was enough to conclude it was kosher according to the standard and didn't actually double check it. I actually had to handle a case of this myself, as I was brought on board on a project that was on fire and used a microcontroller where this happened. The original programmer had created several bugs where 0-initialized pointers were being passed to functions and then indirected for write operations. The program was not segfaulting (because the memory was A-OK to write according to the memory model of the device) so the bug had always been in the firmware silently corrupting memory away, which is kind of funny considering the device was making the company several million dollars a day in revenue.
>>576 >Arrays decay to pointers The idea that it "decays" is false. Arrays are always stored as a memory address. There is simply no way to pass them by value since even an array stored locally is actually just a "pointer". You can just as easily perform range operations on any pointer. int ptr[n] is just syntactic sugar for "address at ptr + n * sizeof(int)". Understanding that you'te just accessing straight memory addresses is actually quite convenient. You're not losing anything when you pass it in to a function because naked arrays already fail to offer any convenience functions. In C++ you could always pass in a vector or some other data structure, but you'd be wise to do that by reference as well.
I hope I am not spamming the board to death, at least I'll give it some traffic >>576 I would have declared a datatype in the first line, as described in >>574 . >>576 >>578 > malloc Makes sense. I was also in doubt about using calloc, since this uses a second argument as datatype size. That clears it up, mostly. Two further questions: in that case, why does max2.png in >>569 work? I only reserve three bytes (?), while I place three ints in it? The function does return the correct values. Second, > Keep in mind that if you reserve memory that way it will be allocated on the heap, not the stack, so you need to manually release itas well. The array definition above is allocated on the stack and does not need to be released manually. Unless you need your data to persist after a function call you should prefer the stack. So does malloc/calloc allocate on the stack or the heap? This sentence conflicts a little. Then, how would I or when should I release the memory when using such a function? > Book Nope, the first tutorial I used was https://www.youtube.com/watch?v=KJgsSFOSQv0 , and I am now doing Pajeets big book of exercises at https://codeforwin.org/c-programming-examples-exercises-solutions-beginners . Since I have some programming knowledge from Uni and am somewhat versed with how computers work on a physical level - plus calculus C level of mathematical knowledge did not prompt me to read a book yet. I might download or find a copy of the K&R sometime, if it is exceptionally helpful. >>578 > calculating at compile time This would probably be the most elegant solution for the application I am using, since you would just have to change a single predefined number and would not have to worry about the later definition. > disjointed arrays Do you mean concatenating the strings? Or a struct? The variables have no mathematical relations, as they are predefined by the "Electrical company". > declaring an array of pointers I see what happens now. Yeah, it should just be an array of values I use for the price ranges. I should write out what happens on paper, that'll help. > using enums Which is not really that convenient of a solution no? Finally: for future reference - this means that I can not return a variable length array from a function right? I foresee that it might become a problem when doing variable timestep integration.
(8.08 KB 290x275 memory.PNG)
>>580 > releasing memory I have an example function for this; image related. I just want to retrieve the first and last digit, but after the function has been called, I stored the variables in my main "variable space(???)" and I wouldn't want the original values to be left somewhere taking up memory.
>>580 >I only reserve three bytes (?), This is correct. >while I place three ints in it? The compiler automatically converted them to char. Read up on type conversions. Also increase the warning level in your compiler (/W4 in MSVC, -Wall in GCC/Clang) to have it bitch at you for such conversions. Ideally your data types would match, otherwise it's good to have the compiler warn you when they don't because type conversions are very tricky and if something doesn't match, it's a good idea to review it (and after reviewing it and confirming it will do what you want, you can use type casting to tell the compiler to stop warning you for that occurrence). Looking the function closer it looks like r[2] might overflow for cm>127999 (as 127999/100000 would give 127, which is the maximum positive value a signed char can hold). >So does malloc/calloc allocate on the stack or the heap? On the heap. You allocate on the stack by declaring local variables (uint8_t bigassBuffer[0xFF]) or using alloca(). The latter I'm not sure if it's standard and there's seldom a reason to use it. Also keep in mind the stack is not the heap, the stack is designed to hold enough memory to pass arguments to functions and hold local variables (so a bunch of bytes), don't abuse it. On a PC you probably will have plenty of stack but that will not be the case in every device. On the other hand, stack memory is allocated extremely fast while dynamic memory is a huge headache and not available in more modest devices, so you have to reach a compromise. >how would I or when should I release the memory when using such a function? See free(). >The variables have no mathematical relations They have an important relation in the program. Consider a large function with a couple hundred lines of code and a big preamble of variable definitions, and let's say that you haven't touched this code in a year or two and then you want to make some changes to it. You will have to remember that if you add another value to one of the arrays, you also have to add a value in the other one, and if you don't do it when you go through the arrays in the for you might go out of bounds. This is undesirable, so ideally the code would be structured in a way that wouldn't let you fuck up like this. >Which is not really that convenient of a solution no? Ideally you would just declare the flexible array but it's not portable, so you have to compromise. >this means that I can not return a variable length array from a function right? You can do a couple of things, like creating a structure with the pointer and a size member and passing it as a (pointer) parameter. Something like this for instance: struct param { uint32_t size; char *ptr; } void func(struct param *p, int number) { const static char str[] = "NIGGER"; const uint32_t len = strlen(str); const uint32_t size = len*number+1; //consider terminating null int count; if(p==NULL) return; p->size=size; p->ptr=malloc(size); p->ptr[0]='\0'; for(count=0; count<number; count++) strcat(p->ptr, str); } int main(void) { struct param p; func(&p, 30); printf("%s (%d chars)", p->ptr, p->size-1); free(p->ptr); p->ptr=NULL; p->size=0; } I did this while bored in a meeting so I didn't compile or review it and I did it with half my mind on something else so don't copy and paste like a nigger without making sure you understand if it works. >>581 When you don't want it anymore, free() it, and after that do not use the memory locations that you freed. This only needs to be done for dynamic memory (which you get through malloc()). When you have a fixed number of elements in your array like there, however, you usually pass down the pointer/array instead of returning it from the called function, which is much cleaner.
>>580 Small note: my C reference states that malloc() accepts the amount of ints if I specifiy it to be an array of ints, so malloc(3) will correctly give my an array of 3 values... I think.
>>584 Never mind this one, didn't update to see >>582 yet.
>>584 >malloc() accepts the amount of ints malloc() accepts the number of bytes. An int can be any size and is generally determined by your CPU's architecture. The C spec only dictates that a short is <= int <= long <= long long, so all of them could be 32-bits and it would meet the spec. Do not make assumptions about the size of int. Char is one byte pretty much universally, though. For the sake of readability and ensuring you get the correct size in bytes for an array you should probably use: int *arr = new int[length * sizeof(int)]; This will calculate the size of the data type during compilation and then perform a simple multiplication at runtime to create the correct amount of space on the heap.
So: I written my first piece of code that I am actually proud of. Take a look at this exercise I did, from a Pajeet website: Print the following number pattern for (N=x=y, square) or (x, y rectangle): 4444444 4333334 4322234 4321234 4322234 4333334 4444444 And so on. I knew for a fact and from a little experience that Pajeets and Bugmen have awful coding skills, but today I experienced it first-hand. First: take a guess how the "solution" looked like (Don't look it up, that's cheating) and second: how would you approach this? I actually found a super elegant solution, I'll share it tomorrow. Yes it is a trivial problem and truly a beginner level exercise, but I was still surprised how well it worked.
>>602 I have a solution for squares, but how should a rectangle look?
>>604 and how should even squares (4x4, 6x6, etc.) look?
>>605 ehh fuck it here's my solution in c, its in "functional style". It made sense when it was just odd squares but making it work with even rectangles really made it confusing. There is probably a dumber solution that is better (maybe just some clever string manipulation). #include <stdio.h> #include <stdlib.h> #define MAX(s, t) ((s) > (t) ? (s) : (t)) int main(int argc, char *argv[]) { int r, c, nr, nc, x; if (argc < 3) { fprintf(stderr, "Computers started going to shit when they made them for niggers.\n"); return 1; } nr = atoi(argv[1]); nc = atoi(argv[2]); for (r = 0; r < nr; r++) { for (c = 0; c < nc; c++) { x = MAX(MAX(0, abs(nr - r * 2 - 1) - MAX(0, nr - nc)), MAX(0, abs(nc - c * 2 - 1) - MAX(0, nc - nr))); printf("%x", x / 2 + 1); } printf("\n"); } return 0; }
>>604 >>605 Up to you, or you leave them undefined. My solution is always x/y symmetric, so even squares and rectangle could look like this: m = 6, n = 6 333333 322223 321123 321123 322223 333333 m = 5, n = 6 333333 322223 321123 322223 333333
>>606 You have give or take the same solution as me. Now, watch and gave upon the horrors that a cruel God hath released upon mankind: /** * C program to print number pattern * https://codeforwin.org/2016/06/number-pattern-17-in-c.html * By Pankaj Prakash */ #include <stdio.h> int main() { int N, i, j; printf("Enter N: "); scanf("%d", &N); // First upper half of the pattern for(i=N; i>=1; i--) { // First inner part of upper half for(j=N; j>i; j--) { printf("%d", j); } // Second inner part of upper half for(j=1; j<=(i*2-1); j++) { printf("%d", i); } // Third inner part of upper half for(j=i+1; j<=N; j++) { printf("%d", j); } printf("\n"); } // Second lower half of the pattern for(i=1; i<N; i++) { // First inner part of lower half for(j=N; j>i; j--) { printf("%d", j); } // Second inner part of lower half for(j=1; j<=(i*2-1); j++) { printf("%d", i+1); } // Third inner part of lower half for(j=i+1; j<=N; j++) { printf("%d", j); } printf("\n"); } return 0; }
(47.31 KB 913x965 ClipboardImage.png)
For the record, this is what he does.
Nearly forgot to post my solution: int pat18(int i, int j, int m, int n) { return max2(abs((m/2.0)-i-0.5)+1,abs((n/2.0)-j-0.5)+1); } This accepts the two sizes and coordinates, and passes the value to that coordinate. The loop function is just a run-of-the-mill grid printf. int m = 7; int n = 7; int i, j; for(i = 0; i < m; i++) { for(j = 0; j < m; j++) { printf("%2i ", pat1(i,j,m,n)); } printf("\n"); } Needless to say, it satisfies me greatly to find such an elegant solution.
>>617 I'll let you take the win, its definitely easier to understand that way. I like fixed point math, but with modern CPUs floating point is usually faster.
>>634 I have to say, sometimes you may find the solution to such a problem in an instant, and as soon as I saw this one, I knew exactly what I had to do.
Holy fuck, C is kinda fucky when you want to use multi-dimensional or variable length arrays. I can handle passing the length of a generated array to a function, but things are fucked up when looking at simple subjects like matrix arithmetic. I said it before, but this and variable-timestep things must be a pain in the ass. Since I want to do those things quite a lot, is C truly the language optimal for these things? Is there a good solution for just even passing a mxn matrix to a function which can use it dynamically?
>>657 If you're expecting matrix multiplication out of the box you're not looking for a general purpose programming language. Make your own matrix module to encapsulate the operations or get a library that does it for you. C++ might be prettier for this since operator overloading will make the code cleaner, but if you're struggling already I don't recommend it.
>>658 I really didn't expect matrix multiplication out of the box, I expected better handling of multi-dimensional arrays. The fact that you need to input the rows of the multi-dim array as an argument in the matrix itself is strange - passing it as a separate argument, fine.
>>658 >If you're expecting matrix multiplication out of the box you're not looking for a general purpose programming language. The absolute state of Cniles. Basic math being included in standard libraries isn't a high bar to pass. >>657 Just use C++, there's very few cases in which pure C is a better pick.
For the time being, C was fun, but I am running into constraints here. I can do a lot and have probably the most freedom and interaction, but I am getting frustrated. >>663 To be precise, I would want a method where I input a multi-dim array (and probably the dimensions separately), like void addMatrix(double A, int ma, int na, double B, int mb, int nb, double C, int mc, int nc) or addMatrix(double A, double B, double C) but well shucks man that **A is just not allowed man - and I get why, but there is no neat solution for the passing of these things. Even passing the matrix just as a pointer and perform pointer arithmetic is a huge pain. >>665 I'll take a look, since even the K&R book does not provide a good solution beyond void A[m][n], A[][n] or (*A)[n].
>>667 Oh wow, I forgot that ** is of course a spoiler tag. That should be addMatrix(double **A, int ma, int na, double **B, int mb, int nb, double **C, int mc, int nc) or addMatrix(double **A, double **B, double **C)
>>668 And while this works, it complains about me not specifying the dimensions - which leads me to believe that just doing this is a bad practice: void addM(double *A, double *B, double *C, int m, int n) { int i,j; for(i = 0; i < m; i++) { for(j = 0; j < n; j++) { *((C + i * n) + j) = *((A + i * n) + j) + *((B + i * n) + j); } } }
>>669 I first did this: addM(A,B,C,3,3); printM(C,3,3); Which gave errors, but calling them like this works again without errors? What the fuck is happening here? addM(*A,*B,*C,3,3); printM(*C,3,3); I dereference the pointer of A in main, so I pass the value of A[0][0] to addM. Next, the function accepts this AS a dereferenced pointer, which just takes the true pointer to A[0][0]? This is needlessly complicated. I apologize for quadrupleposting and spamming the board this much, but this is really annoying.
>>670 And it gave me incorrect results irregardless. Fucking hell.
>>671 Hah, I fucked up in my printing program. It works for now. I should read some more of my code instead of complaining, I'll hold off from posting for now.
>>672 Sorry I was too late to offer any help or advice. You should consider creating a Matrix struct which has the dimensions as members. That will make a function to do operations on them much simpler, since you will only need to pass the matrix structs in. Don't forget to do a typedef to avoid having to say "struct" constantly. It will also make it clear that your functions are meant to take matrices and not just any set of ints. Definitely don't be afraid to ask for help. Sometimes it's the best way to learn.
(84.30 KB 749x844 gsl.png)
>>665 I'm not aware of any general purpose programming language containing matrix arithmetic out of the box. >Basic math being included in standard libraries isn't a high bar to pass. >Just use C++ Are you retarded or so ignorant that you've never done matrix algebra before? >>668 Learn how to structure your code, the road doesn't end exactly the moment you start grasping the syntax. Make a matrix abstraction like >>673 said, then you'll have a set of functions like matrix_mult(matrix_t *a, matrix_t *b), matrix_add(matrix_t *a, matrix_t *b), etc., or you can get a library that already does it for you like anyone else would. Look around the net for one, e.g. https://www.gnu.org/software/gsl/ (pic related).
>>674 Thanks, that helps. Any more standard C libraries that might be useful in calculus, plotting and/or data manipulation? Matrix stuff is still a little abstract for me, but things like these are really helpful. I am mainly doing all of this to get acquainted with C, and all the math since I'll be starting my Masters final project after the summer. I serves as a good practice method for myself to recap all of the info of the last 4 years. >>673 Don't worry, sometimes it's best to just keep on puzzling. Structs might be a better solution, but coming from Matlab (and a few other languages), matrix handling is really quite convoluted here.
>>677 >Matrices are convoluted in Matlab Which is funny because they are first-class objects. Every language is going to hack in advanced mathematics in a way that suits its workflow. Precise math in C and C++ has always been clunky because the language is designed around low-cost abstraction, not easy math. There's a reason most physicists used FORTRAN and mathematicians switched to Matlab (which is basically a driver around FORTRAN code, or was at its inception). These days a lot of people have gone over to Python because it has a library for basically everything and numpy has out-of-the-box support for pretty much any operation imaginable. Try structs, though. "Reviewing C" is worthless if you can only use it like you took an intro course, and it will save you a lot of headache. Although I am personally with the guy who said there's rarely a reason not to use C++. It provides better abstraction which is easier to use and it does it with almost no performance penalty. C fags like to brag about the language being lightweight but outside of some embedded environments you don't absolutely need C, and even that's going away in favor of powerful microcontrollers that can easily store a full C++ install.
>>679 I meant convoluted in C, Matlab just lets you pass anything with numbers to any function that handles numbers so that was super convenient. I am still thinking about learning Python as well - but I would also like the knowledge I have gained in the past two weeks to be useful in making games for example. I'll see how things pan out, but the library that >>674 posted has a LOT of shit, even fucking Monte Carlo integration for the three people on the planet that use it, and even Rydberg and Coulomb functions - useless for everyone, but very useful for physicists and chemists.
>>674 >I'm not aware of any general purpose programming language containing matrix arithmetic out of the box. Depends on how strict your "general purpose" definition is, does FORTRAN fit? In any case, the fact that modern CPUs have circuits designed specifically to be fast at matrix multiplications should be a hint about how important that kind of math is.
>>677 >Any more standard C libraries that might be useful in calculus, plotting and/or data manipulation? Although gsl is an established project with lots of functionality, it's not standard. C has very little in terms of standard libraries. Unfortunately I can't really recommend any libraries for your needs since I've never had to deal with tasks like those in C, but C has libraries for almost anything you could possibly need, so do a couple of searches to find alternatives and try the ones that look the best for what you want to do and your compiler kit. A simple search yielded the gsl library from my previous post, another seems to indicate there are good alternatives for plotting libraries which support lots of compilers and formats, and I'm not sure if it's something you need but there are also a good amount of options for arbitrary precision arithmetic libraries (in case you need to do precise computations with integers of several hundred or thousand of decimals). Go nuts! >>683 >but the library that >>674 posted has a LOT of shit GNU has some pretty cool projects for scientific shit. In general given the age of the language there's a ton of stuff made for it. >>684 Unfortunately I don't have a lot of experience with FORTRAN, however I don't think it would qualify as a general purpose language. >In any case, the fact that modern CPUs have circuits designed specifically to be fast at matrix multiplications should be a hint about how important that kind of math is. They do add instructions to perform some operations with multiple data in one go, but that's even more low level and difficult to manage than what you'd get with C and you're limited by the register size. It's hardly the kind of functionality we're discussing here. Also interestingly, I don't think compilers generate functions using those instructions unless you manually code the instructions yourself, but fortunately the kind of code that would need to use those instructions would usually be already encapsulated in some library so you don't need to.
>>687 Compile this with -O3 -msse2{3,4} and you will get branch-free and SSE vectorized code. or read https://gcc.gnu.org/projects/tree-ssa/vectorization.html typedef struct _M { float v[4][4]; } M; M M_sum(M *s, M *t) { M x; int r, c; for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { x.v[r][c] = s->v[r][c] + t->v[r][c]; } } return x; } M M_mul(M *s, M *t) { M x; int r, c; for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { x.v[r][c] = s->v[r][0] * t->v[0][c] + s->v[r][1] * t->v[1][c] + s->v[r][2] * t->v[2][c] + s->v[r][3] * t->v[3][c]; } } return x; }
>>687 They will generate them, but the conditions have to be perfect. Most commonly, matrix math is used for machine learning and so GPUs are increasingly being optimized. Nvidia has been selling the concept of "tensor cores" lately, which is just high-speed matrix math units. SIMD is nice but it's more about parallel integer multiplication inside of larger registers. For massive parallel floating point you're going to want a tensor core.
(94.38 KB 1024x768 1339426043398.jpg)
>read SICP >get stuck on the "Newton's Method" bit >read Calculus Made Easy >get stuck on infinitesimals >no idea how to even begin to get started on nonstandard analysis
>>697 Do you mean the concept of derivation? Or the computational method behind it?
>>697 What >>698 said; what are you trying to learn to do? Do you already know calculus? If so, why are you reading "calculus made easy" and struggling with a concept like infinitesimals? Or, in summary: we can't answer a question you haven't asked. Try asking a question.
>>699 It's not a question. It's a cautionary tale.
>>700 On the contrary, I think you just need to learn the conceptual basis of calculus.
>>697 only the first (or maybe second) chapter is math heavy. you wont really understand calculus if you don't understand logic and proof methods. You can easily be trained to do derivation of polynomials much like algebra, but still essentially blind to the logic. If you serious enough to read SICP why read "calculus made easy"? "Calculus" by Spivak is similar to SICP in how it demands a precise understanding of the underlying theories before even touching the core subject. Learning calculus the easy way is like learning programming by copying and pasting python snippets from a "recipes" book.
>>499 >>511 >>528 I am a seething turbo-autist with ADHD who can't do college because I am total shit at academia and I can't do homework or pay attention in "lectures", but I've been programming ever since I was in elementary school and I know for fact that I could do a good job if I was hired. What's the best course of action for me?
(59.65 KB 400x468 1446041466326.jpg)
>>703 Your only real option is building a solid portfolio. Either by getting some kind of job, joining an open source project, or starting your own project and actually making something of it. If you can walk in to an interview with an entire github/gitlab full of repos demonstrating solid understanding of material then you can theoretically get hired. The first job is the hardest one because you have no track record or "real" experience. After that, the first company can vouch for you to the second. Normally I'd never recommend books like "Cracking the Coding Interview", since I think companies that hire that way are asking for trouble, but you will be at a disadvantage since they are quizzing prospective hires on common Computer Science homework material. It's an attempt to verify you know the theory. This will be your biggest struggle, so either give up on these jobs entirely or pirate that book and work through it. For what it's worth, SICP also covers a lot of that stuff and it's more coding focused. The only issue is probably that it's functional and not object-oriented like most jobs are looking for. So once again, a post here comes down to "work through SICP". You basically need to be able to say which sort algorithm is best for a scenario, draw a binary search tree, and tell them the runtime complexity of some arbitrary code. There's entire classes on this material being taught, and you'll need to go toe-to-toe with diplomafags. The good news is that most of them suck at these questions and fail because they just crammed the material without understanding it.
Speaking of jobs, what does everyone's resume look like? Do you use one of those newer templates full of colors and retarded shit like star ratings for language and technology knowledge? Or do you still have something more old school with no colors and only one column? I still have the latter and I feel a bit left behind but I do not like the newer style. I'm gonna need to remodel my resume soon so any resume advice welcome. Might not be the right thread but it's moderately on topic. >>688 That's pretty cool. On closer inspection it seems gcc favors XMM instead of the x87 FPU and always uses XMM, which I didn't think it would.
>>705 I think the latex thread became the de facto resume thread, at least for a bit. Obviously everyone is really apprehensive to actually post their resume, which makes it hard to share examples. Maybe we should have a resume thread For mine, I basically eliminated the margins, stuck all the personal/contact info in a centered header at the time. I follow that with an objective (required by some HR departments) and a "skill cloud", which is basically a table (lines hidden) containing my top skills. After that, I have job experience from my top 3-4 jobs. Each of those has bullet points with descriptions of my duties. Numbers are really good, for example "optimized code which led to a 50x speed-up in common task". I was hesitant to do bullet points, but my friend in HR at [well-known corporation] insisted and now I'm used to it. I stick education and some volunteer work in as an afterthought, just to keep it there. My trick is that the template follows the format of a "one column" resume, but because I eliminated the margins I have room to play with. So I use right-justified text on the same line as other text to cram more information into a tighter space. For example, the line with my title will also have the dates I worked there on the right. This avoids wasting lines for trivial information that is immaterial to the work and lets the highlights be my skills and duties, which is what should be put forward to begin with.
>>706 Ah, I'm doing something similar to you. One column, very small margins, skill summary with bullet points, job descriptions in bullet points and specific descriptions that have numbers with a different type of bullet. Unfortunately it still looks dated and it makes it looks like a boring wall of text. I might have to remove some stuff, but I have no idea what. >I was hesitant to do bullet points, but my friend in HR at [well-known corporation] insisted and now I'm used to it. I mixed a little bit, to be fully honest. The bulk of the description for each position is in bullet points but I do have 1 or 2 lines telling what the company and job were about in general terms.
Let's say that I'm working on a library that's going to expose a C++ class, and I want to avoid leaking implementation details (private types, private member variables, private methods, etc.) on the interface header file. How is this supposed to be done? This is easy in C but it's giving me headaches in C++. Here's an example class: #include <someOtherClass1.h> #include <someOtherClass2.h> class library { public: enum class returnValues { ok, not_ok, definitely_not_ok, }; library(){} ~library(){} returnValues pub1() { return returnValues::ok; } private: enum class action { action1, action2, do_barrell_roll }; returnValues priv1(someOtherClass1 &c){} //someOtherClass1 defined in someOtherClass1.h returnValues priv2(someOtherClass2 &c, action a){} //someOtherClass2 defined in someOtherClass2.h } Here the class has an internal type (action), and uses 2 other classes defined in 2 other header files. The latter is specially annoying because it forces me to distribute more header files with my library, header files which are of no use whatsoever to whoever consumes it. Searching around I found that people recommend the PIMPL idiom to fix this issue, and while it looks like yet another workaround to the issues created by OOP, it seems like it would do the job, however this technique goes a bit too far and doesn't allow me to expose the things I do want to expose (public types like returnValues for instance)! What now? None of the examples I've found contemplate this, they always do the piss easy example of a class that has 1 method receiving and returning void. How would you approach this? I have a few ideas but none are very good.
>>721 First, it's a bad idea to use c++ as anything other than a header only library as the ABI changes from version to version and isn't standardized, so you'll need a .lib for each compiler and version you want to support, but ignoring that, PImpl does solve your problem, for you don't need to stick your entire class inside of it. Expose what you want to expose in library and forward declare the Impl class. Library doesn't need to see the definition of Impl to hold a pointer to it, only a declaration, so you can define Impl in some cpp that includes library and make use of its members. class library { public: enum class returnCodes { ok, not_ok, definitely_not_ok, }; library() {}; ~library() {}; returnCodes Foo() { return returnCodes::ok; } private: class Impl; // Defined somewhere else. Impl* _impl; }; Cppreference has a page on PImpl https://en.cppreference.com/w/cpp/language/pimpl. I recommend bookmarking the site if you haven't already as it's a very good resource on c++ and its standard library in general. It's basically one step removed from the standard document, but it at least attempts to include examples and explanations alongside its jargon.
If I want to render environments and objects other than text-based things, am I the best off with learning C++ and use openGL? I cannot find good tutorials for using C and openGL.
>>733 As far as I know it's written in C, but generally game developers (and those doing 3D graphics) tend to use C++ so I imagine most guides will cover that. It's much easier to stick things in objects that just automate tasks rather than relying on passing stuff through functions. I'd recommend learning C++ anyways. Unless you have to work without a standard library or are writing an operating system there's generally little benefit to sticking to C. That said, you should probably consider learning Vulkan instead of classic OpenGL, which is effectively deprecated. If you need any resources on C++ I can recommend a few books. I can't say I know any OpenGL (or Vulkan) resources, but I can dig through my collection of PDFs and try to find something if you need it. But I imagine it will use C++.
>>734 I see - will consider. Sure, it'd be appreciated!
>>728 >it's a bad idea to use c++ as anything other than a header only library Now that doesn't really sound believable, does it? >you'll need a .lib for each compiler and version you want to support I already took that for granted, happens with C too, though I don't know to how much of an issue there is from one version of a compiler to another. >you can define Impl in some cpp that includes library and make use of its members. I thought of doing that, but isn't having that kind of circular dependency terrible form? I mean, library would depend on impl, and impl would depend on library. The headers wouldn't depend mutually because of the forward declare but it still smells stinky. >cppreference Yeah, I use it as a reference sometimes, but man the information written there is written with such complexity. I realize there might not be another way because the language itself has gotten really complex, but that doesn't make things any easier to understand. >jargon This is something that I've wondered for some time. How much of the jargon and complex language functionalities does the average C++ programmer understand and use daily? Am I the only one that thinks the language has gotten absurdly complex? For example, would an average C++ programmer already know what >std::experimental::propagate_const<std::unique_ptr<impl>> pImpl; means? When you read what it does it's reasonable, but I had never come across propagate_const before, and this is just the first thing you see on the linked page, I find that cppreference continually pulls std jargon out the ass and I have no idea how there can always be more!
>>738 I should have specified C is definitely much better as an interface than C++. The lack of name mangling and function overloading allows for a much more stable ABI which can be compatible between different versions of the same compiler or, more specifically, different versions of the standard (a program compiled with C++11 can call c functions in a library compiled with C++20). Once you start using C++ things in the interface you've basically locked yourself in to that compiler version, and it's why you hear stories of companies sticking to C++11 while C++20 is out: they use libraries which they can't recompile. I worked at a place where we didn't switch off of C++14 because no one wanted to recompile boost. > isn't having that kind of circular dependency terrible form? It's terrible form in the sense that it isn't sanctioned OOP design, but strict adherence to a paradigm is for academics. Sometimes the pragmatic solution to a problem won't jibe with the language at hand, and you can either spend hundreds of hours re-architecting a system or just go with what works. In this case, the forward declare could be avoided if you use a void*, but then you'd need to cast it back anytime you want to use it. >>jargon >This is something that I've wondered for some time. How much of the jargon and complex language functionalities does the average C++ programmer understand and use daily? Am I the only one that thinks the language has gotten absurdly complex? For example, would an average C++ programmer already know what >>std::experimental::propagate_const<std::unique_ptr<impl>> pImpl; >means? When you read what it does it's reasonable, but I had never come across propagate_const before, and this is just the first thing you see on the linked page, I find that cppreference continually pulls std jargon out the ass and I have no idea how there can always be more! It really depends on what you mean by average. If you're writing, reading, and reviewing C++ for 8 hours a day, you start to pick up a lot of the esoteric things pertaining to what you're doing. I'd say most of my peers know what templates are and can write simple ones (maybe even a little SFINAE); know about vector, map, set, sort, pair/tuple, string, iostreams, smart pointers, lambdas, iterators, numeric_limits, and maybe filesystem; are capable of looking up most of the language they'd find out in the wild (advanced templates being the thing most would have trouble with); and know some of the surface level jargon of the standard (declare, define, undefined behavior, etc.). Beyond that, you need to have an interest in the language itself to start picking up more stuff. As for if average C++ programmers would already know >std::experimental::propagate_const<std::unique_ptr<impl>> pImpl; I'd say they could look at it and understand what it meant. Most people have probably never used anything in experimental save for filesystem when it was in there, so I'd doubt that anyone could say they've used it out in the wild, but my first intuition is that it would make the pointed to object const if its containing object was const which, from my understanding of cppreference, is the case. The fact that cppreference likes to stick new and strange things into their examples is why I like it so much. You can click on most things that come from the library right from the examples, and their usually simple enough to understand without having to look up everything new. I might be biased, but I like learning about the new and strange stuff, so I don't mind their inclusion. If you really want to get into the jargon, all the papers from the standards committee are posted online at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/ and the working draft itself is posted at https://github.com/cplusplus/draft. I mostly watch the papers for future features and the read the draft if I come across some questionable code.
>>749 >I should have specified C is definitely much better as an interface than C++. I got what you meant anyway. While the lack of name mangling in C does make things a lot easier and might be one less point of failure when linking, ultimately mixing binaries compiled with different compilers is bad idea and might not always be guaranteed to work. You'll link them for sure, but the whole thing might crash at runtime. Hell, if I remember correctly on Windows you can crash your program at runtime even if everything is compiled with the same compiler because they have different underlying runtimes for different compilation configurations. I personally had to work on a (C) project that was being compiled with quite an old GCC toolchain and I needed newer compiler switches not available in that version, but when I tried compiling the code with a newer GCC it would first fail to compile the project and when that got solved, it would randomly crash during execution and not perform predictably. Ultimately I think it's always a good idea to thread carefully around different compilers. >I worked at a place where we didn't switch off of C++14 because no one wanted to recompile boost Did the new compiler really fail at linking with the old libs? Is it really that common for newer compiler versions to make breaking changes to the mangling? And isn't boost kinda easy to compile? >I like learning about the new and strange stuff It's a bit too much for me sometimes. It's interesting stuff, but barely any of it is useful, and I feel a bit peeved that I sometimes have to dig into the language so much when I feel other languages don't require such a big effort and deep knowledge. Anyway, thanks for your answers, they're interesting. I don't get the speak with a lot of other C/C++ devs unfortunately and I lack a ground reference.
(40.31 KB 600x746 how.jpg)
I don't understand memory alignment errors in C . How can one unintentionally end up dealing with misaligned memory? Can you give me a real world example?
>>767 Pointer aliasing for example. In lots of applications, serial numbers are 4 bytes long, or 8 bytes long, or less. Using a 32 bit int or a 64 bit int is very handy to do operations against the serial number (such as comparisons), but using a buffer composed of several 8 bit integers is very useful to store them and transmit them, so what could happen is that the storage is 4 integers of 8 bits each for the aforementioned purposes, and then it's casted to an integer of 32 bits of size to do some other operation, and although this is valid according to the standard it is an unaligned access.
>>767 When you assume sizes/offsets of structs you can run into issues. On 386 Its completely valid to read a DWORD at any byte offset, which can make errors subtle. Its generally not something you run into unless you're trying to be clever. related: http://www.catb.org/esr/structure-packing/ I've had issues while working with structs and binary formatted files. here the file is manually packed, but read with assumed packing, this is a stupid example but I remember doing something similar when I was new. #include <stdio.h> typedef struct { char fugg; int benis; } spurdo; void read_spurdos(spurdo *S, int n, char *fn) { FILE *fp = fopen(fn, "r"); fread(S, sizeof(spurdo), n, fp); fclose(fp); } void write_spurdos(spurdo *S, int n, char *fn) { int i; FILE *fp = fopen(fn, "w"); for (i = 0; i < n; i++) { fwrite(&S[i].fugg, sizeof(char), 1, fp); fwrite(&S[i].benis, sizeof(int), 1, fp); } fclose(fp); } void debug_spurdos(spurdo *S, int n) { int i, j; for (i = 0; i < n; i++) { printf(":%c B", S[i].fugg); for (j = 0; j < S[i].benis && j < 40; j++, putchar('=')); printf("D\n"); } } int main() { spurdo sparde[] = { { 'O', 9 }, { 'D', 6 }, { '(', 1 } }; spurdo gondola[] = { { '?', 0 }, { '?', 0 }, { '?', 0 } }; write_spurdos(sparde, 3, "fugg"); read_spurdos(gondola, 3, "fugg"); debug_spurdos(sparde, 3); debug_spurdos(gondola, 3); return 0; }
>>770 Ebin
>>770 That's a good link and one of my favorite reads. I remember adding attribute(packed) to my first attempts at packed structs, because I didn't trust I was doing it right. Once I realized it was doing nothing and potentially introducing performance penalties, I stopped. Newbies really underestimate the performance penalty of unpacked, misaligned data. They also forget that fitting data into the size of a cache line is immensely beneficial. I've seen benchmarks which stall because you add a single extra unpacked char to a struct.
(12.11 KB 220x280 stupid australian cunt.jpg)
Whats a good resource for learning JCA/JCE and Bouncy Castle? I don't necessarily need to know the mathematics, I am just having trouble understanding the completely autistic class structure. I bought pic related without realizing it's from 2005, so I need something up-to-date. Also, why was the Java Cryptography Architecture designed by a team of severely autistic chimpanzees?
>>784 >Also, why was the Java Cryptography Architecture designed by a team of severely autistic chimpanzees? Because everything about Java was designed by a team of severely autistic chimpanzees. Java is what happens if you take C++, which is an awfully designed language, and remove the C parts, which was the justification for the awful design. You end up with an awfully designed language for no good reason.
>>836 >which is an awfully designed language, and remove the C parts Java is more comparable to C# but it eats more memory do to wanting to be faster just for the sake of claiming to be fastest. >programming languages don't have performance >only implementations do >you can't say that C is faster than Java!!!!!!!11111111111111 >performance doesn't matter, only programming time does because when I sell it, I won't be the one looking at the loading screens all day >rubs hands
(265.06 KB 997x879 eggnog.jpg)
>>838 >performance doesn't matter, only programming time does because when I sell it, I won't be the one looking at the loading screens all day
>>838 >Java is more comparable to C# C# was modelled after Java, but without the burden of backwards compatibility with ancient Java code, which is why it does a few things better. It's still mostly the same OOP Pajeet tier shit, which is intentional by design.
On the topic of C#, is it mostly constrained to Windows platforms on the field or is it also used for Linux to a good degree?
>>850 Mono allows you to compile and run C# and .NET applications (I believe) on Linux.
>>851 I know, but the question was more oriented towards if companies actually do C# development on Linux, as with it being originally a Windows framework I imagine that's the platform most of the development takes place on. I feel I should learn a higher level language but my experiences with Java haven't been great. C# looks a lot like C++ but if people only use it on Windows I don't think it's the language I should go after either. Wish C++ was more popular.
>>852 Ah damn I completely read over the last part. Microsoft is trying to push cross platform with .NET Core, and usage of it is growing in the (loonix) server space. The traditional .Net framework is still focused on Windows development. About C++ development, you shouldn't feel discouraged about learning it if you don't feel there is demand. There certainly is but its likely less than times past since the current programming world has a heavy lean to web development.
>>852 From what I have seen in job postings, C# programmers are also expected to work with various Microsoft Windows technologies. I don't remember the names of those technologies, but I did not even bother applying to those jobs, because I figure they would also make you use Windows as your work OS. I am working as a Java Pajeet, but at least they let me set up my own computer myself.
(134.91 KB 1059x778 wt.png)
Someone on another thread mentioned wt, a C++ library to create webpages. I decided to give it a try and I ended up making a very simple imageboard proof of concept to learn the ropes. It's very interesting though still a bit constrained in some regards, I really hope they continue improving it. One thing I noticed and was surprised by is that somehow this thing does not need javascript to update the DOM. I can make a post and the post is appended to the page correctly even without javascript enabled. Also because of how the library works a thread update timer would not be necessary because the server could just update your browser's page in realtime when a new post is submitted. Overall kind of exciting man. Wish I had a server to play around with for shenanigans. >>868 What's the typical setup for Java development on Linux? What programs are required and what's the typical workflow?

[Index] [Catalog] [Archive] [Top] [Reply] Posts: / UIDs: / Files:

no cookies?