使用“使用”假冒typedef [英] using "using" to fake typedefs

查看:80
本文介绍了使用“使用”假冒typedef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个功能包,这些功能只需要很少编程的人使用
经验(如果有的话)和非常小的耐心。


我不想用程序员吓唬他们

像double这样的词和int。我认为数字

和整数会更可口。


如果我用C / C ++写作,我只会


typedef double Number;

typedef int整数;


但我正在使用C#,因为我认为这将是

更安全对于这些人。


那么,我该怎么做typedef在C#??


我知道我可以使用Number = System.Double写一些类似


;


但是我把它放在哪里让它全局可见?


我当然不希望我的用户看到它

每个文件的顶部,所以我需要隐藏它

某处。


谢谢


bk

解决方案



" bubbakittee" < BU ********* @ cox.net>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...

我正在设计一个功能包,供人们使用,只需很少的编程经验(如果有的话),而且很少有耐心。

我不喜欢我想用程序员的话来吓唬他们像双重这样的话。和int。我认为数字
和整数会更加可口。

如果我用C / C ++编写,我只会

typedef double Number;
typedef int Integer;

那么,我该怎么做typedef呢?在C#??

我知道我可以使用Number = System.Double写一些类似

的东西;

但我该把它放在哪里制作它全局可见??

我当然不希望我的用户在每个文件的顶部看到它,所以我需要在某处隐藏它。




你不是。在C#中没有typedef等效,也没有shoudl。


坦率地说,如果你正在编写函数的人无法处理

语言,他们为什么要用它?我怀疑你最好使用更简单,动态或脚本语言而不是通用的

静态类型语言。


>你不会。

C#中没有typedef等效,也没有shoudl。


好​​的。谢谢你的澄清。

坦率地说,如果你写作的人不能处理语言,他们为什么要使用它?我怀疑你最好使用更简单,动态或脚本语言而不是通用静态类型语言。




也许你对。我正在探索C#,因为它有

(1)一个神话般的开发环境(Vis Sudio)

(2)很多有用的编译时检查

(3)漂亮的内置阵列和琴弦

(4)Headroom。虽然我的潜在用户是新手,但他们中的一些人会为编程而感到兴奋,并希望做更多。我希望他们能够在没有切换语言的情况下成长。

(5)熟悉和存在。我可以在我当地的书店购买20本书

,轻松获得帮助等等。

(6)相当简单的语法(与C ++相比,无论如何),

我认为我可以将它分配并稍微调整一下

一些typedef。显然不是。


正如你在另一篇文章中提到的,IronPython可能会更好地回答
。但是它还没有完成,而且我知道比我对C#知道的更多关于Python的更多信息。




" bubbakittee" < BU ********* @ cox.net>在消息中写道

news:11 ********************** @ z14g2000cwz.googlegr oups.com ...

你不是。
C#中没有typedef等效,也没有shoudl。
好的。谢谢你的澄清。

坦率地说,如果你正在编写的人员无法处理语言,他们为什么要使用它?我怀疑你最好使用更简单,动态或脚本语言而不是通用静态类型语言。



也许你是对的。我正在探索C#,因为它有(1)一个神话般的开发环境(Vis Sudio)
(2)很多有用的编译时检查
(3)很好的内置数组和字符串
(4)净空。虽然我的潜在用户是新手,但他们中的一些人会对编程感到兴奋,并希望做更多。我希望他们能够在不转换语言的情况下成长。
(5)熟悉和存在。我可以在我当地的书店购买20本书,轻松获得帮助等等。




这些都是为什么*你*应该用C#写的很好的理由,但不是

只是你的客户,;)。


请记住,.NET面向多种语言。通过一点点b / b $ b探索,您应该能够找到一种语言,它将编译到

..NET运行时并且足够简单以支持您的客户。您可以让您的

客户使用该语言,您可以使用C#或其他任何适合您的其他.NET语言编写库。


你可能想看看VB.NET,IronPython,nemerle和boo,后者

都是针对运行时的功能语言。


VB.NET具有上述功能,并且具有Integer而不是int(althoug Single

和仍然使用Double)以及其他众多功能。


IronPython ,nemerle和boo是功能性的,有点动态。我认为
可能会建议使用IronPython或者boo,因为我认为nemerle比其他人更复杂,但是我对所有这些产品的体验非常小。 />

还有其他语言可供选择,你可能会发现一个我认为不符合你的目的的一个语言。

或者你可以写自己的,:-D

(6)相当简单的语法(与C ++相比,无论如何),
我认为我可以将它子集和tart一些typedef,它有一点点。显然不是。




Typedefs没有,但你可以使用隐式类型和自定义

结构的组合来伪造它(不要引用语法,我直接输入

消息而不是编辑器。


public struct Integer

{

public Integer(int val)

{

value = val;

}


int value;

public int Value {

get

{

return价值;

}

}


公共静态隐式运算符整数(int输入)

{

返回新的整数(输入);

}

公共静态隐式运算符int(整数输入)

{

返回input.Value;

}

}


你也应该覆盖.Equals和operator ==,加上ToString等等。但是

与概念无关。

我强烈建议反对它,建议你fi和另一种.NET

兼容的语言更适合你的目标受众,但在最坏的情况下这可能会有所帮助(对不起,我没有提到它)

第一次,我忘了它)。这将有效,但有更大的潜力

失败


I am designing a package of functions to be
used by people with very little programming
experience (if any) and very little patience.

I don''t want to scare them with programmerish
words like "double" and "int". I think "Number"
and "Integer" would be more palatable.

If I were writing in C/C++ I would just

typedef double Number;
typedef int Integer;

But I''m using C# because I thought it would be
"safer" for these folks.

So, how do I "typedef" in C# ??

I know I can write something like

using Number = System.Double;

But where do I put this to make it globally visible ??

I certainly don''t want my users to see it at
the top of every file, so I need to hide it
somewhere.

thanks

bk

解决方案


"bubbakittee" <bu*********@cox.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

I am designing a package of functions to be
used by people with very little programming
experience (if any) and very little patience.

I don''t want to scare them with programmerish
words like "double" and "int". I think "Number"
and "Integer" would be more palatable.

If I were writing in C/C++ I would just

typedef double Number;
typedef int Integer;

But I''m using C# because I thought it would be
"safer" for these folks.

So, how do I "typedef" in C# ??

I know I can write something like

using Number = System.Double;

But where do I put this to make it globally visible ??

I certainly don''t want my users to see it at
the top of every file, so I need to hide it
somewhere.



You don''t. There is no typedef equivilent in C#, nor shoudl there be.

Frankly, if the people you are writing functions for can''t handle the
language, why are they using it? I suspect you would be best off using a
simpler, dynamic or scripting language rather than a general purpose
statically typed one.


> You don''t.

There is no typedef equivilent in C#, nor shoudl there be.
OK. Thanks for the clarification.
Frankly, if the people you are writing functions for can''t handle
the language, why are they using it? I suspect you would be
best off using a simpler, dynamic or scripting language rather
than a general purpose statically typed one.



Maybe you''re right. I was exploring C# because it has
(1) A fabulous development environment (Vis Sudio)
(2) Lots of helpful compile-time checking
(3) Nice built-in arrays and strings
(4) Headroom. Though my prospective users are
neophytes, some of them will get excited about
programming and want to do more. I''d like them to be
able to grow without switching languages.
(5) Familiarity and presence. I can buy 20 books
at my local bookstore, get help easily, etc.
(6) Fairly simple syntax (compared to C++, anyway),
and I thought I could subset it and tart it up a bit with
some typedefs. Apparently not.

As you mentioned in another post, IronPython might
be a better answer. But it''s not done yet, and I know
even less about Python than I know about C#.



"bubbakittee" <bu*********@cox.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

You don''t.
There is no typedef equivilent in C#, nor shoudl there be.
OK. Thanks for the clarification.

Frankly, if the people you are writing functions for can''t handle
the language, why are they using it? I suspect you would be
best off using a simpler, dynamic or scripting language rather
than a general purpose statically typed one.



Maybe you''re right. I was exploring C# because it has
(1) A fabulous development environment (Vis Sudio)
(2) Lots of helpful compile-time checking
(3) Nice built-in arrays and strings
(4) Headroom. Though my prospective users are
neophytes, some of them will get excited about
programming and want to do more. I''d like them to be
able to grow without switching languages.
(5) Familiarity and presence. I can buy 20 books
at my local bookstore, get help easily, etc.



Each of these are great reasons why *you* should write in C#, but not
nessecerily your clients, ;).

Remember, .NET was geared towards multiple languages. With a little
exploration you should be able to find a language that will compile to the
..NET runtime and be simple enough to support your clients. You can have your
clients use that language and you can write your library in C# or whatever
other .NET language suits you best.

You might want to look at VB.NET, IronPython, nemerle and boo, the latter
are both functinoal languages targeting the runtime.

VB.NET has the above features and has Integer instead of int(althoug Single
and Double are still used) plus a plethora of other functions.

IronPython, nemerle, and boo are functional and a bit more dynamic. I would
probably suggest IronPython or boo, as I thought nemerle was a bit more
complex than the others, but my experiance with all of them is pretty minor.

There are other languages available as well, you might find one I havn''t
thought off that fits your purposes precisely.

Or you could write your own, :-D
(6) Fairly simple syntax (compared to C++, anyway),
and I thought I could subset it and tart it up a bit with
some typedefs. Apparently not.



Typedefs no, but you could use a combonation of implicit types and custom
structures to fake it(don''t quote the syntax, I''m typing directly in to the
message instead of an editor).

public struct Integer
{
public Integer(int val)
{
value = val;
}

int value;
public int Value{
get
{
return value;
}
}

public static implicit operator Integer(int input)
{
return new Integer(input);
}
public static implicit operator int(Integer input)
{
return input.Value;
}
}

You also should override .Equals and operator==, plus ToString, etc. But
that is unrelated to the concept.
I would strongly advise against it, suggesting you find another .NET
compatible language that would be more suitable to your target audience, but
in the worst case this will probably help(Sorry I didn''t mention it the
first time, I forgot about it). This will work but has a greater potential
for failure


这篇关于使用“使用”假冒typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆