>want the typical source file to be nice and tidy, few hundred lines of code or not more than 1k LOC>don't want a spaghetti mess of "everything depends on everything" or "god" classes/fileshow can i get that clean ass hierarchy so you only need like 1 or a few includes in each file and few "circular" dependencies (A includes B, B includes A)

Could anyone rate my C code and maybe tell me what's wrong?I'm reading a book (Modern C), just finished the first chapter, and not sure if I should proceed or change strategy.Coding style is probably shit, but am I missing any essential C concepts?

this goes on for the 20 entries im interested in.and in the actual parse function i iterate over the file with the indeces of the keywords i've gathered.any tips on error handling? Especially tips on Exception handling in Java would be nice.

Here I have a code which is simply meant to insert sort an array based on a single double value (.gain). Yet when I run it it starts over writing my previous insertions. I have no fucking idea whats going wrong.Note this is the only section of code where this array is written to, I made sure of that.

>>65091475Security. It's a good thing that processes aren't supposed to be able to share memory by default, and that memory is not executable by default, and so on, so that your broken program crashes instead of becoming a vulnerability an attacker can exploit.

>>65091363implement a signal handler for SIGSEGV.That way you can resume where your program would have crashed. You won't get to read/write the memory that doesn't belong to your program though (see also "virtual memory", "paging").

>>Names are overrated>>Let’s look at a function:def findAddress(userId: String): String >>What does it do? Are you sure?>>Now lets look at another:def blah(foo: UserId): Address >>Which one tells you more about its purpose >>— the one with the businessy names, or the >>one with the types?

>>65091640Daily reminder that the study that claimed that static typing had few benefits as most errors were not type errors, was based on Java 1.4 as the representative of all statically typed languages. Among other things, it did not count nullPointerException as a type error. The latter was so common that including it as a type error is sufficient to make statically typed languages win handily in that comparison.

Anon, Why making GUI for a program is exponentially harder than making the logic of the program?Making a simple program for the last 3 days, 1 days spent on the logic and the functionalities of the program, and 2 days spent on creating the GUI with FLTK

>>65091966C++ also has std::array (compile-time fixed-length) and std::list (linked list, several versions). What would you call a contiguously-allocated resizable container when those exist in the same library?

>>65091877>Have to do a GUI project for school>Forcing us to use JavaScript and ReactJS>Barely anyone knows or likes JavaScript>JavaScript does what it does best- allow any old pleb to create a library which introduces ambiguity and makes the code a complete mess>Spend a month playing "Guess what this curly bracket is for"It was the least fun shit ever and put me off the language for good. I fucking hate how lenient JS is with allowing fucking morons changing its syntax.

How to set up Emacs in windows properly?Why the home directory always pointing to executable_location/User/usename ??So for example my emacs.exe located in C:/program Files/emacs, then emacs will try to set C:/program Files/emacs/bin/User/username as the home folder, despite the folder did not exist,but in https://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html, they said that the home folder always in %appdata%

>>65092432A generational compacting GC will significantly improve performance over a non-moving memory allocator whenever you're dealing with linked lists, trees, or any pointer-heavy data structure. The nodes will all end up being allocated next to each other so that you can traverse the entire data structure with almost no cache misses, while a non-moving allocator can't do that and will give you a cache miss on almost every pointer indirection.

Nim and D have non-moving and non-generational GC's so they don't get to have those benefits though, only the overhead.

Optional GC is almost always a shit trade. Either be completely independent of GC like Rust, or build your language around it. That doesn't mean you have to be retarded and heap allocate all the things like Java, but optional GC is just plain stupidity because interacting with manual memory management means that its non-moving, which in turn typically means non-generational.

>>65092676C++ has piss-poor performance when dealing with pointer-heavy data structures though, an order of magnitude slower than C# if done naively because of the large number of cache misses.

In microbenchmarks you can cheat and improve cache locality by allocating the nodes in a pool, but this is rarely done in real-world applications, and you'll still have poor locality if the pool is large.

>>65092806If you read the rest of my post, you'll find that it's still slow in non-naive implementations.

The way to get good performance out of sepples in large projects like the unreal engines, is to write your own GC tuned to the problem. Pure manual or smart-pointer based memory management fails at that, and what nim does (refcounting and cycle collection ) will fail even more terribly.

The only reason why Nim does well in microbenchmarks is because those benchmarks specifically avoid putting pointers to other heap objects on the heap, and they run for a limited amount of time so that they terminate before Nim's GC kicks in.

>>65093102I dont mean literally just duping a 1k element list.just duping nodes or individual elements as you need them.But like the other anon says, there's plenty of use-cases for whole structure duping. It's not like we're fighting for individual bytes these days.

>>65093244today i shall remind them.>The key point here is our programmers are Googlers, they’re not researchers. They’re typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They’re not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt. – Rob Pike 1

>It must be familiar, roughly C-like. Programmers working at Google are early in their careers and are most familiar with procedural languages, particularly from the C family. The need to get programmers productive quickly in a new language means that the language cannot be too radical. – Rob Pike 2

>>65093268>They’re not capable of understanding a brilliant languageRead: We don't want to pay them 6 figures for 3 months while they try to decipher the hidden arcane magicks of Haskell

Go is easy to pick up, easy to work in, but difficult to master. That was literally it's entire point of being created. A performant language virtually anybody could just start working in without sacrifices.

>>65093391>Look ma he posted it again!Give me a single reason, in your own direct opinion, that has nothing to do with ease of use.Ease of use isn't a detrimental feature. I don't know why the hell anybody thinks it is. Go enforces a tremendous amount of good practices and type safety, borderline to the point of Rust's "If it compiles then it works" motto, without any of the retardation accompanying it.

I wish Strongtalk had taken over the world instead of being killed by Sun Microsystems.

It had Go-like interfaces in the early 90s. Unlike Go, it also had generics, or you could fall back and use it as ordinary dynamically typed Smalltalk. It managed to be extremely simple, yet also very expressive and very safe. And faster than Java ended up being.

Between this and Javascript, I hate Sun/Java's legacy so fucking much.

>>65093411>that has nothing to do with ease of use.What does that mean Pajeet?You enjoy writing 3-4x the LOC?Then let's say "no generics" and you uniornically have the same problem as C where you have to write a function with everysinglesetoftypesvs just one in most other languages.

>>65093447>Thinking LOC matters over complexity of file structureGo has lengthy files so you don't have to pay attention to line terminators. It uses semicolons the same as other languages, but it's just not in the source file because, well, why the hell would it be? That's the compilers job, not yours.Go implements interfaces in a way such that if you have significant repeat boilerplate, it should be abstracted into a general function that takes the interface type as an argument instead of using dot notation. Not a hard fix.>But I can't extends car implements feet!And you shouldn't be able to, Go isn't OOP and that kind of thinking leads to AbstractFootFactoryCarClassFactoryAbstrationFieldFactory() retardation because MUH GENERIC SYSTEMS

Still waiting on an actual argument on why the *language* is bad, and not "it doesnt have one feature I like"

>>65093461It has standard FP practices implemented into it directly. Java 8 started to implement this with anonymous lambda functions but it's too little too late.

>>65093423>>65093461Kotlin's extra features are all syntactic sugarThe difference is, the Russians had the balls to go ahead and do it instead of dicking around with bikesheds for a few more yearsRussians are great people and Russia is a great country

>>65093560>only argue in extremesI'm not.I would never use Go for something more suited to a solid OOP language.But in the exact same reverse, every time somebody wants to shit on Go they can, quite literally, only come up with two things:>ITS FOR DUMMIES SEE!?!?!?!?and>IT'S NOT OOP!!@@!!!@Don't put words in my mouth. Provide a single, solid reason that isn't a meme. You faggots never do.I like the language but I'm not married to it, I'd love to hear criticisms more substantial than you screeching "I JUST DON'T LIKE IT" with greentext and brainlet blogs bitching about how it's not exactly how it works in <favorite language>

>>65093583No, it's not. The capacity is the length of the backing array, but that doesn't mean the list allows you to index past its own length just because the capacity is there. That would be leaking implementation details.

>>65093641>BoilerplateMinimal if you're not an idiot, but a fair criticism nonetheless.>Joke of a type systemElaborate>No genericsNot an argument>InterfaceSo which is it, you want generics or don't you?>Less powerfulElaborate.

>>65093704you know, I kinda like that Go exists. it keeps the shitty pajeet "programmers" doing plumbing, and away from more interesting work which i'd like to keep for myself, or more generally, for people who actually care about their quality of work.

>>65093746>Go interfaces are polymorphismNo, they are not. At most you could argue they're inheritance but that would imply the interface actually hands something down to the implementation, which it does not. It only exists as a template of functions, their parameters, and return types.

>>65093748Strong static typing is not a bad thing and removes a ridiculous amount of runtime errors.

>>65093789>This language is bad!>Why?>Cause it's bad!>Why?>Lmao look at this brainlet!>Why's it bad?>He's so mad!!!!!

>>65093798Not really. Go uses postfix type notation, var just indicates it's a variable and not a constant, so it makes perfect sense once you stop reading it as "type name declaration". I could just have easily written sum := 0.0 and achieved the same effect.

man, i hate these dumb language wars. programming languages aren't designed for everyone. they're designed for an audience.

C++: game programmersPython: people who like building diy projectsRuby: web devsJavaScript: frontend web devsJava: all-out pajeetsGo: the simple-mindedRust: soyboys and tranniesHaskell: unemployed "intellectuals"Scheme: CS students who like mathC: great programmers

>>65093818If it's declared with := it's a variable implicitly.If it's declared with const it's a constant.If it's declared with var it's a variable.Or do you exclusively declare variables when defining them with values?

>>65093814Straight from the FAQ addressing this:>The linker in the gc toolchain creates statically-linked binaries by default. All Go binaries therefore include the Go run-time, along with the run-time type information necessary to support dynamic type checks, reflection, and even panic-time stack traces. Once you get into any actual program complexity the size increases very minimally, that first 1.6MB is basically just the go runtime being crammed into a portable executable. I'll give you that as a fair criticism for small programs, but it diminishes almost instantly.

>>65093777Go interfaces are very obviously polymorphism. You define a method that does different things when you call it at runtime on different objects. Even the creators of Go call it Polymorphism, because that's what it is.

>>65093902Yes, Go makes very prominent usage of slices and you're going to be hard pressed to actually run into anything using a standard array and not a slice. Any time you mutate an arrays size it's automatically converted into a slice type instead, because any further mutation is way way faster than doing it against an array.Arrays have to be allocated at runtime so they can't logically be a constant, constants are compile-time. You can however do things like

const ( val1 = iota val2 val3 val4)

To generate enums. You can even do iota * 5 to make it step by 5's, or whatever.

>>65093948>Even the creators of Go call it PolymorphismI have never once seen any of the creators once refer to Go as polymorphic, because it literally is not.

I was thinking about shit like ansible and chef and at the same time writing shell scripts and wondering if it made sense to forgo all that garbage and make a functional-like, strongly typed language that would transpile to gross shell shit using some defined coreutils "target"

>>65094412>C++ is a fucking mess apparentlyPeople says this but I never really understood it. It's fine. The worst complaint people have is it's too "big" which means nothing since the dumbasses aren't obligated to use whatever stuff it is they view is unnecessary to the language.

>>65095102>>write the meat of the code in an hour>>nothing worksthat's not debugging, that's you writing atrocious code.You're either going too fast, or cutting too many corners and forgetting to fix them.

>>65095124Since assignments and projects are well-defined, I always draw diagrams on paper and walk through the procedure in my head, and start up my editor only after feeling comfortable with what I have to do.This has worked very well for me in past classes, but I am having a hard time getting it right in my operating systems class, and I'm slow at debugging

>>65095102First of all, debugging will be hell unless you make your code composable: parts of your code can run without depending on details in the rest of the code. Sometimes its worth it to sacrifice design decisions in favor of composability, but composability is good in general.

Debug individual parts of the code until you are confident that it works. You can either write tests or debug interactively. Some people are opposed to testing because they're lazy but I like to think of it like I'm just recording the interactive tests I'd do to be confident that it works.

In my experience, most bugs are easy to fix but hard to find. So finding where they originate can be difficult, and this can be in a place that is not necessarily where the bug originates. If you're confident that a part of your code is correct yet its breaking, follow the logic back to previous components that might have introduce the error.

If something is seriously not working, figure out which assumptions you're making going in and out of functions and place checks around these boundaries. This is what assert is for, assert is very helpful. Printing out values is also really helpful if you're absolutely clueless where the error is. Usually GDB can point you in the right direction, and stepping through a function and observing values can quickly pinpoint where something is breaking. Also GDB can give you generally useful advice like telling you where a segfault occurs.

>>65095272I'm tired and I phrased one of these sentences badly. I meant to explain that the place and error originates is not necessarily the same place that caused the error, and tracking down that origin is often the most tricky part of debugging. It's especially bad in C.

>>65095310In my opinion, programming methodologies like OO and FP are really just ways to make it easier to incrementally write composable code. The idea is that you can build each part at a time without having to flesh out the entire picture because you probably won't get the picture right unless you're really lucky.

>>65095342It's inlined though. You could easily un-inline it without breaking the logic, just you choose not to because there's no point polluting the toplevel and seperating the logic order of the code. It's still important to have distinct portions of the code that do one thing and one thing well.

>>65095398There is no reason that "null" should necessarily exist in the first place, much less in a high level language. In fact, there is plenty of reason to believe that zero-as-a-pointer could be a valid address and in some systems it is.

>>65095464Of course, but why should only pointers/"objects" be allowed to have none values? And why should ever single pointer be allowed to be null? Why not have a separate discrimination for "possibly missing value" types? Why should that even be a difficult question?

>>65095460But if you follow the comment chain, the entire original point of this discussion was that Java 1.4 was used as a representative of all high-level statically typed programming languages in a paper that tried to find which category of errors would be caught by using a statically typed language. The paper has since been repeatedly been quoted as an argument in favor of dynamic languages.

If they tried literally anything newer the story would have been very much in favor of static typing. The same test in Kotlin would have had next to zero null-related errors.

>>65095487Why would you want to instead of having it as a prim?>>65095483They shouldn't, I'm not the anon you were responding to.>code smellopinion invalidated.Take your shitty buzzwords somewhere else

>>65095500>Java 1.4 was used as a representative of all high-level statically typed programming languages in a paper that tried to find which category of errors would be caught by using a statically typed language. The paper has since been repeatedly been quoted as an argument in favor of dynamic languages.Oh interesting. That's a pretty lame argument for dynamic languages.Now here's an interesting point; shouldn't you have more null-pointer-esque errors in a dynamically typed language, since you have absolutely no static information about the true value of any data? Contrarily, a garbage type system like Java 1.4's might actually delude the programmer into being more lenient than they would be otherwise.

I find that in a lot of typed programming languages, I end up hitting a wall where I know that I have certain information but the type system forces me to throw it away and then get it back through an unsafe check. A prototypical example is .unwrap() in Rust. Now by "breaking" the type system you are making [likely-true] assumptions about your code.If those assumptions change, you are now in danger deluding yourself into thinking a portion of your code is correct when it is not (if it compiles, it's correct, right?). In a dynamically typed language, whenever you change an assumption you know that you need to make sure your code obeys these new assumptions so you are hopefully more rigorous about fixing them.

I want to implement a maybe in c#, but googling gives a lot of different ideas of what a maybe should be like, some are used exactly like a null, what's the best description of how a maybe should work/language that implements it correctly that I can recreate?

>>65095623>>65095631but like the other anon said, null and Nothing are two different things. And without a proper Nothing, your "nothing" will just be a null, which isn't type safe. So I wouldn't bother.

>>65095592>> Rust unwrap.Right, this tends to be fairly common and can happen for a bunch of reasons. In many cases where it used to be done due to programmer laziness, it can be handled with some variant of the ? operator.

The interesting case is when this not the case and monads are not enough. You know that it'll never throw because you are maintaining some kind of invariant in your code. Personally I'd at least improve it a bit to something like .error("Invariant broken") or something similar, but long term the solution would be to formally prove the property. This should be possible eventually, since Rust is on the track to getting dependent types.

>>65095678Agda has a better Emacs mode. Agda has more liberal syntax for names and operators. Agda has typeclasses but you don't need them because of the module system. IIRC Agda handles implicit types better than Idris. Agda has a standard library filled with useful functions and data types and a fuckton of useful properties for proofs. The standard library docs are just the code, since it turns out that reading the source is absolutely essential to writing proofs in a dep language!!!

>>65095705Rust will never get dependent types. I hope it doesn't, since they totally fuck up the runtime semantics of the language. Const generics are not dependent types and if you think they are then you just have proven you don't actually know anything about dependent types.

>>65095707>Agda has a better Emacs mode.not a language feature.Nor should you be using that shit software.>liberal syntaxawful>IIRC Agda handles implicit types better than Idrisexample? Not that it matters considering Idris is an explicit lang for a reason.>. Agda has a standard library filled with useful functions and data typesso does Idris, and it's is more matureSo gz on the emacs i guess.

>>65095686Why would you want to write general purpose programs in either?Also, the more you try to make a program general purpose, the more you probably end up throwing out half of the provable properties.

>>65095719>> they totally fuck up the runtime semantics of the languageNo they don't. They can if they are there for additional expressiveness and moving computation to compile time, but if they are just there for safety you can take the special case of (not necessarily inferrable) refinement types as an example of dependent types that can be completely erased at runtime.

>>65095757>What makes you think that I don't know what totality is?I was wondering if you were the guy from a few days ago that went threw an autistic tantrum calling idris shit because you thought an append function by itself was total.