1
\$\begingroup\$

How to cout bytes for winforms programs? Just met a strange situation here:

C#, 120 bytes

using System.Windows.Forms;class P{static void Main(){var a=new Form();a.Controls.Add(new CheckBox());a.ShowDialog();}}

This code assumes console application and contains full code that can be compiled.

C# (Windows Form Application), 82 bytes

using System.Windows.Forms;class F:Form{public F(){Controls.Add(new CheckBox());}}

Assumes winforms application. There should be additional autogenerated file with code for running the form. And that code is out of calculation... Because of project type?

Is it like some preset we should not count assuming that C# and C# WinForms are different?

VB.NET, 67 (program) + 37 (additional switches) = 104

Class F
Inherits Form
Dim C=New CheckBox With{.Parent=Me}
End Class
vbc.exe *.vb /main:F /imports:System.Windows.Forms

It's a full code and command line for compiling and running it.
/main:F /imports:System.Windows.Forms takes more than a half of program weight.

But what if I use VB.NET WinForms?

I do not have any explicitly generated files (like I do have in C#) I do not need any command line updates and I have that imports by default. So I'll get just 67 instead of 104?


I see it in such way

  1. Some-Lang and Some-Lang Winfroms are different languages
  2. If form designer is not used and designer file should be deleted, only code is counted.
  3. If form designer is used, size of designer file should be added.
  4. All other files and settings except startup form name are kept unchanged and are not counted.

But:

  • What if they are not unchanged?
  • What if there are some changes in progect settings?
\$\endgroup\$
4
  • \$\begingroup\$ I don't understand, In what sense is Some-Lang Winforms a different language? Does it use a different compiler or a different interpreter? \$\endgroup\$ Feb 27, 2017 at 8:34
  • \$\begingroup\$ @PeterTaylor, in the same sense as we treat REPL as different language. \$\endgroup\$
    – Qwertiy
    Feb 27, 2017 at 8:36
  • \$\begingroup\$ Let me completely reword my question, because I may not have expressed it well. What do you mean by Some-Lang Winforms? What is the difference between Some-Lang and Some-Lang Winforms? \$\endgroup\$ Feb 27, 2017 at 8:40
  • \$\begingroup\$ By Some-Lang I meant any language that can be used for console application (as default) or for winforms application with autogenerated solution (or project) template. So the difference is pregenerated code in multiple files. \$\endgroup\$
    – Qwertiy
    Feb 27, 2017 at 8:53

2 Answers 2

3
\$\begingroup\$

You must count the entire source code needed to produce the intended result. In the case of WinForms projects, that usually means Form.vb and Form.Designer.vb (or the equivalents for C#). However, you can get away without including the auto-generated Designer code by implementing it in the form (like the second example does). In addition, you need to include the bytes for extra command-line switches compared to the standard invocation. I'm not really clear on what qualifies as the standard invocation for VB.NET and C#, so I'll leave it to others to determine/clarify what it is.

\$\endgroup\$
4
  • \$\begingroup\$ Form.Designer.vb is not used and can be deleted. No sence to count it in this question. \$\endgroup\$
    – Qwertiy
    Feb 26, 2017 at 22:27
  • \$\begingroup\$ @Qwertiy I misread the code. Fixing my answer now. \$\endgroup\$
    – user45941
    Feb 26, 2017 at 22:27
  • \$\begingroup\$ Actually designer isn't used in all answers. But secons answer expects generated Program.cs that is unchanged and doesn't depend on form code. By the way, VB.NET prepares much more generated code, but it is never explicitly shown - just a part of compiled exe. \$\endgroup\$
    – Qwertiy
    Feb 26, 2017 at 22:30
  • \$\begingroup\$ I updated a question. Also there is one more moment. I can compile VB.NET as winforms since the birth, but it's impossible to do so with C# as winforms application there generates the real cs-file with code for running it. The is no other way to run winforms in C#. There is no any command line for csc that can compile the second code. But it is a part of C# winforms app where all other code is unchanged and designer file can be deleted. \$\endgroup\$
    – Qwertiy
    Feb 26, 2017 at 22:38
0
\$\begingroup\$

If your SomeLang Winforms project can't be compiled without a .somelangproj file, you must count the project file towards the length. This means that in practice there is never any point to claiming SomeLang Winforms as a separate language: it is cheaper to use the SomeLang compiler with some long command-line arguments than to include the project file and compile with MSBuild.

\$\endgroup\$
7
  • \$\begingroup\$ Then why do we separate REPL? In REPL enviroment we are writing only a piece of code: we can drop classes and write only functions, we have imports by default. But if such presets are in a static real file, why should it take part in byte count? As for me it seems like while generated content was not changed, it should not be counted. \$\endgroup\$
    – Qwertiy
    Feb 27, 2017 at 9:01
  • \$\begingroup\$ @Qwertiy, if you want to make the situation comparable to REPL, write an interpreter or compiler which takes just the code from your example and auto-generates the necessary project file etc. Then you can say "Here is my interpreter/compiler which defines a language SomeLang Winforms". \$\endgroup\$ Feb 27, 2017 at 9:04
  • \$\begingroup\$ Why MS Visual Studio isn't ok for this purpose? \$\endgroup\$
    – Qwertiy
    Feb 27, 2017 at 15:08
  • \$\begingroup\$ @Qwertiy, which of the three example programs in the question will Visual Studio compile without any other files (e.g. a .csproj or a .vbproj file)? \$\endgroup\$ Feb 27, 2017 at 15:26
  • \$\begingroup\$ "write an interpreter or compiler which takes just the code from your example and auto-generates the necessary project file etc" - VS does. \$\endgroup\$
    – Qwertiy
    Feb 27, 2017 at 15:27
  • \$\begingroup\$ @Qwertiy, ok, I've saved using System.Windows.Forms;class F:Form{public F(){Controls.Add(new CheckBox());}} in a file called metappcg11650.cs. How do I compile it with VS without creating any other files? \$\endgroup\$ Feb 27, 2017 at 15:34
  • \$\begingroup\$ Seems like you can't. \$\endgroup\$
    – Qwertiy
    Feb 27, 2017 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .