Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Welcome to Code Review! There are quite a few things I can talk about here.

First off, your variable names need to be more descriptive. All of these variables should have more descriptive names:

var res = 7;
var area = [];
var camP = [random(500,1000), random(500,1000)];
area = [];
for (var y = -200; y < 200; y+=res)
for (var x = -200; x < 200; x+=res)
var drawPix = function(v, x, y){

It is preferable not to use single letter variable names in any language, because they are not helpful to understanding what the code is doing. It can be very difficult to come up with appropriate names for variables. This is one of the biggest challenges of programming, but it is an important one to do properly.

Your method names could also be more explicit. They should describe exactly what they are going to do as concisely as possible. So these method names:

var setArea = function()
var drawPix = function(v, x, y){
var drawArea = function()

Should be changed to names such as this:

var createMap = function()
var drawOnePixel = function(v, x, y){
var drawMap = function()

Those names may not be perfect, but they are closer to what would be expected.


Edited to reflect the comments below:

The comparison with a float that you have here is fine:

if (v < 0.49)

However, you should know that if you try to compare a float directly such as

if (v == 0.49)
if (v != 0.49)

You may run into issues. A better and more lengthy description of why this is can be found here: What's wrong with using == to compare floats? What's wrong with using == to compare floats?

Also please see the comment below for more information.

One idea I had to deal with this problem was to simply use integers for everything like this, and avoid using floats. I am not sure yet if this is a better practice overall, but it is something to consider. If you were doing this if (v == 49) or if (v == 490) then you would never run into this issue.


I like that you are creating the map in one function, and rendering the map in another. This is good practice and it is a good separation of concerns. Keep it up!

Welcome to Code Review! There are quite a few things I can talk about here.

First off, your variable names need to be more descriptive. All of these variables should have more descriptive names:

var res = 7;
var area = [];
var camP = [random(500,1000), random(500,1000)];
area = [];
for (var y = -200; y < 200; y+=res)
for (var x = -200; x < 200; x+=res)
var drawPix = function(v, x, y){

It is preferable not to use single letter variable names in any language, because they are not helpful to understanding what the code is doing. It can be very difficult to come up with appropriate names for variables. This is one of the biggest challenges of programming, but it is an important one to do properly.

Your method names could also be more explicit. They should describe exactly what they are going to do as concisely as possible. So these method names:

var setArea = function()
var drawPix = function(v, x, y){
var drawArea = function()

Should be changed to names such as this:

var createMap = function()
var drawOnePixel = function(v, x, y){
var drawMap = function()

Those names may not be perfect, but they are closer to what would be expected.


Edited to reflect the comments below:

The comparison with a float that you have here is fine:

if (v < 0.49)

However, you should know that if you try to compare a float directly such as

if (v == 0.49)
if (v != 0.49)

You may run into issues. A better and more lengthy description of why this is can be found here: What's wrong with using == to compare floats?

Also please see the comment below for more information.

One idea I had to deal with this problem was to simply use integers for everything like this, and avoid using floats. I am not sure yet if this is a better practice overall, but it is something to consider. If you were doing this if (v == 49) or if (v == 490) then you would never run into this issue.


I like that you are creating the map in one function, and rendering the map in another. This is good practice and it is a good separation of concerns. Keep it up!

Welcome to Code Review! There are quite a few things I can talk about here.

First off, your variable names need to be more descriptive. All of these variables should have more descriptive names:

var res = 7;
var area = [];
var camP = [random(500,1000), random(500,1000)];
area = [];
for (var y = -200; y < 200; y+=res)
for (var x = -200; x < 200; x+=res)
var drawPix = function(v, x, y){

It is preferable not to use single letter variable names in any language, because they are not helpful to understanding what the code is doing. It can be very difficult to come up with appropriate names for variables. This is one of the biggest challenges of programming, but it is an important one to do properly.

Your method names could also be more explicit. They should describe exactly what they are going to do as concisely as possible. So these method names:

var setArea = function()
var drawPix = function(v, x, y){
var drawArea = function()

Should be changed to names such as this:

var createMap = function()
var drawOnePixel = function(v, x, y){
var drawMap = function()

Those names may not be perfect, but they are closer to what would be expected.


Edited to reflect the comments below:

The comparison with a float that you have here is fine:

if (v < 0.49)

However, you should know that if you try to compare a float directly such as

if (v == 0.49)
if (v != 0.49)

You may run into issues. A better and more lengthy description of why this is can be found here: What's wrong with using == to compare floats?

Also please see the comment below for more information.

One idea I had to deal with this problem was to simply use integers for everything like this, and avoid using floats. I am not sure yet if this is a better practice overall, but it is something to consider. If you were doing this if (v == 49) or if (v == 490) then you would never run into this issue.


I like that you are creating the map in one function, and rendering the map in another. This is good practice and it is a good separation of concerns. Keep it up!

fixed inaccuracies in the float section
Source Link
bazola
  • 8.6k
  • 2
  • 34
  • 73

Welcome to Code Review! There are quite a few things I can talk about here.

First off, your variable names need to be more descriptive. All of these variables should have more descriptive names:

var res = 7;
var area = [];
var camP = [random(500,1000), random(500,1000)];
area = [];
for (var y = -200; y < 200; y+=res)
for (var x = -200; x < 200; x+=res)
var drawPix = function(v, x, y){

It is preferable not to use single letter variable names in any language, because they are not helpful to understanding what the code is doing. It can be very difficult to come up with appropriate names for variables. This is one of the biggest challenges of programming, but it is an important one to do properly.

Your method names could also be more explicit. They should describe exactly what they are going to do as concisely as possible. So these method names:

var setArea = function()
var drawPix = function(v, x, y){
var drawArea = function()

Should be changed to names such as this:

var createMap = function()
var drawOnePixel = function(v, x, y){
var drawMap = function()

Those names may not be perfect, but they are closer to what would be expected.


I cannot say 100% for Javascript, but I know that for other languages, it can be dangerous to compare against a float in if statements such as this:Edited to reflect the comments below:

The comparison with a float that you have here is fine:

if (v < 0.49)

If you run into bugs where the proper behavior is not triggering at the proper threshold, this could be the cause. In my Objective-C code, I usually compare against a range, but even this has issues. @rolfl suggested this method today in the 2nd Monitor chat room: abs(diff) < threshold. This might be useful to you in the future.However, you should know that if you try to compare a float directly such as

if (v == 0.49)
if (v != 0.49)

AnotherYou may run into issues. A better and more lengthy description of why this is can be found here: What's wrong with using == to compare floats?

Also please see the comment below for more information.

One idea I had to deal with this problem was to simply use integers for everything like this, and avoid using floats. I am not sure yet if this is a better practice overall, but it is something to consider. If you were doing this if (v <== 49) or if (v <== 490) then you would never run into this issue.


I like that you are creating the map in one function, and rendering the map in another. This is good practice and it is a good separation of concerns. Keep it up!

Welcome to Code Review! There are quite a few things I can talk about here.

First off, your variable names need to be more descriptive. All of these variables should have more descriptive names:

var res = 7;
var area = [];
var camP = [random(500,1000), random(500,1000)];
area = [];
for (var y = -200; y < 200; y+=res)
for (var x = -200; x < 200; x+=res)
var drawPix = function(v, x, y){

It is preferable not to use single letter variable names in any language, because they are not helpful to understanding what the code is doing. It can be very difficult to come up with appropriate names for variables. This is one of the biggest challenges of programming, but it is an important one to do properly.

Your method names could also be more explicit. They should describe exactly what they are going to do as concisely as possible. So these method names:

var setArea = function()
var drawPix = function(v, x, y){
var drawArea = function()

Should be changed to names such as this:

var createMap = function()
var drawOnePixel = function(v, x, y){
var drawMap = function()

Those names may not be perfect, but they are closer to what would be expected.


I cannot say 100% for Javascript, but I know that for other languages, it can be dangerous to compare against a float in if statements such as this:

if (v < 0.49)

If you run into bugs where the proper behavior is not triggering at the proper threshold, this could be the cause. In my Objective-C code, I usually compare against a range, but even this has issues. @rolfl suggested this method today in the 2nd Monitor chat room: abs(diff) < threshold. This might be useful to you in the future.

Another idea I had was to simply use integers for everything like this, and avoid using floats. I am not sure yet if this is a better practice overall, but it is something to consider. If you were doing this if (v < 49) or if (v < 490) then you would never run into this issue.


I like that you are creating the map in one function, and rendering the map in another. This is good practice and it is a good separation of concerns. Keep it up!

Welcome to Code Review! There are quite a few things I can talk about here.

First off, your variable names need to be more descriptive. All of these variables should have more descriptive names:

var res = 7;
var area = [];
var camP = [random(500,1000), random(500,1000)];
area = [];
for (var y = -200; y < 200; y+=res)
for (var x = -200; x < 200; x+=res)
var drawPix = function(v, x, y){

It is preferable not to use single letter variable names in any language, because they are not helpful to understanding what the code is doing. It can be very difficult to come up with appropriate names for variables. This is one of the biggest challenges of programming, but it is an important one to do properly.

Your method names could also be more explicit. They should describe exactly what they are going to do as concisely as possible. So these method names:

var setArea = function()
var drawPix = function(v, x, y){
var drawArea = function()

Should be changed to names such as this:

var createMap = function()
var drawOnePixel = function(v, x, y){
var drawMap = function()

Those names may not be perfect, but they are closer to what would be expected.


Edited to reflect the comments below:

The comparison with a float that you have here is fine:

if (v < 0.49)

However, you should know that if you try to compare a float directly such as

if (v == 0.49)
if (v != 0.49)

You may run into issues. A better and more lengthy description of why this is can be found here: What's wrong with using == to compare floats?

Also please see the comment below for more information.

One idea I had to deal with this problem was to simply use integers for everything like this, and avoid using floats. I am not sure yet if this is a better practice overall, but it is something to consider. If you were doing this if (v == 49) or if (v == 490) then you would never run into this issue.


I like that you are creating the map in one function, and rendering the map in another. This is good practice and it is a good separation of concerns. Keep it up!

Source Link
bazola
  • 8.6k
  • 2
  • 34
  • 73

Welcome to Code Review! There are quite a few things I can talk about here.

First off, your variable names need to be more descriptive. All of these variables should have more descriptive names:

var res = 7;
var area = [];
var camP = [random(500,1000), random(500,1000)];
area = [];
for (var y = -200; y < 200; y+=res)
for (var x = -200; x < 200; x+=res)
var drawPix = function(v, x, y){

It is preferable not to use single letter variable names in any language, because they are not helpful to understanding what the code is doing. It can be very difficult to come up with appropriate names for variables. This is one of the biggest challenges of programming, but it is an important one to do properly.

Your method names could also be more explicit. They should describe exactly what they are going to do as concisely as possible. So these method names:

var setArea = function()
var drawPix = function(v, x, y){
var drawArea = function()

Should be changed to names such as this:

var createMap = function()
var drawOnePixel = function(v, x, y){
var drawMap = function()

Those names may not be perfect, but they are closer to what would be expected.


I cannot say 100% for Javascript, but I know that for other languages, it can be dangerous to compare against a float in if statements such as this:

if (v < 0.49)

If you run into bugs where the proper behavior is not triggering at the proper threshold, this could be the cause. In my Objective-C code, I usually compare against a range, but even this has issues. @rolfl suggested this method today in the 2nd Monitor chat room: abs(diff) < threshold. This might be useful to you in the future.

Another idea I had was to simply use integers for everything like this, and avoid using floats. I am not sure yet if this is a better practice overall, but it is something to consider. If you were doing this if (v < 49) or if (v < 490) then you would never run into this issue.


I like that you are creating the map in one function, and rendering the map in another. This is good practice and it is a good separation of concerns. Keep it up!

default

AltStyle によって変換されたページ (->オリジナル) /