X# or C#?

This forum is meant for anything you would like to share with other visitors
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

X# or C#?

Post by ic2 »

The last few weeks I've been working on a project which started years ago in C# and has been enhanced a lot, also in C#. More than once programmers decide to work on new project in C# instead of X# with the argument that there are many samples in C# ready to be used. I recognize that; many of the things I want to program start with a working C# sample from Stackoverflow, Codeproject and more. I always search until I have found code which seems complete & working, with the least amount of program lines and preferably the least amount of no doubt clever but often incomprehensible code.

As we still have most our code in VO and the VO IDE is far better and more usable than VS in nearly every respect I am still not a heavy X# user. I haven't even installed the last few updates anymore. The previous X# versions work for what we have to maintain and there's nothing in the Whatsnew list of the last few versions which affect our code. I am not saying that what has been changed or added is not useful, on the contrary, but not for us. We will probably upgrade like we do with Windows 10: 2-3 times a year is fine unless something is changed where we are waiting for.

But this having said: after these weeks of work in C# it becomes clear how much more VO and hence X# offers than C#. Nearly every VO/X# function for example does not have an equivalent in C#. E.g. At3, Crypt, Left. I always end up with some multi line code sometimes with hard to understand Linq code in it. That is also the case for most other classes as well; .Net has some out-of-the-box functionality but more than once it still requires at least as much code as needed in VO in excellent tools like Fabtools and more libraries many of us use.

In short, even when you are not doing much (yet) in X# and therefor think that you might as well continue in C#: you will definitely end up spending much more time to get simple things working. A good thing to consider if you are thinking about the using special Fox offer (See https://www.xsharp.eu/store/xsharp-2-6- ... -promotion)

@Robert/Chris: one small remark: I noticed in the help that some functions are difficult to find. E.g. try 'functions' and a lot of functions do not appear in the results. There are 14 topics all called Functions, Globals and Defines, but that is one for each different DLL. Also in the Contents.

The VO help does have a more logical/accessible Function Reference (alphabetic and by Category, with the categories named like string, Date & TIme etc which is better than named after the DLL a function can be found in).

In case you don't know anything else to do ;)

Dick
User avatar
wriedmann
Posts: 3754
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# or C#?

Post by wriedmann »

Hi Dick,
I'm preferring X# over C# because of a few strengths:
[*]X# code is easier to read than C# code because the parentheses are replaced by explicit words (like endif/enddo/next)
[*]I can use old VO code
[*]we have a macrocompiler in the language
[*]the product has native access to DBF files
and the most important: We have an excellent support team!
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4898
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

X# or C#?

Post by Chris »

Hi Dick,

That's not true, the .Net Framework (so both X# and c#) has functions (methods) for almost everything that VO ever had and way, way, way more than that in almost every aspect, it just uses different names for those (IndexOf() instead of At() etc). What X# has that c# doesn't, is the integrated macro compiler and native dbf access mainly. And of course the xBase specific compatibility aspects, including the VO-compatible SDK classes, xBase compatible functions etc.

Personally for me the biggest advantage of X# over c# is the syntax, because the syntax of c# is an absolute NO NO for me, and I am very glad that I can do all my development work in a language with a syntax I like and I am now optimistic I will never ever have to do anything in c# for the rest of my life :). (To be clear, a language with syntax like that of Delphi would had also been fine). For other people there are other reasons to use X#, for example for developers with large VO apps, X# offers probably the only sensible path to bring them to today's and future standards. I am sure this will be the case for VFP developers soon as well.

In short, it totally depends on you and your needs and preferences, what language you will choose. Availability of At() and Left() is not a factor though, what is a factor is the way that you use those functions in c# and X# (including the always zero-based aspect in c#). IMO also code snippets availability is not really a factor either, because, yes, samples are written in c#, but after getting used to it a bit, translating them to X# becomes very easy. Availability of programmers willing to code in X# compared to c#, yes I agree this can be an important factor.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

X# or C#?

Post by ic2 »

Hello Wolfgang,
wriedmann wrote:Hi Dick,
I'm preferring X# over C# because of a few strengths:
100% agreed for all reasons.

Try to ask something at answers.microsoft.com or MSDN. Lots of end users to help, sure, but official Microsoft support engineers hardly reply more than "We have not enough information to reply...".

Dick
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

X# or C#?

Post by ic2 »

Hello Chris,
Chris wrote:Hi Dick,

That's not true, the .Net Framework (so both X# and c#) has functions (methods) for almost everything that VO ever had and way, way, way more than that in almost every aspect, it just uses different names for those (IndexOf() instead of At() etc).
I should have formulated it a bit more precise. In case of the Left function: this is a totally logical function to remember (a bit less maybe for At3) but in C# there's no Left function. I understand it used to exist in VB. If you search for a way to accomplish the same result, you will find many examples not using IndexOf, below a few examples I found.

Meaning that none of the people who replied came up with IndexOf but with multi line functions like below.

Same for Crypt. I may have missed it but I have not found anything else than (up to) pages of code for what is 1 function in VO/X#:

https://docs.microsoft.com/en-us/dotnet ... pting-data
https://social.msdn.microsoft.com/Forum ... arpgeneral

My C# program is full of workarounds for missing functions, I think it must be more lines than all FabTools together :P . There is no single function in the program (which includes many collected sample code snippets) that is easier or more logical than an equivalent in VO/X#. And then indeed I am still not talking about the mental ill person who invented the 0 based indexes in C#)

Dick

Several 'solutions' found if you simply search for a Left function in C#:

- char[] array = yourStringVariable.Take(5).ToArray();

- string firstFivChar = new string(yourStringVariable.Take(5).ToArray());

- public static class StringExtensions
{
public static string Left(this string value, int maxLength)
{
if (string.IsNullOrEmpty(value)) return value;
maxLength = Math.Abs(maxLength);

return ( value.Length <= maxLength
? value
: value.Substring(0, maxLength)
);
}
}
User avatar
Chris
Posts: 4898
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

X# or C#?

Post by Chris »

Hi Dick,

In (pure) .Net, instead of Left() (and SubStr()), you would simply use Substring(), it's meant to do the same thing:

cVar:Substring(0,3) // take the first 3 chars

What is different, is that it has different semantics than Left(). First of all, it is not named "Left" :). Also it is not "forgiving", you cannot pass it NULL strings, or string lengths which are longer than the actual string length, like you can do in VO. And worse of all (IMO), it is zero char based. But those are just semantics, for me and you Left() in VO and X# are a lot more intuitive to use than Substring(), but those are only our own preferences, other people may prefer the "cleanness" of the .Net implementation.

What I find much worse, is that there's really not a Right() method in .Net, you can emulate with Substring() again, but the syntax becomes even uglier IMO. Still, that's ugly to me, but it doesn't mean that .Net does not have absolutely everything! Also it is very easy to implement a Left() and Right() extension method that works exactly like in VO, define it in a base library and use it like that everywhere in your code:

Code: Select all

FUNCTION Start() AS VOID
LOCAL c := "abcdef" AS STRING
? c:Right(3) // def

STATIC METHOD Right(SELF cString AS STRING, nCount AS INT) AS STRING
// implement it here exactly the way VO works. Or any other way you prefer

About Crypt() ,maybe there is no .Net function available that works exactly the way that the Crypt() function works. But this is probably because only VO developers use this exact crypt mechanism (which is very weak anyway). Search for .Net cryptography, you will find millions of hits..

Dick, I absolutely agree there are a lot of reasons to prefer X# over c#. Semantics and syntax are two such reasons, if you do prefer the semantics and syntax of X#, like I also absolutely do. But, content, this is absolutely not a reason for choosing one over the other.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

X# or C#?

Post by ic2 »

Hello Chris,

I was not looking for a Crypt function giving the same results as in VO/X#. After all, even from VO to X# you had to add a CryptRaw. But I have not found any 1 line Crypt/Decrypt C# function at all. I haven't checked millions of pages, I admit, but the first few dozen of search results doesn't contain any. Nada. If anyone know a ready to use .Net (De)crypt function (not another self coded workaround) I'd love to hear that.

Same for Right() indeed. And really many, many more functions. And many other programmers who don't realize the existence of simple(r) solutions, when asked.

That's why I don't understand that you write "it doesn't mean that .Net does not have absolutely everything!" . Because IMO, that is exactly what it means. .Net doesn't have a solution for many functions while VO/X# has. That I can write extension function doesn't count. My first computer was an Oric 1 and it didn't have an OnError functions which I very much wanted to use. I wrote it in 6502 machine language (and even earned 100 GBP as I sent it to a computer magazine which published it). It worked very well but I am not going to say that the Oric had absolutely everything in the (Basic) language :lol:

Dick
User avatar
Chris
Posts: 4898
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

X# or C#?

Post by Chris »

Hi Dick,

With a quick search about "Crypt in .Net", I found this in 2 seconds: https://www.codeproject.com/Articles/91 ... Unix-crypt

Obviously there are a lot more than that. Probably there are already available crypt methods also in the system libraries, but even if not, it does not make any difference, when you can download anything from anyone that has ever developed something that you need in .Net and you can use it right away. And trust me, you can find EVERYTHING, any kind of crypt mechanism you have imagined or not. It's the nature of .Net, it is completely open, so you can use what millions and millions of other developers have already created in any language, from any language.

About Right(), as I said of course this is available in .Net:

cVar:Substring(c:Length - 3 , 3) // Right(cVar,3)

It's just not named Right() or Left(), probably because to the eyes of the people who created the system libraries, it would had been redundant to define also those methods, while it is easy (in their eyes) to already achieve the same result with Substring(). Personally I completely dislike this (and many other similar) decisions, but this is just a matter of taste, doesn't change the fact that almost everything is available in .Net.

I am really curious to hear which regular function of VO does not have a one-line equivalent in .Net. Usually they behave differently, but all is there I think. Except of course if you are referring to very specialized functions like MemoLine() or dbf functions and similar.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

X# or C#?

Post by ic2 »

Hello Chris,
Chris wrote:Hi Dick,

With a quick search about "Crypt in .Net", I found this in 2 seconds: https://www.codeproject.com/Articles/91 ... Unix-crypt

I am really curious to hear which regular function of VO does not have a one-line equivalent in .Net.

Well...Crypt hasn't. Your 2 seconds search gives the same result as my 2 seconds (and more than 2 seconds searches). This is a complete library to get a Crypt function. Not a one line function. And trying to push incomprehensible code in 1 line to get a function for "Right" doesn't count as a 1 line function either IMO. For VO/X# this is all included in the default libraries in a easy to understand functions. Which means that in nearly every respect I feel like getting backwards with .Net, VS etc.

That is what I am trying to say all the time. There's about nothing in .Net ready to use. My C# program is filled with workarounds for missing functions. Crypt no doubt will have to be added.

Dick
User avatar
Chris
Posts: 4898
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

X# or C#?

Post by Chris »

Hi Dick,

As I said I agree that Right() in VO feels much better to use than Substring() in .Net. On the other hand, there's absolutely nothing stopping you from using Right() also in c#, if you add a reference to the X# runtime. Or define it yourself to make it work exactly the way you want it to, I don't see any reason why not simply doing that.

In .Net, you have method overloading, dozens of collection classes (compared to simple ARRAY), generics, nested classes and methods, reflection, 64 bit integers, decimal type, namespace grouping, interfaces, extension methods, dozens and dozens "new" language constructs, millions of already developed classes to use instantly, the list of things that we could only had dreamed off in VO is endless.

But if you do prefer VO, and you are more comfortable and productive with it, then of course the best choice for you is to stay with VO, absolutely nothing wrong with that of course. Different people, different preferences, so everybody should use what their prefer. I also like some things the way they were done in VO better than they were done in .Net. How VS generally works is one example :). But the statement "There's about nothing in .Net ready to use" could not possibly be any further from the truth...
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply