digitalmars.D.learn - Why some function are class-less?
- Suliman (9/9) Nov 17 2016 There is some functions that can be called without creation of
- Steven Schveighoffer (4/11) Nov 17 2016 D does not require classes to write functions. All a class member
- Suliman (4/22) Nov 17 2016 Ok, but what profit? Could you give me an example (for example
- Stefan Koch (3/15) Nov 17 2016 for example writeln.
- Suliman (3/20) Nov 17 2016 Ok, but when the logger class may be more helpful that function
- Stefan Koch (3/25) Nov 17 2016 If you log something you usually want to keep private state.
- Jesse Phillips (7/9) Nov 17 2016 You'd use the logger class when you need to make customizations
- Suliman (7/16) Nov 17 2016 For example I need to write all logs to file. I see this
- Jesse Phillips (3/9) Nov 17 2016 It is going to be global if it is a free function and doesn't
There is some functions that can be called without creation of class. For example: http://vibed.org/api/vibe.core.log/ As I understand I can create write log in two way. First create instance of Logger, second simply call function. Why it's done so? Just as shortcut? But is I create class it's look very poor http://vibed.org/api/vibe.core.log/FileLogger and I have only one needed method: ` put Writes part of a log line message. `
Nov 17 2016
On 11/17/16 11:28 AM, Suliman wrote:There is some functions that can be called without creation of class. For example: http://vibed.org/api/vibe.core.log/ As I understand I can create write log in two way. First create instance of Logger, second simply call function. Why it's done so? Just as shortcut? But is I create class it's look very poor http://vibed.org/api/vibe.core.log/FileLogger and I have only one needed method: ` put Writes part of a log line message. `D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter. -Steve
Nov 17 2016
On Thursday, 17 November 2016 at 16:46:37 UTC, Steven Schveighoffer wrote:On 11/17/16 11:28 AM, Suliman wrote:Ok, but what profit? Could you give me an example (for example with logger)?There is some functions that can be called without creation of class. For example: http://vibed.org/api/vibe.core.log/ As I understand I can create write log in two way. First create instance of Logger, second simply call function. Why it's done so? Just as shortcut? But is I create class it's look very poor http://vibed.org/api/vibe.core.log/FileLogger and I have only one needed method: ` put Writes part of a log line message. `D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter. -Steve
Nov 17 2016
On Thursday, 17 November 2016 at 17:42:44 UTC, Suliman wrote:On Thursday, 17 November 2016 at 16:46:37 UTC, Steven Schveighoffer wrote:for example writeln. You would not want to create a stdio object just to call writeln.On 11/17/16 11:28 AM, Suliman wrote:Ok, but what profit? Could you give me an example (for example with logger)?[...]D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter. -Steve
Nov 17 2016
On Thursday, 17 November 2016 at 17:45:31 UTC, Stefan Koch wrote:On Thursday, 17 November 2016 at 17:42:44 UTC, Suliman wrote:Ok, but when the logger class may be more helpful that function usage?On Thursday, 17 November 2016 at 16:46:37 UTC, Steven Schveighoffer wrote:for example writeln. You would not want to create a stdio object just to call writeln.On 11/17/16 11:28 AM, Suliman wrote:Ok, but what profit? Could you give me an example (for example with logger)?[...]D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter. -Steve
Nov 17 2016
On Thursday, 17 November 2016 at 17:54:23 UTC, Suliman wrote:On Thursday, 17 November 2016 at 17:45:31 UTC, Stefan Koch wrote:If you log something you usually want to keep private state. Classes are useful for that.On Thursday, 17 November 2016 at 17:42:44 UTC, Suliman wrote:Ok, but when the logger class may be more helpful that function usage?On Thursday, 17 November 2016 at 16:46:37 UTC, Steven Schveighoffer wrote:for example writeln. You would not want to create a stdio object just to call writeln.On 11/17/16 11:28 AM, Suliman wrote:Ok, but what profit? Could you give me an example (for example with logger)?[...]D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter. -Steve
Nov 17 2016
On Thursday, 17 November 2016 at 17:54:23 UTC, Suliman wrote:Ok, but when the logger class may be more helpful that function usage?You'd use the logger class when you need to make customizations or have multiple logging schemes. I'd expect Vibe.d allows you to override the global logging object. You could then inherit from the Logger class, customize the behavior and assign it to the global logger which is used by all the libraries which just call the log() function.
Nov 17 2016
On Thursday, 17 November 2016 at 18:02:02 UTC, Jesse Phillips wrote:On Thursday, 17 November 2016 at 17:54:23 UTC, Suliman wrote:For example I need to write all logs to file. I see this function, that seem set some global file name. "setLogFile Sets a log file for disk file logging." But would it name accessible from anywhere or it would be visible inly from this scope? If yes is there any way to make it's global?Ok, but when the logger class may be more helpful that function usage?You'd use the logger class when you need to make customizations or have multiple logging schemes. I'd expect Vibe.d allows you to override the global logging object. You could then inherit from the Logger class, customize the behavior and assign it to the global logger which is used by all the libraries which just call the log() function.
Nov 17 2016
On Thursday, 17 November 2016 at 18:40:12 UTC, Suliman wrote:For example I need to write all logs to file. I see this function, that seem set some global file name. "setLogFile Sets a log file for disk file logging." But would it name accessible from anywhere or it would be visible inly from this scope? If yes is there any way to make it's global?It is going to be global if it is a free function and doesn't take/modify a logging object.
Nov 17 2016