> if the method is a function in non-strict mode code, null and undefined will be replaced with the global object and primitive values will be converted to objects.
function dis(){
"use strict";
return this;
}
dis.call(5);
> 5
function modifyValueType(valueType) {
valueType.foo = 5
}
var valueType = 5
console.log(valueType.foo)
// > undefined
// now this is confusing because you don't want to be doing this every time
// a function is called (because this changes):
function modifyValueType() {
if (isValueType(this)) {
// what to do here?
}
this.foo = 'bar'
}
var valueType = 5
modifyValueType.call(valueType)
// So what happens is valueType is boxed to reference, so you can use valueType.foo
this is all of course out of strict mode
basically the boxing behaviour stops you from having to check if this is a value type
Currently I am working on a profiling unit that does not require stack traces to preserve the call stack, and can return the performance in a html format.
All though the logging in itself is fairly fast (negligible overhead on each function), the visualisation of the information is not.
With a ...
This question would be best suited posted to Code Review. Stack Overflow is more general programming Q and A where as Code Review is for 'Q&A for peer programmer code reviews' — Crazy Dino5 secs ago
@CrazyDino In general, yes, but one of the key requirements for Code Review is that "The O.P. owns and understands the code they want reviewed". Reviewing the O.P.'s code, in general, for performance improvements would be ok, comparing it to his lecturer's is not. — Zak54 secs ago
Jas claims to have fed a crawdad to a cow.
According to Wikipedia, a crawdad is just another name for a crayfish. Since you can catch crayfish in the game, I thought that my bovine companions would be delighted to receive one as a treat. However, when I left or right-click the cow while holdin...
What I'm saying, in essence, is that the first half of the O.P's question, by itself, would be ok for Code Review, but "I have no idea how his code works, can anyone explain it as well? Thx." definitely is not. If a question would be okay elsewhere with editing, I like to make that clear before they cross-post and get edited/downvoted/closed. — Zak30 secs ago
My own rules: Make sure stuff gets done faster/better than expectations Don't do anything *blatantly* Off-Topic at your desk Know your workplace culture With the above, do whatever you would feel OK justifying to your boss if asked about it.
I just saw the following code
var array1 = [2,3,4];
var array2 = [1];
Array.prototype.push.apply(array2, array1);
and was wondering why you would do that instead of this
var array1 = [2,3,4];
var array2 = [1];
array2 = array2.concat(array1);
@DanPantry Pretty much. I spend a good % of my work hours reading the news, reading SE/CR, reading other blogs and stuff. It helps that my job is to "Get stuff done, and we don't really care how".
@Mawg It looks wrong, but it's not. That's frameworks for you, they all have their quirks. (I know it's been two years, so sorry about that, but you were being very opinionated! I would hope the people doing the code review would know their way around the framework they're using...) — daemonaka9 secs ago
I have created a lock-free self organizing list with transpose method using the java.util.concurrent.atomic.AtomicStampedReference. The operations are working as expected and I also compared my result to other implementations with locks.
I am looking for suggestions on how i could improve my imp...
I have been developing a simple login registration page with in php using repository pattern. Following is the business rules :
During registration
Email must be unique.
Email must be a valid email address.
User table columns:
id, name, username, password, created_at, updated_at
register.ph...
@Mast Are you saying it's not mentally taxing work if your department consists of people writing code, or that it doesn't have a big impact on the business if your department consists of people writing code?
Starting point
I kind-of inherited a VBA project at work that consists of a bunch of Word document templates that provide users with the tools they need to create documents according to company guidelines and to help them give all documents the same appearance. We use different templates for the ...
@Mast that doesn't work, if you work in a department where people write code, it doesn't stop most people from not knowing how to code. It does change "most people in your department"... pedantry
Thanks a lot, guys! So much food for thought. Though I 'll keep in mind that I have to post these kind of questions in "Code review" section next time. — Alex43 secs ago
I regularly write articles about programming and speak at conferences. That's why I review large amounts of code and see various errors. Once, during the preparation of an article, I noticed an interesting error pattern that I called "Last Line Effect" . Now I have a déjà vu - I have detected one...
@CaptainObvious Why do people make mistakes writing off-topic questions?
I feel bad because it is a fairly comprehensive question
I have a horrible feeling after I fix these syntax errors that flowtype is going to blow up and complain that all the types in the app are wrong
Because we've had type detection turned off for so long
I'm wrong. The optional parameter type in flowtype is the same as TS. It's just you have to have type annotations for all parameters when you are declaring its type via flow
Let's say in my application I have a script that triggers a click event on an html id. I want to then test that event in Jasmine. Below is the test I have in place for this scenario. I have a few questions about it though for anyone familiar with Jasmine. Below is my test and then some questions....
So, my fresh, brand new understanding of #define, #ifdef, #ifndef, and other such bits of code is that they are preprocessor directives that tell the compiler to specifically ignore or include segments of source code? But if those definitions take place within the source code, how does it ever have any sort of differentiable effect?
For instance, I encountered several when setting up my 3D printer's arduino software. I specifically had to go in and tell it certain values. So why are they preprocessor directives? Why aren't they just a normal part of the source code?
But we don't normally distribute source code to clients to compile themselves, right? Or is that actually whats happening when an "installer" run? Is it compiling and organizing source?
nah, an installer merely copies the executable into its "install folder", ensures all the dependencies are there, and registers any COM components with Windows... Assuming Windows and COM components are involved.
@Mat'sMug So you're saying the compiler itself, on the computer on which it is installed, has predefined constants to know what OS or whatever it is installed on? But that still raises the question to me of how it knows when it is installing a software to Windows XP, 7, 8, 8.1, 10, 3.1...
(that last one was a joke...)
Maybe I'm being dense about this, and if so I apologize.
.net usually defines DEBUG and TRACE precompiler constants in a debug configuration, and only a TRACE constant in a release configuration; that's how Debug.Assert and Debug.WriteLine calls are trimmed from a release build AFAIK
There's so much wrong with this code beside the index overrun that the only viable answer would be 'read at least a few of the hundreds of topics about PRIME1 here and at Code Review'. — DarthGizka57 secs ago
I'm afraid I just don't see the value unless you're distributing source code for someone to customize themselves. Then whether I define a value or not in the source code makes a difference in the compiled code, but I have to do the customizing myself. So it becomes a mudulated, cookiecutter kind of source.
I should do more research on this myself. I appreciate your input, guys and gals.
@WaymanBellIII When working on embedded platforms, where you want your program size to be small, it helps to be able to change a constant which enables or disables features via not including them.
Specifically I've had cameras which could move and cameras which couldn't, and rather than maintaining two projects, I had one project and a flag CAMERA_MOVEMENT
Code review question in regards to Javascript. I made a pastebin: http://pastebin.com/Rg67Egpc
My goal was to make several different Objects like Truck, that all inherit (prototype-chain) Vehicle. However I am not sure if I am doing this correctly in JS.
I am looking for general thoughts on if it looks like I know what I am doing, or if it looks like I am just taking a stab in the dark. If that makes sense?
@Austin It's not necessarily the wrong chat, but drive-by "here's my code, please review" requests are not behaviour that would be generally well received. Much better to come in, say hi, ask if it's okay to get an informal review and/or if there's a specific room/people you should take it to.
I'm trying to wrap my head around repository and service layers. What I have can be simplified to an example like this:
Model:
public partial class Employee
{
public int ContractorId { get; set; }
public string Name { get; set; }
public string JobTitle { get; set; }
}
Repository:
...
@Austin It's mostly because, relative to SO, we're a pretty tiny site with a pretty small group of people who populate chat, so there's a certain, I dunno, coziness to the 2nd Monitor.
I am trying to make easy to use non recursive make script.
It works with several directories, here is an minimal example.
Everything is packed here:
https://github.com/nmmmnu/make_test
Directory structure
/ - root
/bin - where executable(s) will be made
/obj - where .o...
i'm using typescript, however this example is in plain javascript. i have a class rank with a child-class master. what i need is an ordered collection of unique masters. here's what i have but it seems a little "kak":
function getMasters() {
var gms = [];
_.each(this.ranks, (r) => {
...
@Austin Read the tour and the on-topic help centre. If you can formulate a question complying with those, feel free to do so. For bonus points, ask the how-to-ask meta.
From what I understand, you want to make sure that new objects are not created when they are identical to what has been created before.
This is relatively easy, and would include either having a static map or a map inside another object, such as a ReflectionFactory. I'd personally go with Reflec...
I have no memory whatsoever of having written that
Background:
Didn't what to have to reference bulky 3rd party lib for inline data driven tests and wanted to use standard MS testing framework.
Created helper InlineDataDrivenTest to provide a workaround for this limitation.
Usage
[TestClass]
public class DataDrivenTests : MiscUnitTests {
...
My favourite: Recently, there was a Supreme Court ruling in the UK. It was supposed to last 2 days of hearings and then the justices would make a decision over the next 2-6 months.
2
Instead, at the end of day 1 they basically went "yep, this is blatantly illegal" and ruled there and then.
I'm attempting to create a script that will run a backup every 6 hours. My current script isn't working. Any advice?
# vi /backup.sh
#!/bin/bash
TIME=date +%b-%d-%y
FILENAME=backup-$TIME.tar.gz
SRCDIR=/imp-data
DESDIR=/mybackupfolder
tar -cpzf $DESDIR/$FILENAME $SRCDI...
I started out with the Rosalind problems a while back. Turns out it's a great way to learn a new language. I'm still trying to learn Ruby, and while I haven't managed to use regular expressions as much as I wanted to (learning those being one of the reasons I started learning Ruby in the first pl...
My first pong game in java. I tried using swing but later on decided to try JavaFX instead.
Both the paddles are controlled by the user, one by WASD and the other by the arrow keys.
I have a few issues with this though:-
1) If I hit the ball while going up(I mean if the ball is about to bounce...
I wrote a userscript (to be run with Greasemonkey/Tampermonkey on Stack Exchange sites) to include a Prettify extension and enable syntax highlighting for a language which isn't supported by default. I have only occasionally dabbled in JavaScript, and I have never written a user-script before.
(...
I'v almost finished my first pong game in java. I tried using swing but later on decided to try JavaFX instead.
Both the paddles are controlled by the user, one by WASD and the other by the arrow keys.
I have a few issues with this though :-
1) If I hit the ball while going up(I mean if the ba...
On TensorFlow side, it was ported to Android and iOS (mostly) and Raspberry Pi. On NaCL side, someone ported Python/SciPy to run inside Chrome (codereview.chromium.org/165473002). So I bet it's possible. But unless you are a hacker genius, I think it may take a >1 month of work though....maybe start a discussion on github to drum up some support? — Yaroslav Bulatov38 secs ago
Did you know C# changes values of double literals slightly, and the difference goes to @gafter's bank account? https://github.com/dotnet/roslyn/issues/4221
I am currently working on an inpainting algorithm : the input is a picture, I apply a Mask (random disposition of dark pixels) and then the algorithm tries to recover the original picture using the "conjugate gradient" method.
I implemented for gray pictures, it works fine. I am now trying to si...
@GameAlchemist That's the pizza test. If my code doesn't stop running in the time it takes me to make a pizza I start to suspect something is wrong. Sure it's no cure for Alan Turing's halting problem but at least I get a pizza outta the deal. — CandiedOrangeApr 17 at 9:52
I was just wondering what other options I could do to improve/change the code that I'm currently working with, eg// the displayed format of my list.
Please feel free to alter my code to make it even better!
The code is about displaying membership information of all clients from database
def op...
I wrote my string class. The code works, but could anyone tell if I am doing anything wrong?
It is an exercise from the "Accelerated c++" book:
Implement the Str class, but choose an implementation strategy that requires that the class manage the storage itself. For example, you might store an ...
It appears your code isn't quite ready for a peer review yet - if you can narrow down on the issue you want to fix, you could ask about it on Stack Overflow. As it stands this question is off-topic. It will be put on hold to give you a chance to edit your working code in without invalidating any answers. — Mat's Mug ♦25 secs ago
Important definitions:
session.gc_maxlifetime - (default 1440 seconds) defines how long an
unused PHP session will be kept alive. For example: A user logs in,
browses through your application or web site, for hours, for days. No
problem. As long as the time between his clicks never exce...
Project Euler problem 10 is to find the sum of all primes less than 2 million. I have written a program that does this, and it works, but it takes an excruciatingly long amount of time. What I'm asking is if there is anyway I could optimize this to make it run much faster. Here is my code:
def c...
I'm very new to OOP and but am aware of the concepts after educating myself with some good resources despite this I want to get expert knowledge on the direction I'm taking for this project I've set myself.
I've decided to make a forum as It allows me to implement the class/inheritance system qu...
def add_info_extractor(self, ie):
"""Add an InfoExtractor object to the end of the list."""
self._ies.append(ie)
if not isinstance(ie, type):
self._ies_instances[ie.ie_key()] = ie
ie.set_downloader(self)
def get_info_extractor(self, ie_key):
"""
Get an instanc...
I have started learning Java and was trying to solve some easy problems from different websites like HackerRank and leetcode.I am relatively new to programming so please don't mind if this is too naive. I found a problem in LeetCode to rotate array.The problem can be found here
I have implement...
@jtbandes please read this and suggest this to the asker. Simon: your problem can be on topic on codereview, but you have to reformulate it according to the standards of that site. — Andras Deak45 secs ago
@AndrasDeak: Please correct me if I'm wrong, but I believe this question is actually a good candidate for CR.SE. Simon, you should see a small link to delete this question if you like, and you can simply post a new one (with the same content) there. Make sure to check out what's considered on topic for CodeReview. — jtbandes58 secs ago
My code will display a Hearthstone deck list.
I'm still learning HTML and I'd like help with a few things:
• How readable is my code? How can I improve readability?
• Have I used any bad practices? What should I do instead?
• Is there any redundancy in my code?
<!DOCTYPE html>
<html>
<head>...