Comments (8)
Please consider avoiding variable names (eg. strings) that resemble keywords (eg. String) which can lead to confusion for beginners. The first example is much more clear when 'strings' is replaced with 'fruits', which is more descriptive.
var fruits:Array<String> = ["Apple", "Pear", "Banana"];
trace(fruits);
from haxe.org-comments.
Your confusion confuses me, String
isn't even a keyword, it's just a type name. Avoiding these kinds of similarities for that reasons seems like a pointless endeavor to me.
... having said that, I still agree that fruits
would be a better name here. And while we're at it, I don't like the Array<String>
type-hint because it's not very haxe-idiomatic to have explicit types for local variables.
from haxe.org-comments.
Maybe I should have said that 'String' is a 'reserved word or identifier' perhaps? This documentation is supposedly for beginners and I try to be mindful of what it was like when I started learning. An experienced programmer will have no problems sifting through the noise of 'strings' vs 'String', but it still creates noise when variable names and datatypes or identifiers resemble each other. Case in point below:
static function function1(int1: Int, int2: Int): Int
{
return int1 + int2;
}
VS.
static function sumTwoNums(num1: Int, num2: Int): Int
{
return num1 + num2;
}
from haxe.org-comments.
I looked at the example in its context again and now I actually disagree: The name strings
here is quite descriptive because the plural suggests that it's some sort of collection of strings, which is exactly what an Array<String>
is. The fact that they are names of fruits has no relevance here. This is amplified by the fact that the next example uses floats
, in which case you couldn't come up with any semantic name anyway.
So overall I prefer to not make any changes here.
from haxe.org-comments.
That's fine, to each his own. In reference to reserved identifiers: This code snippet actually compiles with no errors. I know I'm being a bit explicit in the datatype identification. But datatype identifiers can be used as variable names in Haxe? So, it appears that datatype identifiers are indeed not reserved words in Haxe? The equivalent code snippet would throw an error in most languages I'm familiar with. This is kinda cool, but also kinda scary,
class BasicTest {
static function main()
{
var String: String = "Zach";
Sys.println(String);
var Int: Int = 5;
Sys.println(Int);
}
}
from haxe.org-comments.
That's why I said that String
is a mere type name, there's nothing inherently reserved about this. Although it's still a bad idea to use it because the compiler might generate String.fromCharCode
or something like that, which could then fail if a String
local variable shadows the type.
Out of curiosity, which languages don't allow this?
from haxe.org-comments.
Thanks for the insight. So far this is what I have.
C# Screenshot The assignment target must be an assignable variable, property or indexer. Same warning for both string
and int
Go Screenshot Variable 'string' collides with the 'builtin' type, but Go allowed it to compile
Dart Screenshot Verbose warning
Object Pascal test.pas(4,5) Fatal: Syntax error, "identifier" expected but "STRING" found
from haxe.org-comments.
Multidimensional arrays needs further documentation if not better implementation. I have a few things that don't make sense. Using these:
var a1:Array=[1,2,3];
var a2:Array=[3,2,1];
var a3:Array=[2,3,1];
var all1:Array<Array>=[a1,a2,a3];
var all2:Array<Array>=[[1,2,3],[3,2,1],[2,3,1]];
I can easily sort either all1 or all2 which tells me that Haxe can handle each inner array as a value. But if I do trace(all1.indexOf(a1),all1.indexOf([1,2,3]),all2.indexOf(a1),all2.indexOf([1,2,3]));
output is 0, -1, -1, -1. I think I should get 0,0,0,0.
I also haven't found a way to use mapping to make the string array ["1,2,3","3,2,1","2,3,1"] from all1 or all2. Using trace(all1.map(item -> item.toString)); I get [,,].
Also removing an inner array is problematic. If I make an array [[x,y],[2x,y+10],[3x,y],[4x,y-20]], even though one of those would = [10,20], the functions indexOf and remove won't find it either by passing the specific values or using [a ,b] where a = 10, b = 20.
Yes I can create code to do what I need. The problem is that it took awhile before I could figure out why my code wasn't working.
I assume that these behaviors is because the actual values stored in the arrays are not used, everything is pointer based and not value based. If I'm missing something, let me know. In the meantime I write workaround code.
from haxe.org-comments.
Related Issues (20)
- [haxe.org/manual] Authors and contributions HOT 1
- [haxe.org/manual] Interfaces HOT 1
- [haxe.org/manual] new HOT 2
- [haxe.org/manual] Implementation details (Standard Library - Json) HOT 1
- [haxe.org/manual] Dynamic (Class Fields - Access Modifier) HOT 10
- [code.haxe.org] Abstract types - Email address as abstract type HOT 1
- [code.haxe.org] Beginner - Pattern matching HOT 2
- [code.haxe.org] Abstract types - Pipe using Abstract Operator Overloading HOT 2
- [haxe.org/manual] Target Details HOT 1
- [haxe.org/manual] Generic HOT 2
- [haxe.org/manual] Null Safety HOT 2
- [haxe.org/manual] Blocks HOT 3
- [haxe.org/manual] Tail Recursion Elimination (TRE) HOT 1
- [haxe.org/manual] Module Sub-Types HOT 3
- [code.haxe.org] Macros - Working with compiler flags HOT 1
- [haxe.org/manual] Extractors HOT 2
- [haxe.org/manual] Array Access (Types - Abstract) HOT 2
- [haxe.org/manual] Overriding Methods HOT 1
- [haxe.org/manual] Variable capture HOT 2
- [haxe.org/manual] Tracing Types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from haxe.org-comments.