@mikbe you should never work on production code with this trick. Then someone is doing something wrong. This is just a trick that's fun to use while testing out two different approaches. Such as an iterative versus a recursive algorithm.
This is a cool trick! Thanks
@cguillemette I'm using 8 editors, Visual Studio, Sublime Text 2/3, Mono Develop, Notepad++, Eclipse, NetBeans, MS SQL Management Studio and Vim.
@wildlyinaccurate feature flippers do not prevent code from being built, and thus the code is available in the binary. What's safest depends on the definition of save, and the specs of the project. Feature flippers solves a problem (highly relevant to the open/closed principle) but not the problem this trick solves.
@herson well, then you probably would not use the system time for the currentTime() function - but indeed you found a potential weakness.
The code suggested here would wait time equal to the negative change, so if you set the system clock back 3 hours (-3) then it would take 3 hours before the protothread started up again. Setting the clock ahead of time would simply cause the thread to run sooner than it originally was supposed to.
@paprikkastudio link added, thanks! A very cool little app :)
@sergivives thanks!
This version places text on the lines when multiple lines exits: http://jsfiddle.net/e4AcL/
Also, I love it!
@om-nom-nom although I selected the examples I did because I thought they might reach the most people with a feeling of "I've head about that" you make an embarrassingly good point. I updated the protip to reflect your comment. Thank you!
@tomtheisen thanks! That is of course correct. I updated the protip.
@pantelisar yeah, and I love it!
@mpapis thanks, removed javascript and added ruby.
@dpashkevich These tips would not apply to JS.
However I'd argue that your convention would be the JS equivalent of this tip which is meant for type safe languages obviously. I mean, you surly have some reasoning for putting configs and contructors at the top, right?
I also want to point out that this protip is tagged open-source because that's where I think applies best. In an open source project the source is the product. Documentation is fine, but if you want to 'sell' me the projects I'll read the code, and I expect it to be easily readable. So, when I discover a new promising Java project (for instance) and every files starts with 20 lines of private member listings I leave straight off the bat.
@dpashkevich it's not specified because it's hard to specify for all situations. If my protected method is protected simply because it is a common helper to inheriting types then it fits between public and private. But, if it's virtual or abstract then I could choose to put them above the public methods because I could reason that a likely reader is one that wants to make a superclass of my class. I'm not that black/white about it. Does this make sense to you? Thanks for the discussion! Do you follow any rule of thumb when you author code in regards to the textual location of the code?
@dpashkevich if it's a lot of work to structure the contents of your class it's too big, that said I said nothing about the work having to be manual.
I do not agree that it makes sense to place private methods before the public that uses them. You probably made that method to abstract something away, only to ruin that abstraction by placing the code above which in my mind makes it more important (that's the whole idea behind this opinion/tip).
This is not a suggested replacement for documentation. The idea with this is to NOT force me having to looking at the code 'in all its entirety'.
Outlines tell me nothing of the intent and I very well might not know what I'm looking for. If the class is structured from what the author thinks is important from top to bottom I could safely assume that I should start reading from the top and then goto-anything from there.
FYI: https://coderwall.com/p/un7keg
COPYPASTA OF MY COMMENT:
It may be a good idea to assign the jQuery object to a var, especially if your selector works on a large DOM.
Concider:
var $testDivs = $("#test").find("div");
if ($testDivs.length) {
//use $testDivs without searching the DOM again
}
It may be a good idea to assign the jQuery object to a var, especially if your selector works on a large DOM.
Concider:
var $testDivs = $("#test").find("div");
if ($testDivs.length) {
//use $testDivs without searching the DOM again
}
@ymarcov @jesusaurus this is not supposed to be a solution to the documentation of code. I list four of my reasons for wanting to read the code, and the last point uses the word idea freely.
I start out by saying the intended reader is a colleague and not a consumer of my API. My reason for tagging this in open source is that every contributor is a colleague (at least in my opinion).
SCENARIO: I have read the API documentation, I have read high-level wiki articles but I'm in the process of fixing a bug or adding a feature. I will need to read the code before implementing.
I admit it, I'm lazy and if I can have a say I'd like you to declare fields last because I don't care about them before I'm reading a method, and when I read it I can normally deduce the type of any given variable.
Just FYI: http://coderwall.com/p/uiiuvg :)
Good blog post!
+1
@ydbondt that's embarrassing... I did a google site:coderwall.com search first, no relevant results showed up. I'll update it to link to yours:)
Just as a disclaimer, this is not intended as an example of how to write CSS, but rather what !important can be used for. I've found it to be a time saver many times in real-world situations where I don't have the time or access to refactor the CSS styles. The html and css are written the way they are to cause the problem that may arise when elements inherit styles from many selectors.
@sheerun actually, I just tried to change the id to a class http://codepen.io/anon/pen/Afvto and it's still not displaying the p.news as one might think.
In my opinion it's better to default to JSON and use XML as the exception
@lautarodragan I still use /js or /scripts as well, just realized I could do /js/models /js/modules etc :) stupid really, but that's life. Also, when I first tried Require.js I neglected to do the optimization where Require appends all scripts to one file and minifies it and then the cache is used for clients. That made it a much better tool! I discovered it after I reverted to server side configuration of what files to include. I'll try it again soon though :)
One more interesting thing about javascript code maintenance is the lack of implied file organization. I actually spent quite a long time having just one folder with everything (the dredded /js) until I realized I could organize them however felt natural. That led to the problem of subjectivity, what I feel natural might not be the same as my colleague. In languages that enforce (or heavily invites) to some sort of convention is much easier to maintain just because files are located where you expect them to.
Passion is key, but so is experience! If only seniority indicated a surplus of relevant experience....
Right now it's just simple linear extrapolation between the closest two known values. This means, that for the example you're thinking about this module would really only use the two latest known points, and extrapolate linearly from those two values.
So, if you had visited [0,0] then [1,2] this module would predict [2,4] as the next coordinate which for small interval would be pretty accurate. If one want the curve to be taken into consideration a polynomial would be better, but a spline would probably be best :)
Of course