Why Class name must be prepend with T? I saw people prepend F, P, I... before variable names. I also found people do not use Button1 as name but rename it to btnClick or something like that. What is the convention used there?The convention used is from the "Object Pascal Style Guide" (or "CodeGear Coding Style Guide lines").
Since one style is easier to read, Lazarus follows the CodeGear Coding Style Guide lines. Of course, almost anyone will find some points there, that are arguably less readable than other styles. That's OK, just try to follow at least 90%. See the LCL for examples.https://wiki.freepascal.org/DesignGuidelines
Why Class name must be prepend with T? I saw people prepend F, P, I... before variable names. I also found people do not use Button1 as name but rename it to btnClick or something like that. What is the convention used there?
Note the compiler itself has a completely different coding style... Also by convention...https://wiki.freepascal.org/Coding_style
SpacesI really don't like it if all code is written without spaces. It reads terrible.
Don't use spaces around operators, colons, parentheses etc.
{ correct }
p:=p+i;
{ incorrect }
p := p + i ;
I think it is more accurate to say that the compiler source exhibits various coding styles (plural). Unless by "style" you mean something considerably broader than what the term is generally understood to mean.
You can't force volunteers to write according to a particular narrow style definition. You have the sanction of rejecting contributions. But that is short-sighted if the quality of the code is very high and it is designed to be easy to maintain, but fails to adhere to a preferred style convention.
In a commercial environment, of course, the project leader has other levers s/he can apply to get employees to conform.
At some levels coding is an art as much as it is a science or a mechanical application of technique.
QuoteSpacesI really don't like it if all code is written without spaces. It reads terrible.
Don't use spaces around operators, colons, parentheses etc.
{ correct }
p:=p+i;
{ incorrect }
p := p + i ;
It does not matter what you like or not (I personally don't like that the begin is on a separate line for example), but when you're working on a shared project (no matter if Open Source or in a company) you adhere to the guide lines of that project. When in Rome, do as the Romans do...
Yes, and just like C nobody agrees how things should be laid out. In other words it's down to the project managers, and you don't argue with it.
MarkMLl
Well don't do it then. You don't have to do it, as several people have explained to you it's a convention rather than a hard-and-fast syntactic rule.
But if you don't do it you're making life more difficult for people from whom you ask help. And if you don't stick to project conventions you're making extra work for whoever processes your contributions.
MarkMLl
I rarely use pointers, let alone double pointers. There might be use cases for double pointers but I cannot even imagine one.
I'm on my own so I'm free to choose whatever I like. The fact is I'm from a Java foundation I like to do the Java style. Everything is plain English, class Foo is Foo but no TFoo or something like that, very easy to read and intuitive to understand. But I feared I have to follow your convention, because I need to post snippets on this forum when asking for help ;)Ok, you can do it your own way.
Why Class name must be prepend with T?
I also found people do not use Button1 as name but rename it to btnClick or something like that. What is the convention used there?
Yes. I know. Bad practices build up over time and it's very hard to change. I can't get up early for more than ten years despite how hard I tried.
I'm on my own so I'm free to choose whatever I like. The fact is I'm from a Java foundation I like to do the Java style. Everything is plain English, class Foo is Foo but no TFoo or something like that, very easy to read and intuitive to understand. But I feared I have to follow your convention, because I need to post snippets on this forum when asking for help ;)
Don't forget that this is for FPC developers. For Lazarus, just the opposite is accepted (https://wiki.freepascal.org/DesignGuidelines (https://wiki.freepascal.org/DesignGuidelines)).QuoteSpacesI really don't like it if all code is written without spaces. It reads terrible.
Don't use spaces around operators, colons, parentheses etc.
{ correct }
p:=p+i;
{ incorrect }
p := p + i ;
I'm on my own so I'm free to choose whatever I like. The fact is I'm from a Java foundation I like to do the Java style. Everything is plain English, class Foo is Foo but no TFoo or something like that, very easy to read and intuitive to understand. But I feared I have to follow your convention, because I need to post snippets on this forum when asking for help ;)
So how do you call the instantiation of class Foo? AFoo? Or do you call the type FooClass ?
I'm on my own so I'm free to choose whatever I like. The fact is I'm from a Java foundation I like to do the Java style. Everything is plain English, class Foo is Foo but no TFoo or something like that, very easy to read and intuitive to understand. But I feared I have to follow your convention, because I need to post snippets on this forum when asking for help ;)
So how do you call the instantiation of class Foo? AFoo? Or do you call the type FooClass ?
Remember than in Java a class named Foo can be instantiated into foo, because the case matters. Here is not possible (but it saves some headaches when writing without care... sometimes I type FOo by mistake).
The point is that all that, even the casing is also just a convention.
The point is that all that, even the casing is also just a convention.
I'm not sure if everything human is a convention, at least the languages are conventions, the ones we speak and write.
I feared I have to follow your convention, because I need to post snippets on this forum when asking for help ;)Fear is not a good reason to follow the T prefix convention for types. It's a convention but, there is a reason it exists (a good one too!.) The reason is that it is _often_ useful and important to _know_ you are dealing with a type and not something else.
My advice is… study Pascal with Pascal mindset and paradigm. Don't ever judge Pascal convention using Java mindset and paradigm, or any other languages for that matter. Every language has its own philosophy. Deal with it.
The thing I hate most is prepending a T before any class name. Why? We already know it's a Type. In many languages, Types are equivalent with Classes. It doesn't make any sense at all. The same for prepending a P before pointer name. I have seen many examples of how stupid and ridiculous it is. The most obvious example: double pointer (PP). By following this brain dead convention, you have to do a lot of typedefs. These typedefs are useless. You accuse C of using so many typedefs, but you don't see you are, too.
For example, we have a record Foo.
Pointer to Foo: type PFoo = ^Foo;
Pointer to pointer to Foo: type PPFoo = ^PFoo;
How many `P` will you prepend to it if you have to make a pointer to a pointer to a pointer to Foo?
I rarely use pointers, let alone double pointers. There might be use cases for double pointers but I cannot even imagine one.
I'm on my own so I'm free to choose whatever I like. The fact is I'm from a Java foundation I like to do the Java style. Everything is plain English, class Foo is Foo but no TFoo or something like that, very easy to read and intuitive to understand. But I feared I have to follow your convention, because I need to post snippets on this forum when asking for help ;)
So how do you call the instantiation of class Foo? AFoo? Or do you call the type FooClass ?
I'm on my own so I'm free to choose whatever I like. The fact is I'm from a Java foundation I like to do the Java style. Everything is plain English, class Foo is Foo but no TFoo or something like that, very easy to read and intuitive to understand. But I feared I have to follow your convention, because I need to post snippets on this forum when asking for help ;)
So how do you call the instantiation of class Foo? AFoo? Or do you call the type FooClass ?
Remember than in Java a class named Foo can be instantiated into foo, because the case matters. Here is not possible (but it saves some headaches when writing without care... sometimes I type FOo by mistake).
I feared I have to follow your convention, because I need to post snippets on this forum when asking for help ;)Fear is not a good reason to follow the T prefix convention for types. It's a convention but, there is a reason it exists (a good one too!.) The reason is that it is _often_ useful and important to _know_ you are dealing with a type and not something else.
Consider this code:Look at the lines that start with for <varname> in <something> do ;
var a : set of char; i : integer; x : char; type b : 1..10; // apparently in FPC ":" can be used instead of "=" in type declarations ??? c = 1..10; TSOME_RANGE : 1..10; Direction : (north, east, south, west); // accepts ":" instead of "=" ??? TDIRECTION_ENUM1 = (north, east, south, west); // "=" as expected // these are not in accordance with standard Pascal type declarations TDIRECTION_ENUM1 : (north, east, south, west); // : ??? TDIRECTION_ENUM1 = : (north, east, south, west); // = : ??? var d : Direction; e : TDIRECTION; begin for x in a do ; for i in b do ; for i in c do ; for i in TSOME_RANGE do ; for d in Direction do ; for e in TDIRECTION_ENUM1 do ;
The problem is the <something>. In those statements it is difficult to ascertain at a glance what the extent of the "for" is. This is because a, b and c could be one of an enumeration, a set or a range.
It's much nicer and clearer when not only the type is prefixed with a T but also when it is postfixed with something along the lines of "RANGE", "SET", "ENUM" because it's much easier to have at least some idea of what the statement is doing.
Aside from the examples above. Consider you have a "Database" type. Most programmers would like to have a variable named "Database" to refer to the type "Database" but, because the name of the variable has to be different than the name of the type and, because Pascal is not case sensitive, it makes sense to have some way to identify the type. A very common convention used by Pascal programmers is to prefix the type with T for that reason. That way you can have a "var Database : TDATABASE;" which is logical and sensible. In C that is not necessary only because the language is case sensitive and just using different case for the variable name is enough to distinguish it from an, otherwise, identically named datatype.
Talking about conventions, one I wish Pascal programmers would follow is to _always_ put () after function names that require no parameters. When you see a statement like this:b could be some global variable located somewhere or a function, also located "somewhere". Now to figure out what that statement does, the programmer has to dig out from who knows where what b is. People who are obsessed with typing less will name the function with a single letter or few letters, this usually causes a simple text search for it to return a large number of invalid hits the programmer has to wade through. Too bad the obsession with typing less cannot be converted into obsessing about making the program easy to understand (of all obsessions, that one might be a good one.)
a := b;
You shouldn't complain about Pascal being wordy. For functions that take no parameters and for simple logical expressions, Pascal saves you from typing two characters (the parentheses that C requires but Pascal doesn't.)
Now, on a completely different note. The lines that contain ??? deviate from the expected way types are declared in Pascal. I don't know if that is intended in FPC but, the reference manual does not show that ":" (by itself) and "= :"as acceptable in a type definition.
HTH.
This is a useless discussion to begin with. Convention is not law. It's just common agreements of some people upon something. It's not about right or wrong. It's about you agree or follow it, or not, which is not mandatory to anyone. That's all. Everyone could say any conventions don't make any senses for whatever reasons, and vice versa. For example, case sensitive languages (like Java) don't make any senses. How could 'foo' is different from 'Foo'? It's weird.
AFAIK, anyone who disagree with Pascal convention is mostly not a longtime Pascal programmer so s/he doesn't understand or unable to understand the reasons behind the convention. My advice is… study Pascal with Pascal mindset and paradigm. Don't ever judge Pascal convention using Java mindset and paradigm, or any other languages for that matter. Every language has its own philosophy. Deal with it.
We would call Person1, Person2,... but never person.Hahahahaha :D Isn't that a convention too. Adding 1, 2 or 3 after a variable name?
Why it has to be ARequest but not simply Request, request or simply req? What is the meaning of this `A` after all? ARequest = A request? or ARequest = Abstract request?
But again, if you are on your own and you don't share code, you can do whatever you want.
We would call Person1, Person2,... but never person.Hahahahaha :D Isn't that a convention too.
Why it has to be ARequest but not simply Request, request or simply req? What is the meaning of this `A` after all? ARequest = A request? or ARequest = Abstract request?
Well, that is the point. If instance and class have the same default name, you get a lot of clashes, or the unnatural situation with multiple namespaces (or other hacks) to mask that the same name can mean multiple things.But again, if you are on your own and you don't share code, you can do whatever you want.
Like Martin of MSEGUI fame, who suffixed -ty :-)
What exactly the `A` mean? `A` or `Abstract` or... `Arbitrary`?
I do not against convention but stupid and counter intuitive convention, man.
The leading A in ARequest and AResponse convey, when referenced in the body of the implemented procedure/function, that we are dealing with a passed parameter, not a procedure var or protected fields. If dealing with more than 10 lines in a procedure, this hint is very useful.
procedure TFPWebModule1.DataModuleRequest(Sender: TObject; ARequest: TRequest; AResponse: TResponse; var Handled: Boolean); begin AResponse.Content := 'Hello, World!'; Handled := true; end;
Why it has to be ARequest but not simply Request, request or simply req? What is the meaning of this `A` after all? ARequest = A request? or ARequest = Abstract request?
I don't know for sure but I think the A is for attribute.No, as Marco writes, it is simply the indefinite article prefixed without a space since identifiers cannot contain space characters.
I don't know for sure but I think the A is for attribute.No, as Marco writes, it is simply the indefinite article prefixed without a space since identifiers cannot contain space characters.
I like my version better :PWhy not indeed?
I have seen many examples of how stupid and ridiculous it is.
Nice words. Thanks.I have seen many examples of how stupid and ridiculous it is.
Please do not say it is stupid or ridiculous before you really understand the reasons. It's only make you seem like a troll. I don't know why you gone but came back again and again. But I'm glad to see, your language now 'better' than previously. That's a good improvement.
Actually there is no a 'perfect' language or dev tool that for everyone. What works for others may not work for you. And there is no a single one suitable for all kinds of projects. Each tools have its own advantages and disadvantages. You do not have to pick the tool because others say it is good. And you do not have to limit yourself using only 1 tool.
Honestly I envy about you, in a positive way. You know some basic of various languages and tools, C, Java, Python, etc. And you're still young, you have a very long time for the journey to absorb lots of new things. A good programmer should be able to use various of tools. Instead of forcing yourself to 'accept' Pascal, why don't you just use them all.
Each of the things you complained, we have the reasons to counter. I read the answers, they really answered well. But I think, you're unable to fully understand and still not agree.
My suggestion is, try to develop a 'real' software instead of a hello world program. Maybe a simple game, stock control, personal todo and note book. By doing a real project, then you will see the beauty of Pascal, you will understand why readability and maintainability is important and why the conventions are needed. Experience it yourself is best way to learn.
Maybe later you will find that, Pascal is not for you. That's okay. A while ago, there was a user in the forum asking a lot of questions to find out is Lazarus/FPC suitable for him. Later he left for RemObjects Oxygene. Also a kid who was able to write a simple game using FPC after learning Pascal in weeks. He privately contacted me, telling me C++ is awesome because you type less. Great to hear he found the thing that suitable for him, I didn't try to convince him Pascal is better. We do not always pick the best but we usually choose the one we like most.
You were lucky to get lots of answers from 'real' programmers here. Most of them really built huge projects and have decades of experience.
Have a nice weekend.
Please do not say it is stupid or ridiculous before you really understand the reasons. It's only make you seem like a troll. I don't know why you gone but came back again and again. But I'm glad to see, your language now 'better' than previously. That's a good improvement.
My suggestion is, try to develop a 'real' software instead of a hello world program. Maybe a simple game, stock control, personal todo and note book. By doing a real project, then you will see the beauty of Pascal, you will understand why readability and maintainability is important and why the conventions are needed. Experience it yourself is best way to learn.
One learns the most from projects where one can't change the conditions/deliverables to suit a favoured (easy) solution. E.g. an administration application for some local non-profit is the ultimate test I think.
Fatal: Unable to open file C:UsersIEUserAppDataLocallazarusidemake.cfg -di386I have to use the version from getlazarus.org because it's already docked.
I write a lot of console programs, especially for Linux, because I made a lot of web services and server tools using Free Pascal. If you don't do GUI programming, I think Lazarus IDE is overkill. And its console window is still unable to handle ANSI code and unicode correctly.
One learns the most from projects where one can't change the conditions/deliverables to suit a favoured (easy) solution. E.g. an administration application for some local non-profit is the ultimate test I think.
One learns even more when ones boss can- and does change things, without regard to the ease of solution.
Frankly, no one care about the text mode IDE at all because everything now focus on the superior Lazarus IDE. I hope the text mode IDE should get more attention.
[...] in fairness we didn't have that sort of thing in the late Turbo Pascal era which is approximately what that IDE seeks to emulate.
I think ssh does work on BSDs, am I right? :)
I'm using the Free Pascal text IDE. Glad that it also works on Linux. But on systems other than Linux and Windows, it's broke. It seemed it's some issues with curses so mouse click will not work under the terminal emulator.
Frankly, no one care about the text mode IDE at all because everything now focus on the superior Lazarus IDE. I hope the text mode IDE should get more attention.
Sometimes it's easier to just work from a remote machine, even from within the same local network. That's what I've done since I knew VS Code. I could work on my local Raspberry Pi or my remote Linux VPS from my lovely Macbook Pro using Free Pascal with VS Code through ssh. No need to work directly on the target machine. I think ssh does work on BSDs, am I right? :)
I think ssh does work on BSDs, am I right? :)
I believe so, but mouse support (libgpm) possibly doesn't- particularly remotely.
MarkMLl
I'm using the Free Pascal text IDE. Glad that it also works on Linux. But on systems other than Linux and Windows, it's broke. It seemed it's some issues with curses so mouse click will not work under the terminal emulator.
Frankly, no one care about the text mode IDE at all because everything now focus on the superior Lazarus IDE. I hope the text mode IDE should get more attention.
A bit. After Lazarus matured in 2007-2008 new development for the textmode IDE petered out. But that was also a bit because the few devels doing it simply lost steam. Peter left FPC, and Pierre is still there, but doesn't work on Lazarus.
I from time to time also tried to further it (e.g. replacing the helpsystem with the CHM based system), but realized that the textmode IDE has a hopelessly dated design ( copy of something early nineties pieced together from clones):
- Turbo Pascal (not Delphi) object model
- Turbo Pascal (not Delphi) string support (255 chars max)
- no unicode
- TUI entirely managed in code, no designer, hard to maintain
- Streaming also manual. No RTTI
So basically if you really want to further it, you need to start over and bring the textmode system to Delphi technology (late nineties).
And yes, the sad state of *nix consoles (difficult to program, variable, underdocumented) doesn't help either.
The textmode IDE always has worked best with XTerm.
I think ssh does work on BSDs, am I right? :)
I believe so, but mouse support (libgpm) possibly doesn't- particularly remotely.
Don't underestimate X11 forwarding. Especially if you're using it on the local network. I've used it with Firefox quite some time ago. Alternatively you could try VNC. At work we use that for browsing as well.Sometimes it's easier to just work from a remote machine, even from within the same local network. That's what I've done since I knew VS Code. I could work on my local Raspberry Pi or my remote Linux VPS from my lovely Macbook Pro using Free Pascal with VS Code through ssh. No need to work directly on the target machine. I think ssh does work on BSDs, am I right? :)
X11 port forwarding over ssh? How could you do this with an heavy gui software like VS Code without unbearable lagging, I wonder? Do you use solution like NX or X2Go?
Don't underestimate X11 forwarding. Especially if you're using it on the local network. I've used it with Firefox quite some time ago. Alternatively you could try VNC. At work we use that for browsing as well.
Though bee probably didn't mean GUI, but simply invoking the compiler through SSH.
Though bee probably didn't mean GUI, but simply invoking the compiler through SSH.Yup. Most of my Linux remote machines don't even have X installed. I meant by work remotely is simply open ssh connection to a remote machine, edit the source code via VS code through sftp, and then compile it on the remote machine through ssh terminal. I don't need mouse support nor GUI for that since my program is console or web program. :)
Though bee probably didn't mean GUI, but simply invoking the compiler through SSH.Yup. Most of my Linux remote machines don't even have X installed. I meant by work remotely is simply open ssh connection to a remote machine, edit the source code via VS code through sftp, and then compile it on the remote machine through ssh terminal. I don't need mouse support nor GUI for that since my program is console or web program. :)
The remote machine should be called a build server. I would recommend you to use NFS or Samba share over SFTP for performance reason.