subreddit
stringclasses
11 values
text
stringlengths
246
28.5k
programming
It's not about discrimination, it's about slavery. The date it legally ended is what we were discussing. /u/whenthethingscollide doesn't like it because it proves him wrong. He thinks slavery was only recent in the US but I just showed it was only outlawed 32 years earlier in the UK, not long. Your points are completely irrelevant. Either people were discriminating or even segregating people, but those are not slavery and slavery wasn't legal which was my only point. whenthethingscollide lost so hard all he has is ad-hominem which is admission of defeat, so thanks. ​ The terms master and slave have nothing to do with racism, you are trying to make it about racism because you want to control language. But in reality there were white slaves as well.
programming
Nope, it legally ended. I already said things don't go away overnight. In fact my point was that it didn't end overnight when the UK outlawed it either. You're the naive one to assume I was stating otherwise. Were there slaves in the 1950s? No? less than 100 years ago? No? not that recent then. The fact something is illegal is not irrelevant. It's the first and important step in doing away with slavery. It's saying the Government no longer endorses the practice. Are you really this dense? There is a reason you are the down voted one.
programming
If your point is that there's still slavery today, that's fair, there is. However, that makes the change in terminology more relevant imo, not less. If your point is that slavery and the widespread segregation of black people stopped in 1865, and that because of that it doesn't matter, I don't agree with you. If you never allow yourself as a nation to move on, then it doesn't matter how long ago it was, because it's still relevant. And yes, there were white slaves, but the slavery in the US was remarkable *because* of its systematic racism. So comparing it to others is not very helpful. It's just not the same.
programming
Words can and do have different meanings. A method of overcoming the type of fears like hearing words you don't like is facing them. If someone is so damaged by the words slave and master with alternate tech definitions, I think they have bigger problems in their life to tackle. We do not need to change everything just because someone finds it offensive. If it's blatantly derogatory, sure that's reasonable. Anyone can find anything offensive. We do not model the entire world after each person's problems. We don't abolish working in offices because some people are agoraphobic. What if I grew up with abusive parents to the point I have PTSD? Should we now stop using the word Parent because I find it offensive or hurtful? That's the point, you have to draw the line somewhere. Slave and Master are not fundamentally offensive terms.
programming
You're kind of changing the subject here. But sure. We do not need to change everything just because it's offensive, you're right. However, it is common courtesy to make some effort not to be offensive, and since this is a really small change, why not? Seriously, why not? Just like we don't have to change everything, there's no need to whine about everything either. And yet the latter is happening more and more. Sometimes things change, sometimes they don't, there's no need for lines in the sand because it's something that happens organically. If nobody wants it, it doesn't happen. If a sizable group does, it happens. And a term doesn't have to be fundamentally offensive to be changed. I don't think fundamentally offensive terms even really exist in that sense, because like you said, words mean different things to different people. So wherever the line for changing a term is, it's not that.
programming
Well, it's defined as "involuntary servitude" rather than outright slavery in the constitution, hence the "nor" part of the amendment. They're not technically owned since they weren't explicitly purchased or exchanged for goods at any point prior to their incarceration and involuntary servitude, thus they aren't technically slaves in the sense that they're bought and sold, they're just worked against their will. In the colloquial sense you may very well call them slaves not unlike wage slaves and child factories in the third world or the historical pauper prisons, but in the strictest legal sense not really.
programming
It is my understanding that the following quote from the constitution shows that slavery is legal as a punishment for crime: > Section 1. Neither slavery nor involuntary servitude, except as a punishment for crime [...] Based on the placement of the comma, it would seem to me that the entire previous clause (clause?) "Neither slavery nor involuntary servitude" is affected by the other clause (clause?) "except as punishment for crime." Meaning that both slavery and involuntary servitude are legal as punishment for crime. And from the perspective of the enslaved/involuntarily-serving, I would say they're rather similar predicaments.
programming
This is interesting, because it's a question of linguistic interpretation. Like who would you say are the gentiles in this sentence: >Neither the families of Bob nor of George, who were of the gentile persuasion, had ever gone to a synagogue. Arguments can be made that it refers to George's family as the gentiles or that it refers to both. It's kind of open to interpretation. The 13th amendment, it must be said, was poorly punctuated that way. Given that white prisoners were never really bought and sold like slaves historically though prior to the amendment, I would argue the original *intent* was to make an exception for the involuntary servitude part as opposed to slavery, especially since the exception is presented as its own separate clause, but legally either argument could hold for debate. Even emphasis when read aloud would change the interpretation - putting particular emphasis on "except" changes the meaning implicitly to refer to both slavery and involuntary servitude, but reading it flatly as a run-on, it could easily be taken to mean the exception only applies to the involuntary servitude part. It's an interesting question and a technical loophole in the amendment.
programming
> That’s under “involuntary servitude” though, not slavery. Both the wikipedia page [on the 13th amendment](https://en.wikipedia.org/wiki/Thirteenth_Amendment_to_the_United_States_Constitution#Penal_labor_exemption) and the wikipedia page [on penal slavery in the US](https://en.wikipedia.org/wiki/Penal_labor_in_the_United_States) take it for granted that this reading is wrong. My understanding was that the prevailing view of prisoners' rights for a long time was that expressed by the Virginia Supreme Court in 1871, that prisoners are slaves of the state; this hardly seems to have been something they could have been happy to say if the text was clearly to be read as you say. Do you have some ruling or some other reason in mind for reading the amendment this way? Anyway what do you propose the intended legal distinction is between 'involuntary servitude' and 'slavery?'
programming
I suspect the parent's downvotes were due to the assertion that major Linux distros would refuse to build something with Clang rather than GCC, which seems to be mistaken. To use Debian as an example: there have been efforts to compile the Debian archive with Clang since 2012, one of the release goals of Debian Jessie (released in 2015) was to support Clang as a secondary compiler, and Debian maintains a page at clang.debian.net to track the Clang build status of every package. This isn't to say that Debian *won't* use GCC to build Firefox; in fact I suspect they will. But there's nothing to say that GCC's position is unassailable, or that major distros are opposed to using Clang in principle. (I also wouldn't be all that surprised if by now there exist libraries out there that *only* build with Clang rather than GCC, in the same way that 6.2% of the Debian archive only builds with GCC rather than Clang. Not sure what Debian's policy there is about packaging such libraries.)
programming
FOSS is running on stupid these days. Gnome and FDO are both running around like meth junkies trying to get everything moved over to Meson, that in turn is built on Ninja, that in turn is build on Python. That is a massive change from the largely self hosting and C based GNU tool chain. Frankly i am worried about what insanity Linux (the kernel) will get wrapped up in once Torvalds hands over the keys. He already shot down having the build system being based on Python once.
programming
>> primary compiler for your language on a platform > > GCC is not "the primary compiler". It is a primary compiler. There is no official compiler of the C language, and there is no official compiler of the C++ language. There most definitely is such a thing as the primary compiler *for a platform*. Solaris had one, Windows has one, HP-UX had one, … and so do Linux distros. In the latter case it’s usually GCC because it’s the one *free* compiler that builds the kernel. (There are reports that ICC can build it too but it’s out of the question to use that for a distro.)
programming
Clang is an overall performance win over gcc, especially with LTO and PGO. Offering the clang version of Firefox on a distro means it's faster for end users. Linux distros saying "we prefer to build everything using ONLY gcc because we've always done it that way" seems short-sighted to me. I'm not saying drop gcc, I'm saying support clang as a first-class citizen too, and let some packages build with clang by default.
programming
> FOSS is running on stupid these days. Gnome and FDO are both running around like meth junkies trying to get everything moved over to Meson, that in turn is built on Ninja, that in turn is build on Python. First of all ninja is not python, and second how DARE they use a meta-build system. Surely you don't believe that the autotool gnu garbage is the pinnacle of build systems, do you?
programming
reposting my comment from above, regarding compiling the Linux kernel with Clang: > There winds up being complicated support matrices based on target ISA, kernel configs, kernel LTS branch, and compiler version. Focused on arm64 and x86_64 at the moment. My x86_64 and arm64 clang built kernels run reliably (posting from one). > > If you or anyone are interested in tracking progress or reporting bugs, I'm trying to keep track here: https://github.com/ClangBuiltLinux/linux/issues Recent changes in the kernel make me highly suspect that ICC is incapable of compiling the upstream kernel at the moment, but I've been making a true effort to find anyone who does use ICC so they can help test patches.
programming
From an OLD version of GCC (6) to the latest version of Clang. Current GCC version is 8, and there's been a lot of optimization improvements since version 6 released 2+ years ago. Now they stated that they tried using GCC 8.2 but they had problems, and I'm sure they did because a project of this size/complexity always have problems with working with updated toolchains, as shown by how PGO is only available on Linux at the moment in Firefox builds when using Clang/LLVM. Now Mozilla devs has already stated that they want to only support Clang/LLVM going forward, citing how it makes their job easier, and I'm certain the reliance on Rust which depends on a LLVM frontend in order to compile was part of the decision. In other words, GCC (and Visual Studio) was going to be deprecated no matter what the results were, thus I doubt there were any particular effort made in making it compile under GCC 8.2, which means we don't actually know if it would have performed better or not.
programming
> Recent changes in the kernel make me highly suspect that ICC is incapable of compiling the upstream kernel at the moment, but I've been making a true effort to find anyone who does use ICC so they can help test patches. Yeah ICC is kind of a mystery compiler. I suspect Intel uses a specially prepared kernel tree or at least sticks with one target version for some time. I’ve never seen it in the wild though. It’d be surprising if they maintained GCC compat at a level that allowed them to build each rc the moment Linus pushes it.
programming
>Clang is an overall performance win over gcc, especially with LTO and PGO. GCC also has LTO and PGO, and again the comparison here was between a old version of GCC against the latest Clang/LLVM toolchain. >I'm not saying drop gcc, I'm saying support clang as a first-class citizen too, and let some packages build with clang by default. Well, unless a package explicitly requires Clang/LLVM then I see little reason to build it using that if your default compiler toolchain in your distro is GCC, which is almost always the case. Maybe that will change, but it would likely require something to motivate such a move, like if Clang/LLVM would start delivering better overall performance, which from my experience is not the case right now. Also Clang/LLVM not being able to compile the Linux kernel is a likely stumbling block for distro wide adoption.
programming
Well, Clang is not LLVM, and Rust has it's own frontend for LLVM, so I don't see why the requirement on LLVM would imply that you'd use Clang. So unless there's a specific reason like performance, I can see why you'd prefer using your system default compiler toolchain as far as possible. However, given that Mozilla is planning to no longer support any toolchain other than Clang/LLVM, there is now very good reason to adopt this toolchain for this package unless you want to carry a potential maintenance burden.
programming
\> Well, Clang is not LLVM Clang is the primary front-end to LLVM. It's the only compiler front-end that's an official subproject of LLVM. \> and Rust has it's own frontend for LLVM, so I don't see why the requirement on LLVM would imply that you'd use Clang. I'm just saying that you probably already have Clang installed if you have LLVM and Rust installed. \> So unless there's a specific reason like performance, I can see why you'd prefer using your system default compiler toolchain as far as possible. Clang wins in performance, compilation speed, error messages, static analysis, and extensibility, just to name a few. \> However, given that Mozilla is planning to no longer support any toolchain other than Clang/LLVM, there is now very good reason to adopt this toolchain for this package unless you want to carry a potential maintenance burden. Exactly! I'm just saying that it's not like Mozilla switched to some obscure compiler that no distro has. They switched to a compiler that's widely used and already well-supported on every distro. Supporting it doesn't seem like it should be a big deal. ​
programming
>I'm just saying that you probably already have Clang installed if you have LLVM and Rust installed. Typically you will only install the packages you need, you do not need Clang to make use of LLVM, but even if your assertion is true (which seems quite likely), I don't see why you'd use it for your distro packages unless they need them to build, if your default compiler toolchain is GCC. >Clang wins in performance, compilation speed, error messages, static analysis, and extensibility, just to name a few. When it comes to performance, that's certainly not my experience, granted I only benchmark on x64 (and using the latest upstream toolchains), but for all the cpu intensive stuff I routinely build and benchmark, Blender, emulators, archivers, GCC still wins in performance (~5-8%) which includes using PGO and LTO (PGO is also very slow with Clang/LLVM compared to GCC during the profiling run). That said, Clang/LLVM is undoubtably improving and getting closer to GCC in performance, I'm eager to try out the imminent Clang/LLVM 7 release. Compilation speed is better in Clang/LLVM although it's not as pronounced these days, same for error messages and static analysis (most stuff available for Clang/LLVM seem to have been ported to GCC as well). >Supporting it doesn't seem like it should be a big deal. Not sure what you mean by 'supporting' here ? Like you said, more or less all distros offer Clang/LLVM.
programming
> That's the gist of it, but remember that inlining is probably the number one most important optimization available because it opens up so many other opportunities for the compiler. FWIW, I did some experiments a while back to measure the impact of different optimization levels on one of my code bases. My memory is that `-O0` to `-O1` had the largest effect (compared to O1 to O2, or O2 to O3, and the different was fairly large), and about half of that effect went away if I also passed `-fno-inline` alongside `-O1`. (This was several years back now, to give some perspective.) On a different topic, there are some optimizations that compilers can theoretically perform if they know what a function does (or more to the point, what it *doesn't*) even if it's not explicitly inlined. As an example, consider the following (dumb) code: int plus_one(int x); int twice_plus_two(int x) { return plus_one(x) + plus_one(x); } The generated code for `twice_plus_two` [makes two calls](https://godbolt.org/z/rjS-ax) to `plus_one`, as you may expect. With GCC and Clang, it's possible to annotate the declaration of `plus_one` as such: int plus_one(int x) __attribute__((const)); The `const` attribute tells the compiler that the function's behavior depends only on the argument, and there's no side effects. So it knows that the two calls of `plus_one(x)` will both return the same thing, and [it doesn't need to call it twice](https://godbolt.org/z/NIJleR): twice_plus_two(int): sub rsp, 8 call plus_one(int) ; eax := plus_one(x) add rsp, 8 add eax, eax ; eax := eax + eax; ret ; return eax Now, what happens if we have the body of the function available? int plus_one(int x) { return x + 1; } With that, then `twice_plus_two` [just inlines the calls](https://godbolt.org/z/VKeoN3) and we don't get something that's interesting for this discussion. However, what happens if we can prevent that? int plus_one(int x) __attribute__((noinline)); int plus_one(int x) { return x + 1; } Now the compiler can't inline the call inside `twice_plus_two`, but the compiler still figures out that it's `const` and only makes one call to it. Actually it [does even better](https://godbolt.org/z/ruTrWD): twice_plus_two(int): call plus_one(int) add eax, eax ret The extra stuff it can get rid of I think is because it knows the size of `plus_one`'s stack frame and knows that both frames can fit into x64's redzone; with `-m32` as well, the two versions are just one instruction different. Obviously this is stupid example and I'm forcing no inlining by hand, but there are cases where the compiler would refuse to inline a function for one reason or another and yet still benefit from reasoning based on knowing what it does.
programming
nope - even if you call for instance `gcc foo.c bar.c`, things in bar.c won't be inlined in foo.c: $ echo 'int bar(); int foo() { return bar() + 1; }' > foo.c $ echo 'int bar() { return 0; }' > bar.c $ gcc -O3 -shared foo.c bar.c gets you the following generated code: 0000000000001110 <foo>: 1110: 48 83 ec 08 sub $0x8,%rsp 1114: 31 c0 xor %eax,%eax 1116: e8 15 ff ff ff callq 1030 <bar@plt> // the function call to bar 111b: 48 83 c4 08 add $0x8,%rsp 111f: 83 c0 01 add $0x1,%eax 1122: c3 retq 1123: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 112a: 00 00 00 112d: 0f 1f 00 nopl (%rax) 0000000000001130 <bar>: 1130: 31 c0 xor %eax,%eax 1132: c3 retq now if we throw in -flto... `int foo() { return bar()+1; }` becomes a simple `return 1;` : 0000000000001100 <foo>: 1100: b8 01 00 00 00 mov $0x1,%eax 1105: c3 retq
programming
C++ works on .cpp files with no knowledge of other .cpp files. This is because in the 80's a typical computer didn't have enough RAM to look at a CPP program as a whole - this is the reason .h files exist. A whole bunch of modern parser performance (compilation time) optimizations depend on this property today, so the behavior is retained. In C/C++, a single .cpp file (and any .h) *is* the current set of files being compiled - it constitutes an entire program (that is missing imports). The linker is responsible for taking all the resulting .o files and creating the final ELF/PE. The fact that you can pass multiple .cpp files to the compiler is merely a convenience - you could make multiple individual calls to the compiler, the only difference would be more lines in your build script. WPO/LTO is typically implemented by having the compiler emit some form of [IR](https://en.wikipedia.org/wiki/Intermediate_representation) to disk, instead of a .o - or IR in addition to the .o. This gives the linker more information than just machine code and allows it to optimize across program boundaries. It doesn't seem right if you're used to other programming languages because you can't compile modern languages without having every file as an AST in memory at once.
programming
Yes, very much. As explained in the other replies, the `__attribute__` applies to the function type itself. It's also a separate meaning of const: > Many functions do not examine any values except their arguments, and have no effects except to return a value. Calls to such functions lend themselves to optimization such as common subexpression elimination [which is what my example demos]. The `const` attribute imposes greater restrictions on a function’s definition than the similar `pure` attribute below because it prohibits the function from reading global variables. https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes A `const` qualification on a variable's type means that variable cannot be changed, but nothing about the function's behavior other than how it interacts with that variable. Even `int plus_one(int x) const` if it were a C++ member function doesn't correspond -- that is just applying C++ `const` to the target of `this`. `__attribute__((const))` here has an entirely different meaning that... IMO doesn't really make much sense namewise, but what can you do.
programming
> `int foo() const` > > can still access data from outside the function, it just can't change it. Even that is too strong. The only time I know `int foo() const` to be legal in a C-family language is as a member function in C++: class C { int foo() const; }; In that context, the only thing that the `const` means is that the function cannot change member variables of the given `C` instance; basically, the type of `this` is `C const *` as opposed to `C*`. However, `foo()` is still allowed to read *and modify* global variables, if there was a non-`const` pointer parameter it would be allowed to modify the target of that pointer (ditto C++ reference), it can even still modify `mutable` values of `this`, it can even potentially `const_cast` the constness of `this` away and modify contents (though in that case you're starting to toe the line of undefined behavior). None of this is legal in an `__attribute__((const))` function.
programming
> C++ works on .cpp files with no knowledge of other .cpp files. This is because in the 80's a typical computer didn't have enough RAM to look at a CPP program as a whole - this is the reason .h files exist. A whole bunch of modern parser performance (compilation time) optimizations depend on this property today, so the behavior is retained. In C/C++, a single .cpp file (and any .h) is the current set of files being compiled - it constitutes an entire program (that is missing imports). The linker is responsible for taking all the resulting .o files and creating the final ELF/PE. The fact that you can pass multiple .cpp files to the compiler is merely a convenience - you could make multiple individual calls to the compiler, the only difference would be more lines in your build script. So I just have to #include all my code into one *.cpp file, got it!
programming
Interesting explanation, and reminding me of getting to grips with Z80 and 6502 assembler as a wee teen. A related question: When you speak of the compiler and the lengths it goes to in its quest for the perfect optimisation, is that really in effect internally just a whole bunch of if()'s and switches for all those attributes and flags and the infinite variety of code it may encounter, or is there real hard core magic going on?
programming
The most profitable optimization in LTO probably comes from being able to inline functions across code generation units; in C and C++ these are usually files (usually), in Rust they are crates (sometimes parts of a crate). But that's not the whole story. LTO is done in the linker not the compiler and that really matters because the linker has final visibility information for all symbols in the program; it knows everything that's going into the program and knows you're not going to create a library so it can internalize aggressively. [Teresa Johnson has a great example of this in her CppCon talk about ThinLTO](https://youtu.be/p9nH2vZ2mNo?t=341). LTO can also produce a smaller statically linked binary, even though the conventional wisdom is that inlining causes code bloat other optimizations that shrink code size often win out in my experience (~10% reduction for an 11 MB stripped static binary).
programming
Yeah. If your tight loop calls functions from other .so or .o files, you can expect a huge speed gain. Even if you don't hit the magic instruction combo. Bye bye call and return jumps, stack manipulation for parameters, wiping registers, etc. Constant parameters can be propagated. Bigger chance for the loop to stay in L1 due to fewer cache entries needed for code. For programs that mostly wait for I/O (disk, user input, etc), one may not notice much though. The CPU must be the bottleneck.
programming
I didn't mean it was dumb in the sense of not reflective of something that could happen, just in the sense of the specific example I had, which wasn't reduced from a real-world case or something like that. :-) You *do* have to be a little careful with the `array[0]` example though. The subscripting function is *not* suitable to be marked with the const attribute ("Note that a function that has pointer arguments and examines the data pointed to must not be declared const" from the [GCC docs](https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html)), though it could be `pure`. (Thinking about it now, I wonder if this is why `pure` denotes what it denotes -- it was very strange to me that `const` has the name it does, and it is what I think of as "pure.")
programming
Since LTO runs at link time, you generally know what will be exported (i.e. only main() in an executable, only visible/exported symbols from a library), so even "extern" functions can be mangled freely. In contrast, when compiling an amalgamated source file normally, anything with external linkage - any non-static function, and e.g. all classes outside anonymous namespaces - needs to be preserved. It can still be optimized internally, but the external interface has to stay the same in case there will be another object file included in the link with references to it. I think when a function is external, compilers also generally avoid inlining its code since it would need to keep the outlined copy around anyway.
programming
I bet it's something with a ton of branches that can be optimized out. Like: int align_size(int x) { return ...; } int compute_size_of_something(int base, bool needs_x, bool needs_y) { int size = HEADER_SIZE + align_size(base); if (needs_x) size += align_size(get_configured_x_size(base)); if (needs_y) size += align_size(get_configured_y_size(base)); return align_size(size); } void do_something() { int buffer_size = compute_size_of_something(sizeof(what), false, false); char buffer[buffer_size]; // ... } could easily translate to something like: sub rsp, 30
programming
No. From the description of `pure`: "Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. The pure attribute imposes similar but looser restrictions on a function’s defintion than the const attribute: it allows the function to read global variables." `pure` can also read the values of the target of pointer parameters but `const` cannot. (So `foo(int * p) __attribute__((const))` can't do `*p`, basically.) This was surprising to me initially, but maybe it makes a little sense if you start thinking about what you could actually mark as `pure` in each case, especially given the pointer argument thing. For example, `operator[]` in a C++ vector class can't be marked as `const` but is `pure` by GCC attribute names.
programming
Oh yeah, that's pretty easy actually, especially in loop-free code. But compilers will do a bit of unrolling even in the loop case. The primary optimizations there are constant propagation and constant folding. For example, I grabbed a popcount function from [here](https://en.wikichip.org/wiki/population_count), then modified it to add 2 in each iteration instead of just 1 in order to maybe foil some Clang heuristics that might make this easier for it. Looking at the [GCC-generated assembly](https://godbolt.org/z/m1uwoz) if we call that with constant values, GCC will unroll the loop 17 but not 18 times it seems. Look over to the generated assembly on the right, and you'll see that the smaller values just load a fixed value into `eax` which is used for the return value and then returns, no real computation is done. But 18 and 31 do stuff. [Clang constant folds completely in all of the tested cases](https://godbolt.org/z/UqcAip).
programming
> It doesn't seem right if you're used to other programming languages because you can't compile modern languages without having every file as an AST in memory at once. D has interface files (`.di`), which are like header files in C++, in case you want to compile every `.d` file separately. You can generate interface files from your sources automatically. They aren't used that much anymore, since it's easier to just work with sources. Also, I don't know if they are enough to release binary-only libraries that people can use on various environments.
programming
You can optimize and inline code from a statically linked library. You could do it from a shared library too if you have access to it during the compilation, but that would bring a lot of issues if your functions depend on some external state so I don't think it's done in practice. Usually functions you'd want inlined are in the .h file so there's no need to do that though.
programming
> why does the tech community matter more That's like polling the population about the importance of crumple zones in their sedans, then asking "why does the engineer community matter more?" when the opinions are different. The answer is that the engineer community understands things about a somewhat-complex topic that the layman might not. As an aside: if the only thing that differentiates two "communities" is subject-matter expertise, then you're not talking about different communities.
programming
I'd argue that the people upset here don't understand this at all. You poll engineers about crumple zones because they have done research to identify the effectiveness of that safety feature. But that's not what is happening here. The actual research demonstrates that URLs are *terrible* as a security indicator. Even active security professionals cannot use them properly (clear example is SSLstrip). Laypeople are even worse. Laypeople don't even understand the difference between those two URLs, so how could they make decisions based on that information? In fact, I'd wager that laypeople are a teeny bit better at using URLs to detect phishing when there isn't "https://www." in front of the URL string. This makes the domain be right at the front of the URL, which is the relevant bit for phishing anyway. This is more like having a button in your car under the dash that you can press before an impact to reduce damage but only automobile engineers know about it and they still always forget to press it anyway. The engineering community is upset because "I'll get confused when I visit one of the few websites where these resolve to different IPs" not out of some opinion that this change is bad for the general population.
programming
I don't think that's why the technical community is upset. I think the technical community is upset because Google decided to change this without community consultation, and the technical communities understand how this *will hurt* in edge cases. I agree that URLs are a terrible safety feature. But unlike crumple zones, *they're all we have*. We're not going to improve them by removing relevant information! We're certainly not improving them by removing information which is potentially the *only chance* a user has at realizing they are being phished. (I'm talking about user-controlled sub-domains here). If you want to reduce noise (a noble and *great* goal), do something like Firefox does: Put the protocol and subdomains in a grey colour, and crank the contrast on the domain so it pops. Firefox also greys the path. This way, users can super easily tell what the domain is, and whether they're being phished (doesn't help against user-controlled subdomains, but at least the information is still there).
programming
What consultation would you have wanted? Google says "Hey we are planning on doing this, WDYT? BTW here is a lit review of all the papers that show how shit people are at using URLs for anything meaningful?" When you make a product for 1b people it becomes impossible to consider edge cases. Yes, some people in the tech community will get annoyed. It will cause some dev some pain when he forgets that the www is hidden and is confused when his tests aren't working. But the outrage I have seen has largely been people claiming that this will hurt ordinary people. I have seen zero evidence of this. In fact, the literature that I have seen seems to suggest the opposite.
programming
I am absolutely 100% confident that if you polled users about the difference between "http://foo.com" and "https://foo.com" the overwhelming majority would say "there is no difference". The "https" is literally just noise for people. Why does the tech community matter more? I am absolutely 100% confident that if you polled users about the difference between an "artery" and a "vein" the overwhelming majority would say "there is no difference". The difference is literally just noise for people. Why do doctors matter more? I am absolutely 100% confident that if you polled users about the difference between "tension" and "compression" the overwhelming majority would say "there is no difference". The difference is literally just noise for people. Why do structural engineers matter more?
programming
"hey folks, we're thinking of doing this for reasons x, y and z. We're aware of issues a, b and c. Please comment if you're aware of other issues, or if you of examples where the impacts of these issues are greater than we're aware of." I am aware that Google's use case is different from most simple due to their size. However, they were wrong on eliding the "m" domain, and they could have avoided this hotfix if they *just talked to the community first*. People being upset that they didn't *isn't unreasonable*.
programming
I don't understand this. Ultimately the URL bar is not being used by experts. If people were making a product for doctors and did not distinguish between arteries and veins that would be bad. But if people were making a children's game and did not distinguish between arteries and veins that would not be bad. I'd understand this much more if the change was happening to a system that was primarily used by web developers and admins. But it isn't. It is happening to a system that is primarily used by people who have no use for the difference between these two URLs. Error messages for JS code executed in my browser is not displayed by default. I need to click some buttons to open the dev console. This information is useful for web devs. It is useless for 99.99% of users. Therefore, it is hidden. How is this any different?
programming
It isn't trustless in reality though. Bitcoin needs nobody to own 50%+1 which actually has been violated and everyone basically said "OK we're going to trust the guy who's running more than half the end points as the alternative is my Bitcoin is worthless". Also Ether got forked because of a chain of dodgy transactions and everyone decided to just trust that the fork was at the correct point. Other than the people who didn't trust it and maintained the old blockchain as classic. Crypto is absolutely riddled with trust in practice.
programming
It's an emerging technology that also happens to be incredibly complex. It's not going to be perfect on the first try, and people are going to make mistakes. The important part is the idea behind it and the problems it's trying to solve. When I hear people lay down that narrative, along with stuff like "oh well clearly crypto is unsafe, look at all the crypto that was stolen in all those hacks!", usually ending up boiling it down to "it's a dumb technology that's fundamentally flawed and anyone who advocates for it is an idiot", when I hear that, I just think that people are fundamentally misunderstanding the problem. Yes, those are obviously huge issues. But they aren't issues in the overall technology (if you can call it that), they're just issues in implementation. All those exchanges that got hacked? That's not a problem with bitcoin or ether or any other crypto, that's an issue with how those companies handled security, and it's an issue of not having a mature platform where people can actually store their crypto securely. Most people keep their crypto on exchange-hosted wallets instead of cold-storage, which is an inherently much less secure practice. But there's a simple reason for that. It's way more convenient. Once we have secure and convenient ways to store it, that will no longer be a concern. (Or at least a much smaller one). Another thing people like to argue is "it has no inherent value". You can tell your electricity provider that all that power you used to mine crypto "has no inherent value", but I doubt that'll work out too well. The "value" it's given is based on the cost of mining. And mining is basically just another way of saying "running the system". Now one problem that exists in most cryptocurrencies today is that mining uses way too much power and there are more efficient ways to do it. But again, it's an emerging technology. People will keep figuring out better and better ways of doing it, and it'll become more and more efficient. One of the problems, I think, is that people think of it the same way as "money". But it's a totally different animal. The way I think of it is, money is like math, where crypto is like programming. Math is great and fundamental to so many things, and you can do a lot of great things with it. But then programming *uses* math, or maybe I should say math is an important component of programming. But it can also do soooo many things that math can't. Or at the very least makes it immensely easier. I don't know why I felt the need to write all that out, I guess I just followed the thread of where my thoughts were going. But if nothing else I hope I gave you a bit of a different perspective on the matter. And just a side note, "riddled with" means there's an abundance of something. I'm guessing that's not what you meant ;)
programming
This is nothing to do with exchanges getting hacked. This is to do with the fact in the real world the ultimate condition in which the "trustless" quality of Bitcoin falls to pieces has actually happened. That is an issue with Bitcoin. In the end everyone has assumed nothing bad happened during that incident but it is proof positive that kind of end of days failure condition is achievable in the real world.
programming
23 guidelines is way way way too many. Here is the simplified guidelines: 1. **Keep it simple**. Functions do only one thing. 2. **Names are important**. So plan on spending a lot of time on naming things. 3. **Comment sparingly**. It is better to not comment than to have an incorrect comment 4. **Avoid hidden state whenever, wherever possible**. Not doing this will make rule #7 almost impossible and will lead to increased technical debit. 5. **Code review**. This is more about explaining your thoughts and being consistent amongst developers than finding all the bugs in a your code/system. 6. **Avoid using frameworks**. Adapting frameworks to your problem almost always introduces unneeded complexity further down the software lifecycle. You maybe saving code/time now but not so much later in the life cycle. Better to use libraries that address a problem domain. 7. **Be the maintainer of the code**. How well does the code handle changes to business rules, etc. 8. **Be aware of technical debit**. Shiny new things today often are rusted, leaky things tomorrow. ​
programming
Totally agree on number 3. I've far more often seen incorrect comments than seen a piece of code and wished for a comment. Write simple code. If you really need a comment to explain what you're doing, maybe think about why that is and simplify your code. If you absolutely need to add a comment go for it but now this comment has to be maintained alongside the (probably overly complicated) code.
programming
> Most comments found in code are low-level documentation, made redundant by the code itself---if the code was written to be readable in the first place. Wrong. Comments in the code explain the decision process - why exactly you're doing it, what were the prerequisites, what implicit constraints, and so on. They also include the account of your experiments that lead to the decisions made, they include profiling data, mathematics before it got mutilated beyond recognition by the optimisations in your code, with all the intermediate steps. They may include copy-pasted paragraphs of the specification documents you're implementing, so you know exactly what the code was supposed to do, what version of the spec it's taken from, and so on. Just having a pdf file somewhere attached to a wiki page does not help at all and is guaranteed to get stale in no time.
programming
Yeah, it's one of the signs of a developer fresh out of university. A good rule of thumb is to have a function short enough that it all fits on the screen at once, and then include a comment above the function describing what it does (if the function name is not obviously clear; no need to document a simple getter) what it's inputs are, what its outputs are, the side effects, if there's any exceptions to be aware of and any other gotchas you might not expect. Documentation systems like javadoc/phpdoc/jsdoc make it easy to include the right information. The only reason to document an individual line is if it's doing something clever or weird that's not obvious from looking at it. Mostly as a warning to the next person that comes along and thinks "That's weird; we should change it". Some types of comments belong in the commit logs and not the source code. Particularly "why" comments.
programming
Method names explain the what. Your code explains the how. It's usage explains the why. None of this necessitates comments. Your code is not to be read by non-programmers, you don't need to explain every little thing. I can see the need for some comments but "more comments than code" sounds like utter lunacy. Your code would become unreadable just based on how spread out it is between comments. And then someone needs to update your essay of comments for a minimal code change. But bad comments don't cause compiler errors/crash the app so they are significantly harder to catch than bad code and now your essay is distracting, and incorrect.
programming
> It's usage explains the why. No. Never. Unless you code some CRUD crap, the "why" part of the story is the most complicated one. It might involve explaining the mathematics *before* it became code - with all the intermediate steps. It might involve referring to a number of papers. It might involve citing specification paragraphs you're implementing. Also, there are always some implicit constraints that you cannot infer from the code, and yet you assume them when you write it - you must document them explicitly. > but "more comments than code" sounds like utter lunacy. Sure, go and tell Donald Knuth he's a lunatic, and you know better because you can code hipstor webapps. > Your code would become unreadable just based on how spread out it is between comments. If code is only a small part of the story - yes, it must be thinly spread inside the comments, where its contribution to the story makes sense. What is more readable? TeX, or anything you ever wrote? Can you ever achieve the same quality? Are you willing to write cheques to anyone who discover a bug in your code?
programming
It depends on people who are reading the code. If they're not used to using CVS, yeah - nobody will look at commit messages. In your case, if people don't update comments, they will soon get out of date and misleading. >Also, you must have more lines of such comments than the lines of code - seems a bit too heavy for the commit messages. Didn't really get the meaning of that. Usually, I commit in atomic manner and trying to do it quite frequently. This way you have all the changes (sometimes spanning multiple files) with a message in one commit. I find it really useful and this approach helped me and the others to find reasons for decisions made in the past.
programming
> In your case, if people don't update comments, they will soon get out of date and misleading. And comments are much more likely to get updated than any out-of-source documentation - because they're visible in a diff, so anyone reviewing your code change will notice it. > This way you have all the changes (sometimes spanning multiple files) with a message in one commit. This way you're having a mess, instead of a consistent *story*. And comments must tell a story, something you can read sequentially. You still need commit messages, of course, and they must duplicate some parts of your story, but still, the story must be told.
programming
>It might involve referring to a number of papers. It might involve citing specification paragraphs you're implementing That's a single comment. I never said all comments must go, this is an obvious case where a comment is useful. >Sure, go and tell Donald Knuth he's a lunatic, and you know better because you can code hipstor webapps. Lot of assumptions here, plus a strange idolisation of Knuth. The man is not infallible and programming has come a long way since Knuth (also, can you point to where he actually said that comments should outnumber lines of code?). >What is more readable? TeX, or anything you ever wrote? Can you ever achieve the same quality? Are you willing to write cheques to anyone who discover a bug in your code? Again, you have a bizarre idolisation of this guy and I fail to see how writing lots of comments equates to bug-free code.
programming
> That's a single comment. And all such comments are likely to be bigger than your actual code (unless you're writing some really inefficient verbose code). > The man is not infallible and programming has come a long way since Knuth Mind naming a single code base with the same level of quality as TeX and Metafont? > also, can you point to where he actually said that comments should outnumber lines of code? That's a consequence of using Literate Programming properly. And if it's not always true for the code Knuth wrote himself, keep in mind that this code is in very low level languages (Pascal and C), so the ratio definitely should get biased towards comments for the less verbose higher level languages. > and I fail to see how writing lots of comments equates to bug-free code So, you cannot show me a bug-free code without literate comments? As expected. So, until you find an example of the opposite, we have to assume that Literate Programming was a major contributing factor to producing a bug free code.
programming
Just remember the golden rule of comments: "Explaining **WHY** something was done is a million times more useful than **HOW** it was done." The *how* is contained within the code if you look hard enough, the *why* is lost forever if it isn't written down. e.g. // We loop over the employees for(var n = employee.Count; n > 0; n--) { ... } Vs. // Inverted because list comes down in reverse-alphabetical from employees view for(var n = employee.Count; n > 0; n--) { ... } One of these is useful insight, the other is obvious.
programming
> And all such comments are likely to be bigger than your actual code (unless you're writing some really inefficient verbose code). A link to a paper or a spec is bigger than your code? Right. > Mind naming a single code base with the same level of quality as TeX and Metafont? No, because your bizarre infatuation with the work of one man is completely irrelevant. > So, you cannot show me a bug-free code without literate comments? That is not even remotely related to what I said. You have presented this false equivalency of "more comments = fewer bugs" with nothing more to back it up than "I love Knuth". Tex by the way, despite your obsession is [not magically bug free](https://github.com/latex3/latex2e/issues) because of the amount of comments. I'm done here, if you have nothing more to add than fanboying over Knuth and assuming that anyone who disagrees with you is a web-dev and somehow beneath you then you are obviously beyond help.
programming
> No, because your bizarre infatuation with the work of one man is completely irrelevant. TeX and Metafont are both large code bases that are bug-free. You must be totally fucking retarded to dismiss this fact. > is not magically bug free Just fuck off already you retard. If you see no difference between LaTeX - a huge collection of macros on top of TeX, and TeX itself - you're not worthy of any civilised discussion. Also, only such a retarded piece of shit like you are would have ignored all the arguments I carefully listed and reduced everything to "Knuth is great".
programming
> you're not worthy of any civilised discussion. And you're obviously not capable of it. Literally took you two messages to resort to insults because you just can't deal with opposing views. And when you can't get your point across? > You must be totally fucking retarded > Just fuck off already you retard. > Also, only such a retarded piece of shit like you. Well done on your "civilised discussion".
programming
> because you just can't deal with opposing views. No, because I do not want to talk to a brainless demagogue scum. I do not want to waste my time on a shit like you. > And when you can't get your point across? Of course it's impossible to get your point across when you're talking to a retarded demagogue who ignores all the arguments. This is when the only course of action is to say "fuck you". > Well done on your "civilised discussion". You little piece of shit excluded yourself from a civilised discussion the moment you started to ignore and twist the arguments. Do not expect to be treated as a human being when you do such things.
programming
Having a background in didactics/teaching, I understand the rationale behind making you put a lot of comments explaining your intentions in code assignments. It lets the teacher better understand the thought process behind what you did, (partially) prevents you from just copy-pasting code you don't understand and saying it works without knowing why, and forces you to think about your code as you have to explain and justify what you did. However, to be effective as a teaching tool, it should be made clear that it's not something required (or desirable) in a real-life situation.
programming
I feel like this is too broad a statement. In a super complex codebase, you want to be able to get a general gist of what is happening in the code. The examples here of opening files and looping are one thing, but when you're dealing with a text processor it's kind of important that you explain what some things are doing. A comment like this is immensely helpful, but it doesn't explain why at all. The "why" is implied by the context of the code. // Get the amount of glyph advance for the next character end_bytes = Types::UTF8::NextUnsafe( c, 0, glyphVal );
programming
When I was starting out in uni, we would often write out the functionality in comments first, then implement that. That way I'd end up with a lot of comments. At the time, the 'what' was actually not obvious to me, so it was still useful. Nowadays, the majority of the comments come from GhostDoc that generates it based on the names of the methods to appease the style cop. Only in the rare cases where something is not obvious through naming do I still write comments. This is usually determined by having to debug through said code and not finding it obvious at that time. During development it is all very clear of course what I am doing :P
programming
I once inherited a C# project where virtually every operation looked like this: Console.WriteLine("About to instansiate HelperClass"); using (var writer = acquireFileWriterBySomeMeans()) { writer.WriteLine("About to instansiate HelperCLass"); } // create an instance of HelperClass and store it in helperClass variable var helperClass = new HelperClass(); Console.WriteLine("Created instance of HelperClass"); using (var writer = acquireFileWriterBySomeMeans()) { writer.WriteLine("Created instance of HelperCLass"); } // ... The code was buried in so much noise. All of the logging was the first to get refactored: NLog in this case. Then after we understood what it was doing, we ported it over to some much less verbose scripts. I even [posted one of the snippets from the program up on /r/ProgrammingHorror](https://www.reddit.com/r/programminghorror/comments/5d657p/im_so_sorry_this_is_so_long_but_the_more_you/).
programming
Your specific example could probably be solved by using a small function with a good name, but I agree with the general principle. Sometimes the what can be really hard to understand. The readability of PostgreSQL's code base for example is helped by comments like below. if (write(fd, shared->page_buffer[slotno], BLCKSZ) != BLCKSZ) { pgstat_report_wait_end(); /* if write didn't set errno, assume problem is no disk space */ if (errno == 0) errno = ENOSPC;
programming
> Your specific example could probably be solved by using a small function with a good name. That's a good point and I was thinking that, but really what's the difference? If the code isn't being reused then it seems like a stylistic choice kinda. But yeah, your example is also good. I think a lot of the time when a comment is explaining "what" it's in the sake of keeping the code brief and simple.
programming
> So plan on spending a lot of time on naming things. This is a big one. You feel stupid sometimes spending a long time just trying to name a variable or function, but often that time spent is worth it when you come back to the code much later. Having said that, sometimes if something is hard to name, it's because you're either doing something too complicated in too few steps, or because you don't really understand it right. > It is better to not comment than to have an incorrect comment Also, never comment if what the comment is saying is obvious to someone reading the code. Like "loop over the entries in the list" or something stupid like that. A comment should be for documenting the thoughts of the person writing something, like "note: this list is sorted here because we need to do X later on".
programming
> time savers They potentially open your code up to security holes, they bloat your code and now you have to keep on top of the version numbers or resolve compatibility issues if 2 dependencies use the same dependency. It saves time right now.. yes, but in the grand scheme of things, no. I speak from experience with Java, but look at the mess that Node is in right now because of going completely bonkers with dependencies. The leftpad debacle was hilarious... the advice should be to use dependencies sparingly.
programming
There are real exceptions to this, e.g. Quake's `Q_rsqrt`: float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &y; // evil floating point bit level hacking i = 0x5f3759df - ( i >> 1 ); // what the fuck? y = * ( float * ) &i; y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed return y; } Anything that relies on theoretically-derived results needs to have the 'how' explained.
programming
I have to agree on #6. My pet peeve are test frameworks which are huge black boxes that call your code and prevent meaningful debugging without providing almost any tools for the most time consuming part of testing: designing and writing test cases. In comparison, I’ve recently had to implement some USB stuff on an embedded platform at work. The entire USB stack is just four moderate size C files (and one for the register level hw interface). It’s refreshing to see things done sanely for a change.
programming
Is this kind of code still used today? Or does the compiler automatically do these optimizations? Also I think here is the modern / more accurate way to do it today by-hand if anyone was curious. From [here](http://rrrola.wz.cz/inv_sqrt.html) float inv_sqrt(float x) { union { float f; uint32 u; } y = {x}; y.u = 0x5F1FFFF9ul - (y.u >> 1); return 0.703952253f * y.f * (2.38924456f - x * y.f * y.f); }
programming
No, on x86 we use the `rsqrt` instruction. On platforms without hardware support, we'd probably make do with a `sqrt` + `div`, or if necessary a more legible application of Newton's method. There aren't very many applications I can think of in modern computing where you'd need a fast but inexact inverse square root on very slow hardware. And even if you were writing out Newton's method by hand, there's no way a compiler could 'optimize' to this code—it would both have to figure out you were trying to perform an inverse square root and then decide to replace it with an approximation. Conceivably, your language's standard library could include it, but that would be surprising, to say the least.
programming
I used to almost *never* comment my code. Then, I read the SQLite and Reddis codebases, both of which were pretty heavily commented. I found the comments added a ton of value. I currently work in a fairly large JS codebase. The lack of types + lack of comments makes it super hard to figure out what's going on and why. There's a lot of inconsistent abstraction. Even simple, file-level comments would be nice. Honestly, my opinion on comments has flipped. I now comment quite a bit.
programming
the difference is that your very simple function is now trivial to understand because its name explains what the cryptic one-liner is doing. When you'll encounter this function in the wild, in the middle of a big class, you'll be glad to understand what it does in a glimpse instead of googling what `Types::UTF8::NextUnsafe( c, 0, glyphVal );` does and probably lose 10 minutes for something of no interest. It helps on onboarding new devs, it helps for you when you come back on your code in 6 months, it helps your coworker who will have to touch this class next week for the first time, it help newbies who don't know jack about UTF8 encoding... Overall you gain in productivity for the whole team.
programming
well, for starter if this code used meaningful variable names, it wouldn't need most of its comments. Look at how easier it is to understand the mergesort function than the merge one, only because the most complicated parts are moved to a merge function. I've done this really fast, and there's probably big mistakes in it, but simple renaming variables, extracting bits of code into functions is making a BIG change. Each function in itself is pretty easy to understand. And the only comment left explains WHY it's done this way. void merge(int array[], int start, int middle, int end) { int i, j, k; int first_half_index = middle - start + 1; int second_half_index = end - middle; first_half_array = make_half_array(array, start, first_half_index) second_half_array = make_half_array(array, middle, second_half_index) array = merge_back(array, start, first_half_array, second_half_array) } void mergeSort(int array[], int start, int end) { if (start < end) { // Same as (start+end)/2, but avoids overflow for large start and middle int middle = start + (end - start)/2; mergeSort(array, start, middle); mergeSort(array, middle + 1, end); merge(array, start, middle, end); } } make_half_array(array, start, end) { i = 0; temp_array= []; for (i = 0; i < end; i++) temp_array[i] = array[start + i]; return temp_array; } merge_back(array, start, first_half_array, second_half_array) { i = 0; j = 0; k = start; while (i < first_half_index && j < second_half_index) { if (first_half_array[i] <= second_half_array[j]) { array[k] = first_half_array[i]; i++; } else { array[k] = second_half_array[j]; j++; } k++; } array = copy_remaining_elements(array, k, first_half_index, i) array = copy_remaining_elements(array, k, second_half_index, i) return array; } copy_remaining_elements(array, k, first_half_index, i) { while (i < first_half_index) { array[k] = first_half_array[i]; i++; k++; } }
programming
A disadvantage is that it's possible, over time, for the code and the comment to become disconnected. Here's a contrived example: // Get the amount of glyph advance for the next character end_bytes = Types::UTF8::NextUnsafe( c, 0, glyphVal ); Commit Message: Quick fix for an issue where invalid glyph values were causing problems. // Get the amount of glyph advance for the next character if(isValidGlyphVal(glyphVal)) { end_bytes = Types::UTF8::NextUnsafe( c, 0, glyphVal ); } else { log("Invalid glyph value"); end_bytes = 0; } Commit Message: Support the ability to offset glyphs by a constant factor. // Get the amount of glyph advance for the next character glyphVal += OffsetVal; if(validGlyphVal(glyphVal)) { end_bytes = Types::UTF8::NextUnsafe( c, 0, glyphVal ); } else { log("Invalid glyph value"); end_bytes = 0; } Commit Message: Generalize glyph offset calculations. // Get the amount of glyph advance for the next character glyphVal = applyOffset(glyphVal, [](auto x) { return x + OffsetVal; }); if(validGlyphVal(glyphVal)) { end_bytes = Types::UTF8::NextUnsafe( c, 0, glyphVal ); } else { log("Invalid glyph value"); end_bytes = 0; }
programming
> Get the amount of glyph advance for the next character Idk what in the hell you're trying to say here, but the code looks like you're trying to get the next codepoint? glyphs != codepoints. 🇺🇸 is one "glyph" (grapheme in Unicode parlance), except in reality it's 2 codepoints. `U+1F1FA` and `U+1F1F8` which in UTF-8 are encoded as 2 sets of 4 "code units" aka bytes. in UTF-16 it's encoded as 2 sets of surrogate pair encoded "code units" aka "short" (tho I really hate that term)
programming
LOL. Again - a separate document is much more likely to get stale, when your implementation starts to drift from the ideas explained in the paper. In the literate code you won't be able to review a code change without noticing that there is a comment nearby that is obsoleted by the change. Take a look at Axiom (although you're unlikely to have a mental capacity to dig into this kind of a code base).
programming
I did read all of the comments and it looks like you were on the losing side of the argument and then you turned into a huge asshole and started personally insulting the guy because he didn’t agree with you. Come to think of it, I’m currently talking with you in *another* thread about literal programming. It’s cool that you like it but it’s not cool to turn into a dick like you did to this guy just because whoever you’re talking to doesn’t like it.
programming
> started personally insulting the guy because he didn’t agree with you. I do not care about disagreement. He did not disagree - he dared to dismiss the arguments and resorted to trolling. > just because whoever you’re talking to doesn’t like it There are tons of valid reasons for not liking it. But dismissing TeX as an example of a bug-free code base, because there are tons of issues in LaTeX - it's just a plain trolling. As well as dismissing all the arguments as "you simply like Knuth". The fact that TeX is bug-free is a serious argument, and it must be discussed seriously, not dismissed with this retarded false superiority that idiot demonstrated.
programming
> LOL. Again - a separate document is much more likely to get stale, when your implementation starts to drift from the ideas explained in the paper. ​ Yes, which is why a link back to the paper is likely better. As I said, IF you are trying to summarise a paper you have obviously gone way beyond the scope of a comment and it would make sense to be a separate document since any change to the code invalidates it. Even if you don't update the documentation, you can still see where the code came from. Stale comments are more confusing since the assumption is that they are reflective of the current code. ​ I can see that this is hard for you to grasp but actually reading a message before sending a dumb knee-jerk response would probably help you a lot. ​ > Take a look at Axiom (although you're unlikely to have a mental capacity to dig into this kind of a code base). ​ Is this another code base that is provably bug-free simply because of the volume of comments? Because at a glance, they are not immune to redundant comments stating the obvious, mistyped comments, or incorrect comments. Also, separate conversation but why is anyone using SVN anymore?
programming
> ​Yes, which is why a link back to the paper is likely better. It's even worse - the external document is immutable. Only if you implement it 100% faithfully, which is unlikely. Otherwise you *must* duplicate the reasoning from the paper in your comments, adapting it to your specific needs, and modifying as your code and requirements evolve. > Even if you don't update the documentation, you can still see where the code came from. By all means, link to the original paper. But keep your local elaborate explanation up to date. > Stale comments are more confusing since the assumption is that they are reflective of the current code. Stop referring to this strawman argument. Comments are not going to be stale if you follow the proper literate programming discipline - any code reviewer will immediately see that comments were not updated when a code is changed. > Is this another code base that is provably bug-free simply because of the volume of comments? No, it's just a code base that is easy to read and that makes little sense without all the literate comments. > Also, separate conversation but why is anyone using SVN anymore? Commit hooks. Small checkout size. More centralised control. That's the usual reasons in the industry. As for the open source projects - it's just inertia. Say, LLVM project was trying to move away from Subversion for years now, and still could not do it.
programming
Also a common way of programming (I originally read this in Code Complete back in the early-mid 2000s). Especially useful in languages which can be obtuse or where syntax would slow you down. Write out your logic in single-line comments in your primary spoken/written language (e.g. English). Do this, then that, start loop, end loop. It keeps you focused on what you're trying to accomplish without getting bogged down in syntax. Then convert the comments into real code. (Still useful as a technique as I enter my 3rd decade programming for a paycheck.)
programming
1.30 is in beta now, but we haven't prepared the release notes, so I don't have a full list handy. But I do know one large thing: the first chunk of procedural macros. More specifically, attribute-like procedural macros and function-like procedural macros in item position. 1.31 is master, so hasn't been finished development, so it's impossible to say everything. But the biggest thing is that it will be the initial release of Rust 2018.
programming
Editions are for backwards-incompatible changes. For example, adding async/await as keywords. ( Which is not compatible because they used to be valid identifiers. ) Any crate can declare which edition it belongs to, all rust compilers will be able to compile all editions that are older than them, crates of different editions can be linked together, and any new features that are not backwards-incompatible will be added to all editions. Or, to put it more simply: On *Edition 2018* release, the only difference between it and compiling edition 2015 with the same compiler is that you can no longer use async as an identifier. Later, async will be introduced as an actual keyword.
programming
I have many complaints about this article but I will put most of those aside and focus on one thing HTML as a data contract for API endpoints. In either example the JSON or the HTML the code breaks when the data contract is changed without the consumer realizing it. The author claims html is better because its structure can change, but fails to realize he has changed the data contract compared to json by using queryselector on attributes instead of using an object graph with a specific structure. If you change the name (the data contract) it still breaks. Not only that you lose all benefits of generating an object graph and instead do a really naive search for all this data using attribute names so you can hydrate some other data structure. Lastly this isn't an html exclusive thing all of what was done could be achieved using xml, and xsl paths. There are many other problems with this article but I chose to cover the points relevant to his core argument of using html as the data contract at API endpoints.
programming
>but fails to realize he has changed the data contract compared to json by using queryselector on attributes instead of using an object graph with a specific structure Can you elaborate on this part? >There are many other problems with this article but I chose to cover the points relevant to his core argument of using html as the data contract at API endpoints. Can you please point out the other things you believe are problems with the article? Thanks. ​
programming
by using just query selectors for attributes the data contract is no longer reliant on the object structure. Essentially its just a dictionary at this point because that is how you are accessing and treating it by doing query selectors on just attributes. It also has the downside of not utilizing any of the performance benefits you would get from actually using the tree structure it creates in memory when creating a DOM document, and only does slow lookups. Also the author implies a few things that are untrue. HTML has versioning that is breaking. You can't reliably mix html from different versions and have it render reliably. Another annoying thing is...if all you are doing is looking up elements based on attribute values and grabbing their values use xml and xsl it is more expressive and essentially a less strict version of html that will have less overhead. Overall I got the impression the author only had a shallow understanding of what he was discussing. Lastly I would ask you to just imagine any scenario more complex than the contrived ones he described and talk through what is going on. You would load an html into a document object creating a tree like graph. Instead of taking advantage of that tree like graph you access the data with dictionary like calls using only attributes and their values, that don't take advantage of the structure to speed up looking for the data. You then take that data and either directly modify or in a lot of cases hydrate another object because it is unlikely you made an api call and only care about 1 discrete property of an entire document.
programming
>It also has the downside of not utilizing any of the performance benefits you would get from actually using the tree structure it creates in memory when creating a DOM document, and only does slow lookups. Do you agree this is a tradeoff of micro optimization over decoupling? If that's so, isn't decoupling better than micro optimization if you want to read a website's workflow that is a very small payload? The post argues in favor of maintainability and decoupling over performance. The same can be said about [this](https://medium.com/@fagnerbrack/html-and-state-a-challenging-way-to-look-at-web-performance-e3084fcff70d). >Also the author implies a few things that are untrue. HTML has versioning that is breaking. You can't reliably mix html from different versions and have it render reliably. The post says, and I quote: "The most common workaround for a fragile API ... is to [start sending versions](https://twitter.com/fielding/status/376835835670167552) in URLs or headers". It doesn't say anything about the DOCTYPE. Versioning in the message is totally fine. >Another annoying thing is...if all you are doing is looking up elements based on attribute values and grabbing their values use xml and xsl it is more expressive and essentially a less strict version of html that will have less overhead. In that case the browser can't render XML for humans. If you use HTML, you can use browser rendering AND an API foundation that allows you to create metadata in the markup itself. The website already have a workflow, it's very easy and convenient to just code that workflow for machines to use. Use tags to render information for humans; attributes to provide metadata for machines. Does that make sense?
programming
Your ignore my first and probably the most important point....this solution doesn't solve anything. By only utilizing the query selector with attribute value pairs your treating your data like a dictionary. it is equivalent to as if the document was a dictionary and you were doing Document['class="something"']. The data contract is now a dictionary not a rich object graph. The data contract still break down if an element changes. You haven't decoupled anything you have simply changed the data contract. To your last point if you have found a use for an request that can server as both a data feed for an api endpoint and a user accessible web page more power to you...but I don't think that need exists. XML is readable enough, and accomplished the same thing the author is trying to do with his narrow use of query selector but better, and without the extra rules html has. EDIT: sorry for any typos or bad grammar.
programming
>The data contract is now a dictionary not a rich object graph. The data contract still break down if an element changes. You're right the contract is a dictionary of key/value pairs, but why does that matter to the post? I don't understand how the data contract still breaks down if an element changes, in fact what do you mean by "breaks down" exactly? Does the code throws a runtime error "Cannot find property x of undefined" or it just doesn't find the element? If the value of the "class" changes, of course it's not gonna find the element. However, it's not gonna "break down" the code as if you were looking up the properties like this: "regions.Sydney.latitude". If one property changes, that's a runtime error, it breaks everything. If you use querySelector, though, it doesn't break everything. The code doesn't find the element it's looking for but it still works as if the element is not there. >To your last point if you have found a use for an request that can server as both a data feed for an api endpoint and a user accessible web page more power to you...but I don't think that need exists. XML is readable enough, and accomplished the same thing the author is trying to do with his narrow use of query selector but better, and without the extra rules html has. Yes you can use XML in a new end-point, the cost here is that you have to create a new representation of your website when you already have one. Why create a new end-point when you can just enhance your existing one to expose the workflow to non-visual clients? The need doesn't exist because many people are used to bear the cost of creating new end-points without realizing it. There's no need to do that in many circumstances.
programming
The important part isn't that my javascript code for this particular situation doesn't break. In fact the not breaking when the data isn't there is a probably a worse situation than the code breaking because it is likely masking an exception. An API is an application programming interface. An interface is a contract of behavior. When you set up your data contracts at your endpoints it is important that between major versions you honor that contract. If you tell a consumer to get this data look here, then move it while it might not break if you are doing it with the query selector method, you have breached the contract. That is all that matter.
programming
>The important part isn't that my javascript code for this particular situation doesn't break. In fact the not breaking when the data isn't there is a probably a worse situation than the code breaking because it is likely masking an exception. Totally agree. That's an obvious fundamental principle of relying on data that is essential for the application to work. If the data isn't there, you don't want to mask an exception. Ever. However, you would never code in a way it can evolve into an architecture that have to rely on that kind of coupling in the first place. That's the wrong way to do things. That statement seems like a [straw man](https://en.wikipedia.org/wiki/Straw_man) to what we're really talking about here. Which has nothing to do with cases where the data you rely on is essential to the application. I'm talking about designing a non-visual client that will work even if the data is not there. The Sydney latitude example shows if the latitude is not there it doesn't need to show anything. Also, you can change the structure of the HTML and as long as it respects the contract, it won't break. The non-visual client doesn't care about the structure, it only cares about specific attributes. >An API is an application programming interface. An interface is a contract of behavior. When you set up your data contracts at your endpoints it is important that between major versions you honor that contract. Do you mean major versions of the website, the client or the URL? There's a big difference here. Version the message or the client, not the website. Everybody loves to version the website in "/v1" end-point. That's completely wrong and misses fundamental understanding of how the web works. >If you tell a consumer to get this data look here, then move it while it might not break if you are doing it with the query selector method, you have breached the contract. Can you elaborate what you mean by that paragraph? It's too confusing and I can't understand it, sorry. ​ ​
programming
>This almost make it sound like you care more about your consuming code and less about the API itself. Of course I care about the consuming code because that's the client of the API! It makes no sense to design an API that is not to make the life of the consuming code easier. >You can always null check on javascript object. Do you mean "if (!prop) { do somewthing? }". If you mean that be aware that's additional code that needs to be tested. You don't need that. Code that doesn't exist is the code you don't need to debug. You can write code that can last forever, [look at this](https://levelup.gitconnected.com/how-to-write-code-that-will-last-forever-f8c4b1c0c867). >Many applications need data to be in the apis they are calling if it isn't there it is often an unrecoverable exception similar to a database connection failing. It isn't often just oh well wasn't there lets continue on our merry way. Those application bind domain-specific logic into the message. If you write a client against a message that has the domain model bound to it, then you're doomed to have to version URLs because every change in your API will break clients, you're also doomed to create specific code like "if (domainProperty) { doSomethingWith(domainProperty) }" and have to test it. That's just a waste of time. If you code against a hypermedia format like what querySelector does, in the end you only have a Facade and you change your whole format without breaking clients (as long as you keep the contract). >As I understand this you want to be able to 'ehance' existing endpoints to also work as datafeeds. That is just blurring responsibility of the page/endpoint for a minor gain of convenience for the developer. At the same time it pushed the responsibility of consuming the 'API' in this new way that is inefficient and verbose onto the consumer... I don't see the benefit of this maybe I am missing the point. The point is cost of change and maintainability. You don't need to maintain multiple end-points to provide an API for your website's workflow (I mean ONLY the website's workflow). You already have one and that's the website itself. >I'm sorry I simply don't agree with you or the author Sorry I didn't put the disclaimer, but I'm the author. I assumed the Reddit username and the medium account would give the hint. Is there a way to mark the post as "OC"?
programming
> Totally agree. That's an obvious fundamental principle of relying on data that is essential for the application to work. If the data isn't there, you don't want to mask an exception. Ever. However, you would never code in a way it can evolve into an architecture that have to rely on that kind of coupling in the first place. That's the wrong way to do things. > That statement seems like a straw man to what we're really talking about here. Which has nothing to do with cases where the data you rely on is essential to the application. I'm talking about designing a non-visual client that will work even if the data is not there. The Sydney latitude example shows if the latitude is not there it doesn't need to show anything. Also, you can change the structure of the HTML and as long as it respects the contract, it won't break. The non-visual client doesn't care about the structure, it only cares about specific attributes. First of all you're right you don't code in a way that relies on a specific implementation, you create boundaries between appropriate layers. A consumer could just say oh that data doesn't exists anymore, or it moved somewhere else, but they shouldn't have to. You establish a contract of how the data feed is gonna look, stuff like this data can be found here it will always be there, this other piece can be found here it may or may not exists. The producer of the data doesn't just say well the consumer shouldn't have relied on the data being in that spot its on them. That bogus. The point of a data feed is to provide data. If a database connection fails we don't say you shouldn't have coded in a way that relied on a data connection, we throw an exception and hopefully have system that notifies someone the database is down. When the application needs to data to achieve its core goal that is unavoidable there is no coding around it that is a hard dependency. You should keep the app from blowing up but that doesn't mean it can continue execution as normal. > If you tell a consumer to get this data look here, then move it while it might not break if you are doing it with the query selector method, you have breached the contract. What I mean is if a producer of data tells me I can find the data I need somewhere, and then changes that I'm sure as hell not gonna be relying on that data feed anymore. You cannot violate a data contract once it has been established. EDIT I edited my previous post after you responded to it(didn't realize you had) moving it here for clarity. > If the value of the "class" changes, of course it's not gonna find the element. However, it's not gonna "break down" the code as if you were looking up the properties like this: "regions.Sydney.latitude". If one property changes, that's a runtime error, it breaks everything. If you use querySelector, though, it doesn't break everything. The code doesn't find the element it's looking for but it still works as if the element is not there. This almost make it sound like you care more about your consuming code and less about the API itself. You can always null check on javascript object. It is just the same. But if it doesn't error when you expect data to be there that can be a worse issue. Many applications need data to be in the apis they are calling if it isn't there it is often an unrecoverable exception similar to a database connection failing. It isn't often just oh well wasn't there lets continue on our merry way. I'm sorry I simply don't agree with you or the author. As I understand this you want to be able to 'ehance' existing endpoints to also work as datafeeds. That is just blurring responsibility of the page/endpoint for a minor gain of convenience for the developer. At the same time it pushed the responsibility of consuming the 'API' in this new way that is inefficient and verbose onto the consumer... I don't see the benefit of this maybe I am missing the point.
programming
> > This almost make it sound like you care more about your consuming code and less about the API itself. > Of course I care about the consuming code because that's the client of the API! It makes no sense to design an API that is not to make the life of the consuming code easier. I'm sorry I was a little unclear here. I should have said it kinda sounds like your saying the only thing that matters is the client. Your client does all the work what the endpoint returns doesn't matter in the slightest you just search for magic strings and if they are there act on it. There is no API in this scenario, just an html scraper. No-one can ever build anything that relies on the data being there so it is extremely limited in its uses. Saying it works as long as no-one changes the class name is equivalent to saying a json payload works as long as the structure doesn't change. > Those application bind domain-specific logic into the message. If you write a client against a message that has the domain model bound to it, then you're doomed to have to version URLs because every change in your API will break clients, you're also doomed to create specific code like "if (domainProperty) { doSomethingWith(domainProperty) }" and have to test it. That's just a waste of time. If you code against a hypermedia format like what querySelector does, in the end you only have a Facade and you change your whole format without breaking clients (as long as you keep the contract). First of all the point of any API is to expose a consumer to a domain that they are interested in and give it a way of interacting with that domain. Second it sounds to me like you are advocating that your html just exists as normal and sometimes it might contain information that your 'client' is interested in and the client can scrape for that. In that case you haven't created an API you created a framework within your site.
programming
The HTML doesn't have domain specific logic in the structure, but in the metadata. >Every attribute value that you use to select elements in an HTML document is the equivalent to having specific keys in a JSON document. It is, the difference is that you have to create a new end-point to produce that JSON and maintain that. There's no point to do that if you can just enhance your HTML with meaningful information that other clients can understand, with the benefit you already have a Facade to lookup for it (querySelector)
programming
>you create boundaries between appropriate layers. A consumer could just say oh that data doesn't exists anymore, or it moved somewhere else, but they shouldn't have to. You establish a contract of how the data feed is gonna look, stuff like this data can be found here it will always be there, this other piece can be found here it may or may not exists. The producer of the data doesn't just say well the consumer shouldn't have relied on the data being in that spot its on them. That bogus. I don't understand this part: "stuff like this data can be found here it will always be there, this other piece can be found here it may or may not exists. The producer of the data doesn't just say well the consumer shouldn't have relied on the data being in that spot its on them. That bogus." Can you elaborate? Thanks.